From 727f1ed7f327018e95a13d223ad6a132e6775f5d Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 15 May 2023 00:16:39 -0400 Subject: [PATCH] Use BoringSSL's public API in keymaster_hidl_hal_test Reaching into the struct will fail to build in the future when we make the struct opaque. Use the public APIs instead. Test: mm, treehugger Change-Id: I78cbf5e66f0c4a891049edd187c8705ad163f658 --- .../3.0/vts/functional/keymaster_hidl_hal_test.cpp | 13 ++++++++----- .../4.0/vts/functional/keymaster_hidl_hal_test.cpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp index 554afe761a..65b3dfa8a2 100644 --- a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp +++ b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp @@ -2617,10 +2617,11 @@ TEST_P(EncryptionOperationsTest, RsaNoPaddingTooLarge) { EVP_PKEY_Ptr pkey(d2i_PUBKEY(nullptr /* alloc new */, &p, exported.size())); RSA_Ptr rsa(EVP_PKEY_get1_RSA(pkey.get())); - size_t modulus_len = BN_num_bytes(rsa->n); + const BIGNUM* n = RSA_get0_n(rsa.get()); + size_t modulus_len = BN_num_bytes(n); ASSERT_EQ(1024U / 8, modulus_len); std::unique_ptr modulus_buf(new uint8_t[modulus_len]); - BN_bn2bin(rsa->n, modulus_buf.get()); + BN_bn2bin(n, modulus_buf.get()); // The modulus is too big to encrypt. string message(reinterpret_cast(modulus_buf.get()), modulus_len); @@ -2632,10 +2633,12 @@ TEST_P(EncryptionOperationsTest, RsaNoPaddingTooLarge) { EXPECT_EQ(ErrorCode::INVALID_ARGUMENT, Finish(message, &result)); // One smaller than the modulus is okay. - BN_sub(rsa->n, rsa->n, BN_value_one()); - modulus_len = BN_num_bytes(rsa->n); + BIGNUM_Ptr n_minus_1(BN_new()); + ASSERT_TRUE(n_minus_1); + ASSERT_TRUE(BN_sub(n_minus_1.get(), n, BN_value_one())); + modulus_len = BN_num_bytes(n_minus_1.get()); ASSERT_EQ(1024U / 8, modulus_len); - BN_bn2bin(rsa->n, modulus_buf.get()); + BN_bn2bin(n_minus_1.get(), modulus_buf.get()); message = string(reinterpret_cast(modulus_buf.get()), modulus_len); EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::ENCRYPT, params)); EXPECT_EQ(ErrorCode::OK, Finish(message, &result)); diff --git a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp index b7099047fe..96580c04a7 100644 --- a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp +++ b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp @@ -2449,10 +2449,11 @@ TEST_P(EncryptionOperationsTest, RsaNoPaddingTooLarge) { EVP_PKEY_Ptr pkey(d2i_PUBKEY(nullptr /* alloc new */, &p, exported.size())); RSA_Ptr rsa(EVP_PKEY_get1_RSA(pkey.get())); - size_t modulus_len = BN_num_bytes(rsa->n); + const BIGNUM* n = RSA_get0_n(rsa.get()); + size_t modulus_len = BN_num_bytes(n); ASSERT_EQ(2048U / 8, modulus_len); std::unique_ptr modulus_buf(new uint8_t[modulus_len]); - BN_bn2bin(rsa->n, modulus_buf.get()); + BN_bn2bin(n, modulus_buf.get()); // The modulus is too big to encrypt. string message(reinterpret_cast(modulus_buf.get()), modulus_len); @@ -2464,10 +2465,12 @@ TEST_P(EncryptionOperationsTest, RsaNoPaddingTooLarge) { EXPECT_EQ(ErrorCode::INVALID_ARGUMENT, Finish(message, &result)); // One smaller than the modulus is okay. - BN_sub(rsa->n, rsa->n, BN_value_one()); - modulus_len = BN_num_bytes(rsa->n); + BIGNUM_Ptr n_minus_1(BN_new()); + ASSERT_TRUE(n_minus_1); + ASSERT_TRUE(BN_sub(n_minus_1.get(), n, BN_value_one())); + modulus_len = BN_num_bytes(n_minus_1.get()); ASSERT_EQ(2048U / 8, modulus_len); - BN_bn2bin(rsa->n, modulus_buf.get()); + BN_bn2bin(n_minus_1.get(), modulus_buf.get()); message = string(reinterpret_cast(modulus_buf.get()), modulus_len); EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::ENCRYPT, params)); EXPECT_EQ(ErrorCode::OK, Finish(message, &result));