Mercurial > dropbear
comparison libtomcrypt/src/pk/katja/katja_export.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file katja_export.c | 12 @file katja_export.c |
15 Export Katja LTC_PKCS-style keys, Tom St Denis | 13 Export Katja PKCS-style keys, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef MKAT | 16 #ifdef LTC_MKAT |
19 | 17 |
20 /** | 18 /** |
21 This will export either an KatjaPublicKey or KatjaPrivateKey | 19 This will export either an KatjaPublicKey or KatjaPrivateKey |
22 @param out [out] Destination of the packet | 20 @param out [out] Destination of the packet |
23 @param outlen [in/out] The max size and resulting size of the packet | 21 @param outlen [in/out] The max size and resulting size of the packet |
24 @param type The type of exported key (PK_PRIVATE or PK_PUBLIC) | 22 @param type The type of exported key (PK_PRIVATE or PK_PUBLIC) |
25 @param key The Katja key to export | 23 @param key The Katja key to export |
26 @return CRYPT_OK if successful | 24 @return CRYPT_OK if successful |
27 */ | 25 */ |
28 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key) | 26 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key) |
29 { | 27 { |
30 int err; | 28 int err; |
31 unsigned long zero=0; | 29 unsigned long zero=0; |
32 | 30 |
39 return CRYPT_PK_INVALID_TYPE; | 37 return CRYPT_PK_INVALID_TYPE; |
40 } | 38 } |
41 | 39 |
42 if (type == PK_PRIVATE) { | 40 if (type == PK_PRIVATE) { |
43 /* private key */ | 41 /* private key */ |
44 /* output is | 42 /* output is |
45 Version, n, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p, pq | 43 Version, n, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p, pq |
46 */ | 44 */ |
47 if ((err = der_encode_sequence_multi(out, outlen, | 45 if ((err = der_encode_sequence_multi(out, outlen, |
48 LTC_ASN1_SHORT_INTEGER, 1UL, &zero, | 46 LTC_ASN1_SHORT_INTEGER, 1UL, &zero, |
49 LTC_ASN1_INTEGER, 1UL, key->N, | 47 LTC_ASN1_INTEGER, 1UL, key->N, |
50 LTC_ASN1_INTEGER, 1UL, key->d, | 48 LTC_ASN1_INTEGER, 1UL, key->d, |
51 LTC_ASN1_INTEGER, 1UL, key->p, | 49 LTC_ASN1_INTEGER, 1UL, key->p, |
52 LTC_ASN1_INTEGER, 1UL, key->q, | 50 LTC_ASN1_INTEGER, 1UL, key->q, |
53 LTC_ASN1_INTEGER, 1UL, key->dP, | 51 LTC_ASN1_INTEGER, 1UL, key->dP, |
54 LTC_ASN1_INTEGER, 1UL, key->dQ, | 52 LTC_ASN1_INTEGER, 1UL, key->dQ, |
55 LTC_ASN1_INTEGER, 1UL, key->qP, | 53 LTC_ASN1_INTEGER, 1UL, key->qP, |
56 LTC_ASN1_INTEGER, 1UL, key->pq, | 54 LTC_ASN1_INTEGER, 1UL, key->pq, |
57 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | 55 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { |
58 return err; | 56 return err; |
59 } | 57 } |
60 | 58 |
61 /* clear zero and return */ | 59 /* clear zero and return */ |
62 return CRYPT_OK; | 60 return CRYPT_OK; |
63 } else { | 61 } else { |
64 /* public key */ | 62 /* public key */ |
65 return der_encode_sequence_multi(out, outlen, | 63 return der_encode_sequence_multi(out, outlen, |
66 LTC_ASN1_INTEGER, 1UL, key->N, | 64 LTC_ASN1_INTEGER, 1UL, key->N, |
67 LTC_ASN1_EOL, 0UL, NULL); | 65 LTC_ASN1_EOL, 0UL, NULL); |
68 } | 66 } |
69 } | 67 } |
70 | 68 |
71 #endif /* LTC_MRSA */ | 69 #endif /* LTC_MRSA */ |
72 | 70 |
73 /* $Source$ */ | 71 /* ref: $Format:%D$ */ |
74 /* $Revision$ */ | 72 /* git commit: $Format:%H$ */ |
75 /* $Date$ */ | 73 /* commit time: $Format:%ai$ */ |