Skip to content

Commit 165c795

Browse files
authored
Merge pull request #546 from libtom/fix-dsa-sha-dependency
fix DSA dependency to SHA2
2 parents 077f4d6 + 9a07c42 commit 165c795

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/headers/tomcrypt_pk.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,14 @@ int x25519_shared_secret(const curve25519_key *private_key,
384384

385385
#ifdef LTC_MDSA
386386

387-
/* Max diff between group and modulus size in bytes */
388-
#define LTC_MDSA_DELTA 512
387+
/* Max diff between group and modulus size in bytes (max case: L=8192bits, N=256bits) */
388+
#define LTC_MDSA_DELTA 992
389389

390-
/* Max DSA group size in bytes (default allows 4k-bit groups) */
391-
#define LTC_MDSA_MAX_GROUP 512
390+
/* Max DSA group size in bytes */
391+
#define LTC_MDSA_MAX_GROUP 64
392+
393+
/* Max DSA modulus size in bytes (the actual DSA size, max 8192 bits) */
394+
#define LTC_MDSA_MAX_MODULUS 1024
392395

393396
/** DSA key structure */
394397
typedef struct {

src/misc/crypt/crypt_constants.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static const crypt_constant s_crypt_constants[] = {
102102
{"LTC_MDSA", 1},
103103
C_STRINGIFY(LTC_MDSA_DELTA),
104104
C_STRINGIFY(LTC_MDSA_MAX_GROUP),
105+
C_STRINGIFY(LTC_MDSA_MAX_MODULUS),
105106
#else
106107
{"LTC_MDSA", 0},
107108
#endif

src/pk/dsa/dsa_generate_pqg.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
2626
int err, res, mr_tests_q, mr_tests_p, found_p, found_q, hash;
2727
unsigned char *wbuf, *sbuf, digest[MAXBLOCKSIZE];
2828
void *t2L1, *t2N1, *t2q, *t2seedlen, *U, *W, *X, *c, *h, *e, *seedinc;
29+
const char *accepted_hashes[] = { "sha3-512", "sha512", "sha3-384", "sha384", "sha3-256", "sha256" };
2930

3031
/* check size */
31-
if (group_size >= LTC_MDSA_MAX_GROUP || group_size < 1 || group_size >= modulus_size) {
32+
if (group_size > LTC_MDSA_MAX_GROUP || group_size < 1 || group_size >= modulus_size || modulus_size > LTC_MDSA_MAX_MODULUS) {
3233
return CRYPT_INVALID_ARG;
3334
}
3435

@@ -87,16 +88,15 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
8788
else { mr_tests_q = 64; }
8889
#endif
8990

90-
if (N <= 256) {
91-
hash = register_hash(&sha256_desc);
91+
hash = -1;
92+
for (i = 0; i < sizeof(accepted_hashes)/sizeof(accepted_hashes[0]); ++i) {
93+
hash = find_hash(accepted_hashes[i]);
94+
if (hash != -1) break;
9295
}
93-
else if (N <= 384) {
94-
hash = register_hash(&sha384_desc);
96+
if (hash == -1) {
97+
return CRYPT_INVALID_ARG; /* no appropriate hash function found */
9598
}
96-
else if (N <= 512) {
97-
hash = register_hash(&sha512_desc);
98-
}
99-
else {
99+
if (N > hash_descriptor[hash].hashsize * 8) {
100100
return CRYPT_INVALID_ARG; /* group_size too big */
101101
}
102102

0 commit comments

Comments
 (0)