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

version» Context lines:

pike.git/lib/modules/Crypto.pmod/DH.pmod:19:    Gmp.mpz("c9bbf5f774a8297b0f97cdda3a3468c7117b6bf799a13d9f1f5dac487b2241fe95efb13c2855dfd2f898b3f99188e24edf326dd68c76cc85537283512d46f1953129c693364d8c71202eabb3ebc85c1df53907fbd0b7eb490ad0bc99289686800c46ab04bf7cdd9ad425e6fb25592eb6258a0655d75e93b2671746ae349e721b",16),       // Hard-coded in Apache httpd 2.0, modules/ssl/ssl_engine_dh.c.    Gmp.mpz("e6969d3d495be32c7cf180c3bdd4798e91b7818251bb055e2a2064904a79a770fa15a259cbd523a6a6ef09c43048d5a22f971f3c20129b48000e6edd061cbc053e371d794e5327df611ebbbe1bac9b5c6044cf023d76e05eea9bad991b13a63c974e9ef1839eb5db125136f7262e56a8871538dfd823c6505085e21f0dd5c86b",16),      >);      //! Diffie-Hellman parameters.   class Parameters   { -  inherit __builtin.Nettle.DH_Params; + #if constant(Nettle.DH_Params) +  inherit Nettle.DH_Params; + #else +  //! Prime. +  Gmp.mpz p;    -  +  //! Generator. +  Gmp.mpz g; +  +  //! Subgroup size. +  Gmp.mpz q; +  +  // FIXME: generate(). +  +  //! Generate a Diffie-Hellman key pair. +  //! +  //! @returns +  //! Returns the following array: +  //! @array +  //! @elem Gmp.mpz 0 +  //! The generated public key. +  //! @elem Gmp.mpz 1 +  //! The corresponding private key. +  //! @endarray +  array(Gmp.mpz) generate_keypair(function(int(0..):string(8bit)) rnd) +  { +  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 && !known_primes[p] && !p->probably_prime_p(effort) )    return 0;
pike.git/lib/modules/Crypto.pmod/DH.pmod:44:    qq /= f;       if( g->powm( [object(Gmp.mpz)]((p-1)/qq), p )==1 )    return 0;       return 1;    }       //! Initialize the set of Diffie-Hellman parameters.    //! +  //! @param other +  //! Copy the parameters from this object. +  protected void create(this_program other) +  { +  p = other->p; +  g = other->g; +  q = other->q; +  } +  +  //! Initialize the set of Diffie-Hellman parameters. +  //! +  //! @param p +  //! The prime for the group. +  //! +  //! @param g +  //! The generator for the group. Defaults to @expr{2@}. +  //! +  //! @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::p = Gmp.mpz(p); +  this::g = g && Gmp.mpz(g) || Gmp.mpz(2); +  this::q = q && Gmp.mpz(q) || Gmp.mpz( [int](p-1)/2 ); +  } +  +  // Dummy declaration of Crypto.DSA.State to +  // avoid circular references. +  private class DSA_State { +  Gmp.mpz get_p(); +  Gmp.mpz get_g(); +  Gmp.mpz get_q(); +  } +  +  //! Initialize the set of Diffie-Hellman parameters. +  //!    //! @param dsa    //! Copy the parameters from this object. -  protected variant void create(Crypto.DSA.State dsa) +  protected variant void create(DSA_State dsa)    {    p = dsa->get_p();    g = dsa->get_g();    q = dsa->get_q();    }       protected string _sprintf(int t)    {    if( t!='O' ) return UNDEFINED;    mapping(string:mixed) m = mkmapping([array(string)]indices(Crypto.DH),