Browse Source

DSA gen params: fixed check group_size vs LTC_MDSA_MAX_GROUP, updated LTC_MDSA_DELTA, new LTC_MDSA_MAX_MODULUS

Karel Miko 4 years ago
parent
commit
9a07c425bd
3 changed files with 9 additions and 5 deletions
  1. 7 4
      src/headers/tomcrypt_pk.h
  2. 1 0
      src/misc/crypt/crypt_constants.c
  3. 1 1
      src/pk/dsa/dsa_generate_pqg.c

+ 7 - 4
src/headers/tomcrypt_pk.h

@@ -384,11 +384,14 @@ int x25519_shared_secret(const curve25519_key *private_key,
 
 
 #ifdef LTC_MDSA
 #ifdef LTC_MDSA
 
 
-/* Max diff between group and modulus size in bytes */
-#define LTC_MDSA_DELTA     512
+/* Max diff between group and modulus size in bytes (max case: L=8192bits, N=256bits) */
+#define LTC_MDSA_DELTA 992
 
 
-/* Max DSA group size in bytes (default allows 4k-bit groups) */
-#define LTC_MDSA_MAX_GROUP 512
+/* Max DSA group size in bytes */
+#define LTC_MDSA_MAX_GROUP 64
+
+/* Max DSA modulus size in bytes (the actual DSA size, max 8192 bits) */
+#define LTC_MDSA_MAX_MODULUS 1024
 
 
 /** DSA key structure */
 /** DSA key structure */
 typedef struct {
 typedef struct {

+ 1 - 0
src/misc/crypt/crypt_constants.c

@@ -102,6 +102,7 @@ static const crypt_constant s_crypt_constants[] = {
     {"LTC_MDSA", 1},
     {"LTC_MDSA", 1},
     C_STRINGIFY(LTC_MDSA_DELTA),
     C_STRINGIFY(LTC_MDSA_DELTA),
     C_STRINGIFY(LTC_MDSA_MAX_GROUP),
     C_STRINGIFY(LTC_MDSA_MAX_GROUP),
+    C_STRINGIFY(LTC_MDSA_MAX_MODULUS),
 #else
 #else
     {"LTC_MDSA", 0},
     {"LTC_MDSA", 0},
 #endif
 #endif

+ 1 - 1
src/pk/dsa/dsa_generate_pqg.c

@@ -29,7 +29,7 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
   const char *accepted_hashes[] = { "sha3-512", "sha512", "sha3-384", "sha384", "sha3-256", "sha256" };
   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;
   }
   }