Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Oct 7, 2024
1 parent c9562cb commit fe914e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crypto/evp_extra/evp_extra_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,13 @@ TEST(EVPExtraTest, DHParamgen) {
EVP_PKEY *raw_pkey = NULL;
// Generate the parameters
ASSERT_TRUE(EVP_PKEY_paramgen(ctx.get(), &raw_pkey));
EVP_PKEY_free(raw_pkey);
bssl::UniquePtr<EVP_PKEY> pkey(raw_pkey);
ASSERT_TRUE(raw_pkey);

const DH* dh = EVP_PKEY_get0_DH(pkey.get());
const BIGNUM* p = DH_get0_p(dh);
unsigned p_size = BN_num_bits(p);
ASSERT_EQ(p_size, (unsigned)prime_len);
}

// Test error conditions
Expand Down
26 changes: 26 additions & 0 deletions crypto/fipsmodule/evp/evp_ctx_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "internal.h"

#include <gtest/gtest.h>
#include <openssl/dh.h>
#include <openssl/ec_key.h>
#include <openssl/err.h>
#include <openssl/evp.h>
Expand Down Expand Up @@ -239,6 +240,31 @@ TEST_F(EvpPkeyCtxCtrlStrTest, DhPad) {
// There is no function to retrieve the DH pad value.
}

TEST_F(EvpPkeyCtxCtrlStrTest, DhParamGen) {
// Create a EVP_PKEY_CTX with a newly generated DH
bssl::UniquePtr<EVP_PKEY_CTX> ctx(EVP_PKEY_CTX_new_id(EVP_PKEY_DH, nullptr));
ASSERT_TRUE(ctx);
ASSERT_TRUE(EVP_PKEY_paramgen_init(ctx.get()));

ASSERT_EQ(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_prime_len", "256"), 1);
ASSERT_NE(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_prime_len", "gg"), 1);
ASSERT_NE(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_prime_len", "255"), 1);

ASSERT_EQ(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_generator", "5"), 1);
ASSERT_NE(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_prime_len", "gg"), 1);
ASSERT_NE(EVP_PKEY_CTX_ctrl_str(ctx.get(), "dh_paramgen_prime_len", "1"), 1);

EVP_PKEY* raw = nullptr;
ASSERT_EQ(EVP_PKEY_paramgen(ctx.get(), &raw), 1);
bssl::UniquePtr<EVP_PKEY> pkey(raw);
ASSERT_TRUE(raw);

const DH* dh = EVP_PKEY_get0_DH(pkey.get());
const BIGNUM* p = DH_get0_p(dh);
unsigned p_size = BN_num_bits(p);
ASSERT_EQ(p_size, 256u);
}

static const char *hkdf_hexsalt = "000102030405060708090a0b0c";
static const char *hkdf_hexinfo = "f0f1f2f3f4f5f6f7f8f9";
static const char *hkdf_hexkey = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b";
Expand Down

0 comments on commit fe914e4

Please sign in to comment.