From 79ce98626255dc5f160c44c734f4ec33e5b995be Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Mon, 28 Oct 2024 08:50:53 -0400 Subject: [PATCH] Ruby Support - DSA custom md/qbits --- crypto/dsa/dsa.c | 14 ++++++++++---- crypto/dsa/internal.h | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c index aa44c2fdf53..24063ae8ac5 100644 --- a/crypto/dsa/dsa.c +++ b/crypto/dsa/dsa.c @@ -232,6 +232,15 @@ int DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) { int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in, size_t seed_len, int *out_counter, unsigned long *out_h, BN_GENCB *cb) { + const EVP_MD *evpmd = (bits >= 2048) ? EVP_sha256() : EVP_sha1(); + return dsa_internal_paramgen(dsa, bits, evpmd, seed_in, seed_len, out_counter, out_h, cb); +} + +int dsa_internal_paramgen(DSA *dsa, size_t bits, const EVP_MD *evpmd, + const unsigned char *seed_in, size_t seed_len, + int *out_counter, unsigned long *out_h, + BN_GENCB *cb) +{ int ok = 0; unsigned char seed[SHA256_DIGEST_LENGTH]; unsigned char md[SHA256_DIGEST_LENGTH]; @@ -244,10 +253,7 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in, int r = 0; BN_CTX *ctx = NULL; unsigned int h = 2; - const EVP_MD *evpmd; - - evpmd = (bits >= 2048) ? EVP_sha256() : EVP_sha1(); - size_t qsize = EVP_MD_size(evpmd); + const size_t qsize = EVP_MD_size(evpmd); if (bits < 512) { bits = 512; diff --git a/crypto/dsa/internal.h b/crypto/dsa/internal.h index aae32637c24..fb9b287cc02 100644 --- a/crypto/dsa/internal.h +++ b/crypto/dsa/internal.h @@ -44,6 +44,9 @@ struct dsa_st { // DoS bounds. It returns one on success and zero on error. int dsa_check_key(const DSA *dsa); +int dsa_internal_paramgen(DSA *dsa, size_t bits, const EVP_MD *evpmd, + const unsigned char *seed_in, size_t seed_len, + int *out_counter, unsigned long *out_h, BN_GENCB *cb); #if defined(__cplusplus) } // extern C