Mercurial > dropbear
comparison libtomcrypt/src/pk/katja/katja_import.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_import.c | 12 @file katja_import.c |
15 Import a LTC_PKCS-style Katja key, Tom St Denis | 13 Import a PKCS-style Katja key, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef MKAT | 16 #ifdef LTC_MKAT |
19 | 17 |
20 /** | 18 /** |
21 Import an KatjaPublicKey or KatjaPrivateKey [two-prime only, only support >= 1024-bit keys, defined in LTC_PKCS #1 v2.1] | 19 Import an KatjaPublicKey or KatjaPrivateKey [two-prime only, only support >= 1024-bit keys, defined in PKCS #1 v2.1] |
22 @param in The packet to import from | 20 @param in The packet to import from |
23 @param inlen It's length (octets) | 21 @param inlen It's length (octets) |
24 @param key [out] Destination for newly imported key | 22 @param key [out] Destination for newly imported key |
25 @return CRYPT_OK if successful, upon error allocated memory is freed | 23 @return CRYPT_OK if successful, upon error allocated memory is freed |
26 */ | 24 */ |
32 LTC_ARGCHK(in != NULL); | 30 LTC_ARGCHK(in != NULL); |
33 LTC_ARGCHK(key != NULL); | 31 LTC_ARGCHK(key != NULL); |
34 LTC_ARGCHK(ltc_mp.name != NULL); | 32 LTC_ARGCHK(ltc_mp.name != NULL); |
35 | 33 |
36 /* init key */ | 34 /* init key */ |
37 if ((err = mp_init_multi(&zero, &key->d, &key->N, &key->dQ, | 35 if ((err = mp_init_multi(&zero, &key->d, &key->N, &key->dQ, |
38 &key->dP, &key->qP, &key->p, &key->q, &key->pq, NULL)) != CRYPT_OK) { | 36 &key->dP, &key->qP, &key->p, &key->q, &key->pq, NULL)) != CRYPT_OK) { |
39 return err; | 37 return err; |
40 } | 38 } |
41 | 39 |
42 if ((err = der_decode_sequence_multi(in, inlen, | 40 if ((err = der_decode_sequence_multi(in, inlen, |
43 LTC_ASN1_INTEGER, 1UL, key->N, | 41 LTC_ASN1_INTEGER, 1UL, key->N, |
44 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | 42 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { |
45 goto LBL_ERR; | 43 goto LBL_ERR; |
46 } | 44 } |
47 | 45 |
48 if (mp_cmp_d(key->N, 0) == LTC_MP_EQ) { | 46 if (mp_cmp_d(key->N, 0) == LTC_MP_EQ) { |
49 /* it's a private key */ | 47 /* it's a private key */ |
50 if ((err = der_decode_sequence_multi(in, inlen, | 48 if ((err = der_decode_sequence_multi(in, inlen, |
51 LTC_ASN1_INTEGER, 1UL, zero, | 49 LTC_ASN1_INTEGER, 1UL, zero, |
52 LTC_ASN1_INTEGER, 1UL, key->N, | 50 LTC_ASN1_INTEGER, 1UL, key->N, |
53 LTC_ASN1_INTEGER, 1UL, key->d, | 51 LTC_ASN1_INTEGER, 1UL, key->d, |
54 LTC_ASN1_INTEGER, 1UL, key->p, | 52 LTC_ASN1_INTEGER, 1UL, key->p, |
55 LTC_ASN1_INTEGER, 1UL, key->q, | 53 LTC_ASN1_INTEGER, 1UL, key->q, |
56 LTC_ASN1_INTEGER, 1UL, key->dP, | 54 LTC_ASN1_INTEGER, 1UL, key->dP, |
57 LTC_ASN1_INTEGER, 1UL, key->dQ, | 55 LTC_ASN1_INTEGER, 1UL, key->dQ, |
58 LTC_ASN1_INTEGER, 1UL, key->qP, | 56 LTC_ASN1_INTEGER, 1UL, key->qP, |
59 LTC_ASN1_INTEGER, 1UL, key->pq, | 57 LTC_ASN1_INTEGER, 1UL, key->pq, |
60 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | 58 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { |
61 goto LBL_ERR; | 59 goto LBL_ERR; |
62 } | 60 } |
63 key->type = PK_PRIVATE; | 61 key->type = PK_PRIVATE; |
64 } else { | 62 } else { |
74 } | 72 } |
75 | 73 |
76 #endif /* LTC_MRSA */ | 74 #endif /* LTC_MRSA */ |
77 | 75 |
78 | 76 |
79 /* $Source$ */ | 77 /* ref: $Format:%D$ */ |
80 /* $Revision$ */ | 78 /* git commit: $Format:%H$ */ |
81 /* $Date$ */ | 79 /* commit time: $Format:%ai$ */ |