comparison libtomcrypt/src/pk/dsa/dsa_set_pqg_dsaparam.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 #include "tomcrypt.h"
10
11
12 #ifdef LTC_MDSA
13
14 /**
15 Import DSA's p, q & g from dsaparam
16
17 dsaparam data: openssl dsaparam -outform DER -out dsaparam.der 2048
18
19 @param dsaparam The DSA param DER encoded data
20 @param dsaparamlen The length of dhparam data
21 @param key [out] the destination for the imported key
22 @return CRYPT_OK if successful.
23 */
24 int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamlen,
25 dsa_key *key)
26 {
27 int err, stat;
28
29 LTC_ARGCHK(dsaparam != NULL);
30 LTC_ARGCHK(key != NULL);
31 LTC_ARGCHK(ltc_mp.name != NULL);
32
33 /* init key */
34 err = mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
35 if (err != CRYPT_OK) return err;
36
37 if ((err = der_decode_sequence_multi(dsaparam, dsaparamlen,
38 LTC_ASN1_INTEGER, 1UL, key->p,
39 LTC_ASN1_INTEGER, 1UL, key->q,
40 LTC_ASN1_INTEGER, 1UL, key->g,
41 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
42 goto LBL_ERR;
43 }
44
45 key->qord = mp_unsigned_bin_size(key->q);
46
47 /* quick p, q, g validation, without primality testing */
48 if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) {
49 goto LBL_ERR;
50 }
51 if (stat == 0) {
52 err = CRYPT_INVALID_PACKET;
53 goto LBL_ERR;
54 }
55
56 return CRYPT_OK;
57
58 LBL_ERR:
59 dsa_free(key);
60 return err;
61 }
62
63 #endif
64
65 /* ref: $Format:%D$ */
66 /* git commit: $Format:%H$ */
67 /* commit time: $Format:%ai$ */