|
|
|
|
|
#pike __REAL_VERSION__ |
|
|
#if constant(Crypto.DSA) |
|
import Standards.ASN1.Types; |
|
|
|
|
Sequence algorithm_identifier(Crypto.DSA|void dsa) |
{ |
return |
dsa ? Sequence( ({ .Identifiers.dsa_id, |
Sequence( ({ Integer(dsa->get_p()), |
Integer(dsa->get_q()), |
Integer(dsa->get_g()) }) ) }) ) |
: Sequence( ({ .Identifiers.dsa_id }) ); |
} |
|
|
string public_key(Crypto.DSA dsa) |
{ |
return Integer(dsa->get_y())->get_der(); |
} |
|
|
|
|
|
|
|
|
string private_key(Crypto.DSA dsa) |
{ |
return Sequence(map( ({ dsa->get_p(), dsa->get_q(), dsa->get_g(), |
dsa->get_y(), dsa->get_x() }), |
Integer))->get_der(); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
Crypto.DSA parse_public_key(string key, Gmp.mpz p, Gmp.mpz q, Gmp.mpz g) |
{ |
Object a = Standards.ASN1.Decode.simple_der_decode(key); |
if(!a || a->type_name!="INTEGER" ) return 0; |
|
Crypto.DSA dsa = Crypto.DSA(); |
dsa->set_public_key(p, q, g, a->value); |
return dsa; |
} |
|
|
Crypto.DSA parse_private_key(string key) |
{ |
Object a = Standards.ASN1.Decode.simple_der_decode(key); |
|
if (!a |
|| (a->type_name != "SEQUENCE") |
|| (sizeof(a->elements) != 5) |
|| (sizeof(a->elements->type_name - ({ "INTEGER" }))) ) |
return 0; |
|
Crypto.DSA dsa = Crypto.DSA(); |
dsa->set_public_key(@ a->elements[..3]->value); |
dsa->set_private_key(a->elements[4]->value); |
|
return dsa; |
} |
|
|
|
Sequence build_public_key(Crypto.DSA dsa) |
{ |
return Sequence(({ |
algorithm_identifier(dsa), |
BitString(public_key(dsa)), |
})); |
} |
|
|
|
Sequence signature_algorithm_id(Crypto.Hash hash) |
{ |
switch(hash->name()) |
{ |
case "sha1": |
return Sequence( ({ .Identifiers.dsa_sha_id }) ); |
break; |
case "sha224": |
return Sequence( ({ .Identifiers.dsa_sha224_id }) ); |
break; |
case "sha256": |
return Sequence( ({ .Identifiers.dsa_sha256_id }) ); |
break; |
} |
return 0; |
} |
|
#else |
constant this_program_does_not_exist=1; |
#endif |
|
|