Skip to content

Commit 32d6508

Browse files
sjaeckelkarel-m
authored andcommitted
use sha3 if available
1 parent 96c72ec commit 32d6508

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/pk/dsa/dsa_generate_pqg.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,20 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
8888
#endif
8989

9090
hash = -1;
91-
#ifdef LTC_SHA256
92-
if (N <= 256) {
93-
hash = register_hash(&sha256_desc);
94-
}
95-
#endif
96-
#ifdef LTC_SHA384
97-
if ((N <= 384) && (hash == -1)) {
98-
hash = register_hash(&sha384_desc);
99-
}
100-
#endif
101-
#ifdef LTC_SHA512
102-
if ((N <= 512) && (hash == -1)) {
103-
hash = register_hash(&sha512_desc);
104-
}
91+
#if defined(LTC_SHA3)
92+
hash = register_hash(&sha3_512_desc);
93+
#elif defined(LTC_SHA512)
94+
hash = register_hash(&sha512_desc);
95+
#elif defined(LTC_SHA384)
96+
hash = register_hash(&sha384_desc);
97+
#elif defined(LTC_SHA256)
98+
hash = register_hash(&sha256_desc);
10599
#endif
106100
if (hash == -1) {
107-
return CRYPT_INVALID_ARG; /* group_size too big or no appropriate hash function found */
101+
return CRYPT_INVALID_ARG; /* no appropriate hash function found */
102+
}
103+
if (N > hash_descriptor[hash].hashsize * 8) {
104+
return CRYPT_INVALID_ARG; /* group_size too big */
108105
}
109106

110107
if ((err = hash_is_valid(hash)) != CRYPT_OK) { return err; }

0 commit comments

Comments
 (0)