comparison libtomcrypt/src/pk/dsa/dsa_export.c @ 285:1b9e69c058d2

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 13:23:58 +0000
parents
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
281:997e6f7dc01e 285:1b9e69c058d2
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 $ */