comparison src/pk/dsa/dsa_export.c @ 210:4768b55c5240 libtomcrypt

propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 33c416b902f1a44913d825bae7ad9a160f703ed3) to branch 'au.asn.ucc.matt.dropbear.ltc' (head 4d6aec6e6121e13f68c11c149b6579c41cb63e74)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 12:10:23 +0000
parents 39d5d58461d6
children
comparison
equal deleted inserted replaced
199:8be64e2c86f4 210:4768b55c5240
25 @param key The key to export 25 @param key The key to export
26 @return CRYPT_OK if successful 26 @return CRYPT_OK if successful
27 */ 27 */
28 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key) 28 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
29 { 29 {
30 unsigned long y, z; 30 unsigned char flags[1];
31 int err;
32 31
33 LTC_ARGCHK(out != NULL); 32 LTC_ARGCHK(out != NULL);
34 LTC_ARGCHK(outlen != NULL); 33 LTC_ARGCHK(outlen != NULL);
35 LTC_ARGCHK(key != NULL); 34 LTC_ARGCHK(key != NULL);
36 35
37 /* can we store the static header? */ 36 /* 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) { 37 if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
43 return CRYPT_PK_TYPE_MISMATCH; 38 return CRYPT_PK_TYPE_MISMATCH;
44 } 39 }
45 40
46 if (type != PK_PUBLIC && type != PK_PRIVATE) { 41 if (type != PK_PUBLIC && type != PK_PRIVATE) {
47 return CRYPT_INVALID_ARG; 42 return CRYPT_INVALID_ARG;
48 } 43 }
49 44
50 /* store header */ 45 flags[0] = (type != PK_PUBLIC) ? 1 : 0;
51 packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_KEY);
52 y = PACKET_SIZE;
53 46
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) { 47 if (type == PK_PRIVATE) {
67 OUTPUT_BIGNUM(&key->x,out,y,z); 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);
68 } 64 }
69
70 *outlen = y;
71 return CRYPT_OK;
72 } 65 }
73 66
74 #endif 67 #endif
75 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 $ */