comparison libtomcrypt/src/pk/ecc/ecc_decrypt_key.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
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 9
12 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 10 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
13 * 11 *
14 * All curves taken from NIST recommendation paper of July 1999 12 * All curves taken from NIST recommendation paper of July 1999
17 #include "tomcrypt.h" 15 #include "tomcrypt.h"
18 16
19 /** 17 /**
20 @file ecc_decrypt_key.c 18 @file ecc_decrypt_key.c
21 ECC Crypto, Tom St Denis 19 ECC Crypto, Tom St Denis
22 */ 20 */
23 21
24 #if defined(LTC_MECC) && defined(LTC_DER) 22 #if defined(LTC_MECC) && defined(LTC_DER)
25 23
26 /** 24 /**
27 Decrypt an ECC encrypted key 25 Decrypt an ECC encrypted key
31 @param outlen [in/out] The max size and resulting size of the plaintext 29 @param outlen [in/out] The max size and resulting size of the plaintext
32 @param key The corresponding private ECC key 30 @param key The corresponding private ECC key
33 @return CRYPT_OK if successful 31 @return CRYPT_OK if successful
34 */ 32 */
35 int ecc_decrypt_key(const unsigned char *in, unsigned long inlen, 33 int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
36 unsigned char *out, unsigned long *outlen, 34 unsigned char *out, unsigned long *outlen,
37 ecc_key *key) 35 ecc_key *key)
38 { 36 {
39 unsigned char *ecc_shared, *skey, *pub_expt; 37 unsigned char *ecc_shared, *skey, *pub_expt;
40 unsigned long x, y, hashOID[32]; 38 unsigned long x, y;
39 unsigned long hashOID[32] = { 0 };
41 int hash, err; 40 int hash, err;
42 ecc_key pubkey; 41 ecc_key pubkey;
43 ltc_asn1_list decode[3]; 42 ltc_asn1_list decode[3];
44 43
45 LTC_ARGCHK(in != NULL); 44 LTC_ARGCHK(in != NULL);
49 48
50 /* right key type? */ 49 /* right key type? */
51 if (key->type != PK_PRIVATE) { 50 if (key->type != PK_PRIVATE) {
52 return CRYPT_PK_NOT_PRIVATE; 51 return CRYPT_PK_NOT_PRIVATE;
53 } 52 }
54 53
55 /* decode to find out hash */ 54 /* decode to find out hash */
56 LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, sizeof(hashOID)/sizeof(hashOID[0])); 55 LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, sizeof(hashOID)/sizeof(hashOID[0]));
57 56 err = der_decode_sequence(in, inlen, decode, 1);
58 if ((err = der_decode_sequence(in, inlen, decode, 1)) != CRYPT_OK) { 57 if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
59 return err; 58 return err;
60 } 59 }
61 60
62 hash = find_hash_oid(hashOID, decode[0].size); 61 hash = find_hash_oid(hashOID, decode[0].size);
63 if (hash_is_valid(hash) != CRYPT_OK) { 62 if (hash_is_valid(hash) != CRYPT_OK) {
64 return CRYPT_INVALID_PACKET; 63 return CRYPT_INVALID_PACKET;
65 } 64 }
66 65
67 /* we now have the hash! */ 66 /* we now have the hash! */
142 return err; 141 return err;
143 } 142 }
144 143
145 #endif 144 #endif
146 145
147 /* $Source$ */ 146 /* ref: $Format:%D$ */
148 /* $Revision$ */ 147 /* git commit: $Format:%H$ */
149 /* $Date$ */ 148 /* commit time: $Format:%ai$ */
150 149