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

version» Context lines:

pike.git/lib/modules/Crypto.pmod/RSA.pike:297:   //! @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 message, int(1..2) type,    function(int:string)|void random)   { -  string cookie; +  string cookie = "";    int len;       len = size - 3 - sizeof(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 ) random = this_program::random; -  cookie = replace( random(len), "\0", "\1"); +  do { +  cookie += random(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 rsa_unpad(Gmp.mpz block, int type)   {