Skip to content

Commit 5640f8a

Browse files
committed
put dsa_set_pqg_dsaparam() in own c file
1 parent 3c2e0d6 commit 5640f8a

2 files changed

Lines changed: 63 additions & 45 deletions

File tree

src/pk/dsa/dsa_set.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,51 +57,6 @@ int dsa_set_pqg(const unsigned char *p, unsigned long plen,
5757
return err;
5858
}
5959

60-
/**
61-
Import DSA's p, q & g from dsaparam
62-
63-
dsaparam data: openssl dsaparam -outform DER -out dsaparam.der 2048
64-
65-
@param dsaparam The DSA param DER encoded data
66-
@param dsaparamlen The length of dhparam data
67-
@param key [out] the destination for the imported key
68-
@return CRYPT_OK if successful.
69-
*/
70-
int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamlen,
71-
dsa_key *key)
72-
{
73-
int err;
74-
75-
LTC_ARGCHK(dsaparam != NULL);
76-
LTC_ARGCHK(key != NULL);
77-
LTC_ARGCHK(ltc_mp.name != NULL);
78-
79-
/* init key */
80-
err = mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
81-
if (err != CRYPT_OK) return err;
82-
83-
if ((err = der_decode_sequence_multi(dsaparam, dsaparamlen,
84-
LTC_ASN1_INTEGER, 1UL, key->p,
85-
LTC_ASN1_INTEGER, 1UL, key->q,
86-
LTC_ASN1_INTEGER, 1UL, key->g,
87-
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
88-
goto LBL_ERR;
89-
}
90-
91-
key->qord = mp_unsigned_bin_size(key->q);
92-
93-
if (key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
94-
(unsigned long)key->qord >= mp_unsigned_bin_size(key->p) || (mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA) {
95-
err = CRYPT_INVALID_PACKET;
96-
goto LBL_ERR;
97-
}
98-
return CRYPT_OK;
99-
100-
LBL_ERR:
101-
dsa_free(key);
102-
return err;
103-
}
104-
10560
/**
10661
Import DSA public or private key from raw numbers
10762
@param pub DSA's y (public key) in binary representation

src/pk/dsa/dsa_set_pqg_dsaparam.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)