Mercurial > dropbear
comparison src/pk/dsa/dsa_export.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05
Re-import libtomcrypt 1.05 for cleaner propagating.
From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 12:58:00 +0000 |
parents | |
children | d5faf4814ddb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 280:59400faa4b44 |
---|---|
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 char flags[1]; | |
31 | |
32 LTC_ARGCHK(out != NULL); | |
33 LTC_ARGCHK(outlen != NULL); | |
34 LTC_ARGCHK(key != NULL); | |
35 | |
36 /* can we store the static header? */ | |
37 if (type == PK_PRIVATE && key->type != PK_PRIVATE) { | |
38 return CRYPT_PK_TYPE_MISMATCH; | |
39 } | |
40 | |
41 if (type != PK_PUBLIC && type != PK_PRIVATE) { | |
42 return CRYPT_INVALID_ARG; | |
43 } | |
44 | |
45 flags[0] = (type != PK_PUBLIC) ? 1 : 0; | |
46 | |
47 if (type == PK_PRIVATE) { | |
48 return der_encode_sequence_multi(out, outlen, | |
49 LTC_ASN1_BIT_STRING, 1UL, flags, | |
50 LTC_ASN1_INTEGER, 1UL, &key->g, | |
51 LTC_ASN1_INTEGER, 1UL, &key->p, | |
52 LTC_ASN1_INTEGER, 1UL, &key->q, | |
53 LTC_ASN1_INTEGER, 1UL, &key->y, | |
54 LTC_ASN1_INTEGER, 1UL, &key->x, | |
55 LTC_ASN1_EOL, 0UL, NULL); | |
56 } else { | |
57 return der_encode_sequence_multi(out, outlen, | |
58 LTC_ASN1_BIT_STRING, 1UL, flags, | |
59 LTC_ASN1_INTEGER, 1UL, &key->g, | |
60 LTC_ASN1_INTEGER, 1UL, &key->p, | |
61 LTC_ASN1_INTEGER, 1UL, &key->q, | |
62 LTC_ASN1_INTEGER, 1UL, &key->y, | |
63 LTC_ASN1_EOL, 0UL, NULL); | |
64 } | |
65 } | |
66 | |
67 #endif | |
68 | |
69 | |
70 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_export.c,v $ */ | |
71 /* $Revision: 1.6 $ */ | |
72 /* $Date: 2005/06/03 19:24:31 $ */ |