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

version» Context lines:

pike.git/lib/modules/Crypto.pmod/RSA.pike:1: - /* $Id: RSA.pike,v 1.4 2004/02/05 19:21:15 nilsson Exp $ + /* $Id: RSA.pike,v 1.5 2004/02/08 03:21:02 nilsson Exp $    *    * Follow the PKCS#1 standard for padding and encryption.    */      #pike __REAL_VERSION__   #pragma strict_types      #if constant(Gmp.mpz)      static Gmp.mpz n; /* modulo */
pike.git/lib/modules/Crypto.pmod/RSA.pike:29: Inside #if constant(Gmp.mpz)
  {    return e;   }      //! Returns the RSA private exponent (if known).   Gmp.mpz get_d()   {    return d;   }    - // Returns the first RSA prime (if known). + //! Returns the first RSA prime (if known).   Gmp.mpz get_p()   {    return p;   }    - // Returns the second RSA prime (if known). + //! Returns the second RSA prime (if known).   Gmp.mpz get_q()   {    return q;   }      //! Returns the RSA modulo as a binary string.   string cooked_get_n()   {    return n->digits(256);   }
pike.git/lib/modules/Crypto.pmod/RSA.pike:59: Inside #if constant(Gmp.mpz)
  {    return e->digits(256);   }      //! Returns the RSA private exponent (if known) as a binary string.   string cooked_get_d()   {    return d->digits(256);   }    - // Returns the first RSA prime (if known) as a binary string. + //! Returns the first RSA prime (if known) as a binary string.   string cooked_get_p()   {    return p->digits(256);   }    - // Returns the second RSA prime (if known) as a binary string. + //! Returns the second RSA prime (if known) as a binary string.   string cooked_get_q()   {    return q->digits(256);   }      //! Sets the public key.   this_program set_public_key(Gmp.mpz|int modulo, Gmp.mpz|int pub)   {    n = Gmp.mpz(modulo);    e = Gmp.mpz(pub);
pike.git/lib/modules/Crypto.pmod/RSA.pike:127: Inside #if constant(Gmp.mpz)
  //! function if provided. Otherwise   //! @[Crypto.Random.random_string] will be used.   //! @endint   Gmp.mpz rsa_pad(string message, int(1..2) type,    function(int:string)|void random)   {    string cookie;    int len;       len = size - 3 - sizeof(message); -  /* write(sprintf("%d, %d, %d, %s", len, size, sizeof(message), message)); */ +     if (len < 8)    error( "Block too large. (%d,%d)\n", sizeof(message), size-3 );       switch(type)    {    case 1:    cookie = sprintf("%@c", allocate(len, 0xff));    break;    case 2:    if (random)
pike.git/lib/modules/Crypto.pmod/RSA.pike:208: Inside #if constant(Gmp.mpz)
     //! Compares the public key of this RSA object with another RSA   //! object.   int(0..1) public_key_equal(this_program rsa)   {    return n == rsa->get_n() && e == rsa->get_e();   }      // end of _rsa    - //! @fixme - //! Document this function. + //! Signs the @[message] with a PKCS-1 signature using hash algorithm + //! @[h].   Gmp.mpz sign(string message, .Hash h)   {    return raw_sign(Standards.PKCS.Signature.build_digestinfo(message, h));   }    - //! @fixme - //! Document this function. + //! Verify PKCS-1 signature @[sign] of message @[msg] using hash + //! algorithm @[h].   int(0..1) verify(string msg, .Hash h, Gmp.mpz sign)   {    string s = Standards.PKCS.Signature.build_digestinfo(msg, h);    return raw_verify(s, sign);   }      //! @fixme   //! Document this function.   string sha_sign(string message, mixed|void r)   {
pike.git/lib/modules/Crypto.pmod/RSA.pike:259: Inside #if constant(Gmp.mpz)
     //! @fixme   //! Document this function.   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));   }    - //! @fixme - //! Document this function. + //! Generate a prime with @[bits] number of bits using random function + //! @[r].   Gmp.mpz get_prime(int bits, function(int:string) r)   {    int len = (bits + 7) / 8;    int bit_to_set = 1 << ( (bits - 1) % 8);       Gmp.mpz p;       do {    string s = r(len);    p = Gmp.mpz(sprintf("%c%s", (s[0] & (bit_to_set - 1))
pike.git/lib/modules/Crypto.pmod/RSA.pike:327: Inside #if constant(Gmp.mpz)
   } while (!sha_verify(msg, sha_sign(msg, r)));    return this;   }      /*    * Block cipher compatibility.    */      static int encrypt_mode; // For block cipher compatible functions    - //! @fixme - //! Document this function. + //! Sets the public key to @[key] and the mode to encryption.   //! @seealso   //! @[set_decrypt_key], @[crypt]   this_program set_encrypt_key(array(Gmp.mpz) key)   {    set_public_key(key[0], key[1]);    encrypt_mode = 1;    return this;   }    - //! @fixme - //! Document this function. + //! Sets the public key to @[key]and the mod to decryption.   //! @seealso   //! @[set_encrypt_key], @[crypt]   this_program set_decrypt_key(array(Gmp.mpz) key)   {    set_public_key(key[0], key[1]);    set_private_key(key[2]);    encrypt_mode = 0;    return this;   }    - //! @fixme - //! Document this function. + //! Encrypt or decrypt depending on set mode.   //! @seealso   //! @[set_encrypt_key], @[set_decrypt_key]   string crypt(string s)   {    return (encrypt_mode ? encrypt(s) : decrypt(s));   }      //! Returns the string @expr{"RSA"@}.   string name() {    return "RSA";   }      #endif