Skip to content
Snippets Groups Projects
Commit 2c5261ba authored by Niels Möller's avatar Niels Möller
Browse files

Parsing and formatting of DSA keys.

Rev: lib/modules/Standards.pmod/PKCS.pmod/DSA.pmod:1.1
parent 5c24975f
No related branches found
No related tags found
No related merge requests found
/* DSA.pmod
*
* DSA operations as defined in RFC-2459.
*
*/
/* NOTE: Unlike the functions in RSA.pmod, this function returns
* an object rather than a string. */
import Standards.ASN1.Types;
object algorithm_identifier(object|void dsa)
{
return
dsa ? asn1_sequence( ({ .Identifiers.dsa_id,
asn1_sequence( ({ asn1_integer(dsa->p),
asn1_integer(dsa->q),
asn1_integer(dsa->g) }) ) }) )
: asn1_sequence( ({ .Identifiers.dsa_id }) );
}
string public_key(object dsa)
{
return asn1_integer(dsa->y)->get_der();
}
/* I don't know if this format interoperates with anything else */
string private_key(object dsa)
{
return asn1_sequence(Array.map(
({ dsa->p, dsa->q, dsa->g, dsa->y, dsa->x }),
asn1_integer))->get_der();
}
object 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;
object dsa = Crypto.dsa();
dsa->set_public_key(@ a->elements[..3]->value);
dsa->set_private_key(a->elements[4]->value);
return dsa;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment