Mercurial > dropbear
comparison src/pk/dsa/dsa_export.c @ 191:1c15b283127b libtomcrypt-orig
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 13:23:02 +0000 |
parents | |
children | 39d5d58461d6 |
comparison
equal
deleted
inserted
replaced
143:5d99163f7e32 | 191:1c15b283127b |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file dsa_export.c | |
15 DSA implementation, export key, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef MDSA | |
19 | |
20 /** | |
21 Export a DSA key to a binary packet | |
22 @param out [out] Where to store the packet | |
23 @param outlen [in/out] The max size and resulting size of the packet | |
24 @param type The type of key to export (PK_PRIVATE or PK_PUBLIC) | |
25 @param key The key to export | |
26 @return CRYPT_OK if successful | |
27 */ | |
28 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key) | |
29 { | |
30 unsigned long y, z; | |
31 int err; | |
32 | |
33 LTC_ARGCHK(out != NULL); | |
34 LTC_ARGCHK(outlen != NULL); | |
35 LTC_ARGCHK(key != NULL); | |
36 | |
37 /* can we store the static header? */ | |
38 if (*outlen < (PACKET_SIZE + 1 + 2)) { | |
39 return CRYPT_BUFFER_OVERFLOW; | |
40 } | |
41 | |
42 if (type == PK_PRIVATE && key->type != PK_PRIVATE) { | |
43 return CRYPT_PK_TYPE_MISMATCH; | |
44 } | |
45 | |
46 if (type != PK_PUBLIC && type != PK_PRIVATE) { | |
47 return CRYPT_INVALID_ARG; | |
48 } | |
49 | |
50 /* store header */ | |
51 packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_KEY); | |
52 y = PACKET_SIZE; | |
53 | |
54 /* store g, p, q, qord */ | |
55 out[y++] = type; | |
56 out[y++] = (key->qord>>8)&255; | |
57 out[y++] = key->qord & 255; | |
58 | |
59 OUTPUT_BIGNUM(&key->g,out,y,z); | |
60 OUTPUT_BIGNUM(&key->p,out,y,z); | |
61 OUTPUT_BIGNUM(&key->q,out,y,z); | |
62 | |
63 /* public exponent */ | |
64 OUTPUT_BIGNUM(&key->y,out,y,z); | |
65 | |
66 if (type == PK_PRIVATE) { | |
67 OUTPUT_BIGNUM(&key->x,out,y,z); | |
68 } | |
69 | |
70 *outlen = y; | |
71 return CRYPT_OK; | |
72 } | |
73 | |
74 #endif | |
75 |