Mercurial > dropbear
comparison libtomcrypt/src/pk/dh/dh_set_pg_dhparam.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 | |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
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 | |
10 #include "tomcrypt.h" | |
11 | |
12 #ifdef LTC_MDH | |
13 | |
14 /** | |
15 Import DH key parts p and g from dhparam | |
16 | |
17 dhparam data: openssl dhparam -outform DER -out dhparam.der 2048 | |
18 | |
19 @param dhparam The DH param DER encoded data | |
20 @param dhparamlen The length of dhparam data | |
21 @param key [out] Where the newly created DH key will be stored | |
22 @return CRYPT_OK if successful, note: on error all allocated memory will be freed automatically. | |
23 */ | |
24 int dh_set_pg_dhparam(const unsigned char *dhparam, unsigned long dhparamlen, dh_key *key) | |
25 { | |
26 int err; | |
27 | |
28 LTC_ARGCHK(key != NULL); | |
29 LTC_ARGCHK(ltc_mp.name != NULL); | |
30 LTC_ARGCHK(dhparam != NULL); | |
31 LTC_ARGCHK(dhparamlen > 0); | |
32 | |
33 if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, NULL)) != CRYPT_OK) { | |
34 return err; | |
35 } | |
36 if ((err = der_decode_sequence_multi(dhparam, dhparamlen, | |
37 LTC_ASN1_INTEGER, 1UL, key->prime, | |
38 LTC_ASN1_INTEGER, 1UL, key->base, | |
39 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | |
40 goto LBL_ERR; | |
41 } | |
42 | |
43 return CRYPT_OK; | |
44 | |
45 LBL_ERR: | |
46 dh_free(key); | |
47 return err; | |
48 } | |
49 | |
50 #endif /* LTC_MDH */ | |
51 | |
52 /* ref: $Format:%D$ */ | |
53 /* git commit: $Format:%H$ */ | |
54 /* commit time: $Format:%ai$ */ |