@@ -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