pike.git / lib / modules / Crypto.pmod / DH.pmod

version» Context lines:

pike.git/lib/modules/Crypto.pmod/DH.pmod:37:    {    Gmp.mpz key = [object(Gmp.mpz)]    (Gmp.mpz(rnd([int(0..)](q->size() / 8 + 16)), 256) % (q - 1) + 1);       Gmp.mpz pub = g->powm(key, p);       return ({ pub, key });    }   #endif    +  //! Validate that the DH Parameters doesn't have obvious security +  //! weaknesses. It will first attempt to verify the prime @[p] using +  //! Donald Knuth's probabilistic primality test with provided +  //! @[effort]. This has a chance of pow(0.25,effort) to produce a +  //! false positive. An @[effort] of 0 skipps this step. The second +  //! test verifies that @[g] is of high order. +  bool validate(int(0..) effort) +  { +  if( effort && !p->probably_prime_p(effort) ) +  return 0; +  +  Gmp.mpz qq = [object(Gmp.mpz)]((p-1)/2); +  while( int f = qq->small_factor() ) +  qq /= f; +  +  if( g->powm( [object(Gmp.mpz)]((p-1)/qq), p )==1 ) +  return 0; +  +  return 1; +  } +     //! Alias for @[q].    //!    //! @deprecated q    __deprecated__ Gmp.mpz `order()    {    return q;    }       //! Alias for @[q].    //!
pike.git/lib/modules/Crypto.pmod/DH.pmod:92:    //!    //! @param q    //! The order of the group. Defaults to @expr{(p-1)/2@}.    protected variant void create(Gmp.mpz|int p, Gmp.mpz|int|void g,    Gmp.mpz|int|void q)    {    this_program::p = Gmp.mpz(p);    this_program::g = g && Gmp.mpz(g) || Gmp.mpz(2);    this_program::q = q && Gmp.mpz(q) || Gmp.mpz( [int](p-1)/2 );    } +  +  protected string _sprintf(int t) +  { +  if( t!='O' ) return UNDEFINED; +  mapping(string:mixed) m = mkmapping([array(string)]indices(Crypto.DH), +  values(Crypto.DH)); +  foreach(m; string id; mixed val) +  if( val==this ) return sprintf("Crypto.DH.%s", id); +  return sprintf("%O(%O, %O, %O)", this_program, p, g, q);    } -  + }      //! MODP Group 1 (768 bit) (aka First Oakley Group (aka ORM96 group 1)).   //!   //! RFC 2409 6.1   //!   //! @note   //! Not allowed for use with FIPS 140.   Parameters MODPGroup1 =    /* p = 2^768 - 2 ^704 - 1 + 2^64 * floor( 2^638 Pi + 149686 ) */    Parameters(Gmp.mpz("FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"