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

version» Context lines:

pike.git/lib/modules/Crypto.pmod/RSA.pike:15:   protected Gmp.mpz n; /* modulo */   protected Gmp.mpz e; /* public exponent */   protected Gmp.mpz d; /* private exponent (if known) */   protected int size;      /* Extra info associated with a private key. Not currently used. */      protected Gmp.mpz p;   protected Gmp.mpz q;    - protected function(int:string(8bit)) random = .Random.random_string; + protected function(int(0..):string(8bit)) random = .Random.random_string;      Gmp.mpz get_n() { return n; } //! Returns the RSA modulo (n).   Gmp.mpz get_e() { return e; } //! Returns the RSA public exponent (e).      //! Returns the RSA private exponent (d), if known.   Gmp.mpz get_d() { return d; }      Gmp.mpz get_p() { return p; } //! Returns the first RSA prime (p), if known.   Gmp.mpz get_q() { return q; } //! Returns the second RSA prime (q), if known.      //! Sets the random function, used to generate keys and parameters, to   //! the function @[r]. Default is @[Crypto.Random.random_string]. - this_program set_random(function(int:string(8bit)) r) + this_program set_random(function(int(0..):string(8bit)) r)   {    random = r;    return this;   }      //! Returns the string @expr{"RSA"@}.   string(8bit) name() { return "RSA"; }      //   // --- Key methods
pike.git/lib/modules/Crypto.pmod/RSA.pike:362:   //! @param type   //! @int   //! @value 1   //! The message is padded with @expr{0xff@} bytes.   //! @value 2   //! The message is padded with random data, using the @[random]   //! function if provided. Otherwise the default random function   //! set in the object will be used.   //! @endint   Gmp.mpz rsa_pad(string(8bit) message, int(1..2) type, -  function(int:string(8bit))|void random) +  function(int(0..):string(8bit))|void random)   {    string(8bit) cookie = "";       // Padding length. At least 8 bytes as security margin.    int len = size - 3 - sizeof(message);    if (len < 8)    error( "Block too large. (%d>%d)\n", sizeof(message), size-11 );       switch(type)    {    case 1:    cookie = sprintf("%@c", allocate(len, 0xff));    break;    case 2:    if( !random ) random = this_program::random;    do { -  cookie += random(len-sizeof(cookie)) - "\0"; +  cookie += random([int(0..)](len-sizeof(cookie))) - "\0";    } while( sizeof(cookie)<len );    break;    default:    error( "Unknown type.\n" );    }    return Gmp.mpz(sprintf("%c", type) + cookie + "\0" + message, 256);   }      //! Reverse the effect of @[rsa_pad].   string(8bit) rsa_unpad(Gmp.mpz block, int type)