|
| 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; |
| 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 | + if (key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 || |
| 48 | + (unsigned long)key->qord >= mp_unsigned_bin_size(key->p) || (mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA) { |
| 49 | + err = CRYPT_INVALID_PACKET; |
| 50 | + goto LBL_ERR; |
| 51 | + } |
| 52 | + return CRYPT_OK; |
| 53 | + |
| 54 | +LBL_ERR: |
| 55 | + dsa_free(key); |
| 56 | + return err; |
| 57 | +} |
| 58 | + |
| 59 | +#endif |
| 60 | + |
| 61 | +/* ref: $Format:%D$ */ |
| 62 | +/* git commit: $Format:%H$ */ |
| 63 | +/* commit time: $Format:%ai$ */ |
0 commit comments