|
@@ -26,9 +26,10 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
|
|
int err, res, mr_tests_q, mr_tests_p, found_p, found_q, hash;
|
|
int err, res, mr_tests_q, mr_tests_p, found_p, found_q, hash;
|
|
unsigned char *wbuf, *sbuf, digest[MAXBLOCKSIZE];
|
|
unsigned char *wbuf, *sbuf, digest[MAXBLOCKSIZE];
|
|
void *t2L1, *t2N1, *t2q, *t2seedlen, *U, *W, *X, *c, *h, *e, *seedinc;
|
|
void *t2L1, *t2N1, *t2q, *t2seedlen, *U, *W, *X, *c, *h, *e, *seedinc;
|
|
|
|
+ const char *accepted_hashes[] = { "sha3-512", "sha512", "sha3-384", "sha384", "sha3-256", "sha256" };
|
|
|
|
|
|
/* check size */
|
|
/* check size */
|
|
- if (group_size >= LTC_MDSA_MAX_GROUP || group_size < 1 || group_size >= modulus_size) {
|
|
|
|
|
|
+ if (group_size > LTC_MDSA_MAX_GROUP || group_size < 1 || group_size >= modulus_size || modulus_size > LTC_MDSA_MAX_MODULUS) {
|
|
return CRYPT_INVALID_ARG;
|
|
return CRYPT_INVALID_ARG;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,16 +88,15 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
|
|
else { mr_tests_q = 64; }
|
|
else { mr_tests_q = 64; }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- if (N <= 256) {
|
|
|
|
- hash = register_hash(&sha256_desc);
|
|
|
|
|
|
+ hash = -1;
|
|
|
|
+ for (i = 0; i < sizeof(accepted_hashes)/sizeof(accepted_hashes[0]); ++i) {
|
|
|
|
+ hash = find_hash(accepted_hashes[i]);
|
|
|
|
+ if (hash != -1) break;
|
|
}
|
|
}
|
|
- else if (N <= 384) {
|
|
|
|
- hash = register_hash(&sha384_desc);
|
|
|
|
|
|
+ if (hash == -1) {
|
|
|
|
+ return CRYPT_INVALID_ARG; /* no appropriate hash function found */
|
|
}
|
|
}
|
|
- else if (N <= 512) {
|
|
|
|
- hash = register_hash(&sha512_desc);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ if (N > hash_descriptor[hash].hashsize * 8) {
|
|
return CRYPT_INVALID_ARG; /* group_size too big */
|
|
return CRYPT_INVALID_ARG; /* group_size too big */
|
|
}
|
|
}
|
|
|
|
|