1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
15
int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
21
_ARGCHK(outlen != NULL);
24
/* can we store the static header? */
25
if (*outlen < (PACKET_SIZE + 1 + 2)) {
26
return CRYPT_BUFFER_OVERFLOW;
29
if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
30
return CRYPT_PK_TYPE_MISMATCH;
33
if (type != PK_PUBLIC && type != PK_PRIVATE) {
34
return CRYPT_INVALID_ARG;
38
packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_KEY);
41
/* store g, p, q, qord */
43
out[y++] = (key->qord>>8)&255;
44
out[y++] = key->qord & 255;
46
OUTPUT_BIGNUM(&key->g,out,y,z);
47
OUTPUT_BIGNUM(&key->p,out,y,z);
48
OUTPUT_BIGNUM(&key->q,out,y,z);
51
OUTPUT_BIGNUM(&key->y,out,y,z);
53
if (type == PK_PRIVATE) {
54
OUTPUT_BIGNUM(&key->x,out,y,z);