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

 version » Context lines: 10204080filenone3

pike.git/lib/modules/Crypto.pmod/RSA.pike:156: Inside #if constant(Crypto.Hash)
}      //! Generate a valid RSA key pair with the size @[bits] using the   //! random function set with @[set_random()]. The public exponent @[e]   //! will be used, which defaults to 65537. Keys must be at least 89   //! bits.   this_program generate_key(int(128..) bits, void|int e)   {    if (bits < 128)    error( "Ridiculously small key.\n" ); +  if( e ) +  { +  if(!(e&1)) error("e needs to be odd.\n"); +  if(e<3) error("e is too small.\n"); +  if(e->size()>bits) error("e has to be smaller in size than the key.\n"); +  }       /* NB: When multiplying two n-bit integers,    * you're most likely to get an (2n - 1)-bit result.    * We therefore add an extra bit to s2.    *    * cf [bug 6620].    */       int s1 = bits / 2; /* Size of the first prime */    int s2 = 1 + bits - s1;    -  string msg = "This is a valid RSA key pair\n"; +  string msg = "A" * (bits/8-3-8);       do    {    Gmp.mpz p;    Gmp.mpz q;    Gmp.mpz mod;    do {    p = get_prime(s1, random);    q = get_prime(s2, random);    mod = [object(Gmp.mpz)](p * q);
pike.git/lib/modules/Crypto.pmod/RSA.pike:437:   }      __deprecated__ int(0..) rsa_size() { return [int(0..)](size*8); }         // Broken implementation of RSA/MD5 SIG RFC 2537. The 0x00 01 FF* 00   // prefix is missing.      // (RSA/SHA-1 SIG is in RFC 3110)    + #if constant(Crypto.MD5) +    __deprecated__ string md5_sign(string message, mixed|void r)   {    string s = Crypto.MD5->hash(message);    s = "0 0\14\6\10*\x86H\x86\xf7\15\2\5\5\0\4\20"+s;    return raw_sign(s)->digits(256);r;   }      __deprecated__ int md5_verify(string message, string signature)   {    string s = Crypto.MD5->hash(message);    s = "0 0\14\6\10*\x86H\x86\xf7\15\2\5\5\0\4\20"+s;    return raw_verify(s, Gmp.mpz(signature, 256));   }    -  + #endif +    __deprecated__ string sha_sign(string message, mixed|void r)   {    string s = sprintf("%c%s%1H", 4, "sha1", Crypto.SHA1->hash(message));    return raw_sign(s)->digits(256);r;   }      __deprecated__ int sha_verify(string message, string signature)   {    string s = sprintf("%c%s%1H", 4, "sha1", Crypto.SHA1->hash(message));    return raw_verify(s, Gmp.mpz(signature, 256));