pike.git / lib / 7.8 / modules / Crypto.pmod / DSA.pike

version» Context lines:

pike.git/lib/7.8/modules/Crypto.pmod/DSA.pike:1:      //! The Digital Signature Algorithm (aka DSS, Digital Signature Standard).      #pike __REAL_VERSION__   #pragma strict_types + #require constant(Crypto.Random)    - #if constant(Crypto.Random) -  +    protected Gmp.mpz p; // Modulo   protected Gmp.mpz q; // Group order   protected Gmp.mpz g; // Generator      protected Gmp.mpz y; // Public key   protected Gmp.mpz x; // Private key    - function(int:string) random = Crypto.Random.random_string; + function(int(0..):string) random = Crypto.Random.random_string;         // Accessors      Gmp.mpz get_p() { return p; } //! Returns the modulo.   Gmp.mpz get_q() { return q; } //! Returns the group order.   Gmp.mpz get_g() { return g; } //! Returns the generator.   Gmp.mpz get_y() { return y; } //! Returns the public key.   Gmp.mpz get_x() { return x; } //! Returns the private key.         //! Sets the public key in this DSA object.   this_program set_public_key(Gmp.mpz p_, Gmp.mpz q_, Gmp.mpz g_, Gmp.mpz y_)   {    p = p_; q = q_; g = g_; y = y_; -  - #if 0 - #define D(x) ((x) ? (x)->digits() : "NULL") -  werror("dsa->set_public_key\n" -  " p = %s,\n" -  " q = %s,\n" -  " g = %s,\n" -  " y = %s,\n", -  D(p), D(q), D(g), D(y)); - #endif -  +     return this;   }      //! Sets the private key in this DSA object.   this_program set_private_key(Gmp.mpz secret)   {    x = secret;    return this;   }      //! 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) r) + this_program set_random(function(int(0..):string) r)   {    random = r;    return this;   }      //! Makes a DSA hash of the messge @[msg].   Gmp.mpz hash(string msg)   { -  return [object(Gmp.mpz)](Gmp.mpz(Crypto.SHA1.hash(msg), 256) % q); +  return [object(Gmp.mpz)](Gmp.mpz(Crypto.SHA1.hash([string(8bit)]msg), 256) % q);   }      protected Gmp.mpz random_number(Gmp.mpz n)   { -  return [object(Gmp.mpz)](Gmp.mpz(random( (q->size() + 10 / 8)), 256) % n); +  return [object(Gmp.mpz)](Gmp.mpz(random( [int(0..)](q->size() + 10 / 8)), 256) % n);   }      protected Gmp.mpz random_exponent()   {    return [object(Gmp.mpz)](random_number([object(Gmp.mpz)](q - 1)) + 1);   }      //! Sign the message @[h]. Returns the signature as two @[Gmp.mpz]   //! objects.   array(Gmp.mpz) raw_sign(Gmp.mpz h, void|Gmp.mpz k)
pike.git/lib/7.8/modules/Crypto.pmod/DSA.pike:126:   {    return Standards.ASN1.Types.Sequence(    Array.map(raw_sign(hash(msg)),    Standards.ASN1.Types.Integer))->get_der();   }      //! Verify an SSL signature @[s] of message @[msg].   int(0..1) verify_ssl(string msg, string s)   {   #define Object Standards.ASN1.Types.Object -  Object a = Standards.ASN1.Decode.simple_der_decode(s); +  Object a = Standards.ASN1.Decode.simple_der_decode([string(8bit)]s);       if (!a    || (a->type_name != "SEQUENCE")    || (sizeof([array]a->elements) != 2)    || (sizeof( ([array(object(Object))]a->elements)->type_name -    ({ "INTEGER" }))))    return 0;       return raw_verify(hash(msg),    [object(Gmp.mpz)]([array(object(Object))]a->elements)[0]->
pike.git/lib/7.8/modules/Crypto.pmod/DSA.pike:148:    [object(Gmp.mpz)]([array(object(Object))]a->elements)[1]->    value);   }         #define SEED_LENGTH 20      protected string nist_hash(Gmp.mpz x)   {    string s = x->digits(256); -  return Crypto.SHA1.hash(s[sizeof(s) - SEED_LENGTH..]); +  return Crypto.SHA1.hash([string(8bit)]s[sizeof(s) - SEED_LENGTH..]);   }      //! The (slow) NIST method of generating a DSA prime pair. Algorithm   //! 4.56 of Handbook of Applied Cryptography.   array(Gmp.mpz) nist_primes(int l)   {    if ( (l < 0) || (l > 8) )    error( "Unsupported key size.\n" );       int L = 512 + 64 * l;
pike.git/lib/7.8/modules/Crypto.pmod/DSA.pike:268:   //! Compares the public key in this object with that in the provided   //! @[DSA] object.   int(0..1) public_key_equal (.DSA dsa)   {    return (p == dsa->get_p()) && (q == dsa->get_q()) &&    (g == dsa->get_g()) && (y == dsa->get_y());   }      //! Returns the string @expr{"DSA"@}.   string name() { return "DSA"; } -  - #else - constant this_program_does_not_exist=1; - #endif +