From: Eric Biggers <ebiggers@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org
Subject: [PATCH 2/3] fscrypt-crypt-util: use OpenSSL EVP API for AES self-tests
Date: Sun, 19 Mar 2023 12:38:46 -0700 [thread overview]
Message-ID: <20230319193847.106872-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20230319193847.106872-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
OpenSSL 3.0 has deprecated the easy-to-use AES block cipher API in favor
of EVP. EVP is also available in earlier OpenSSL versions. Therefore,
update test_aes_keysize() to use the non-deprecated API to avoid
deprecation warnings when building the algorithm self-tests.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
src/fscrypt-crypt-util.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c
index 4bb4f4e5..040b80c0 100644
--- a/src/fscrypt-crypt-util.c
+++ b/src/fscrypt-crypt-util.c
@@ -662,19 +662,37 @@ static void aes_decrypt(const struct aes_key *k, const u8 src[AES_BLOCK_SIZE],
}
#ifdef ENABLE_ALG_TESTS
-#include <openssl/aes.h>
+#include <openssl/evp.h>
static void test_aes_keysize(int keysize)
{
unsigned long num_tests = NUM_ALG_TEST_ITERATIONS;
+ const EVP_CIPHER *evp_cipher;
+ EVP_CIPHER_CTX *ctx;
+
+ switch (keysize) {
+ case 16:
+ evp_cipher = EVP_aes_128_ecb();
+ break;
+ case 24:
+ evp_cipher = EVP_aes_192_ecb();
+ break;
+ case 32:
+ evp_cipher = EVP_aes_256_ecb();
+ break;
+ default:
+ ASSERT(0);
+ }
+ ctx = EVP_CIPHER_CTX_new();
+ ASSERT(ctx != NULL);
while (num_tests--) {
struct aes_key k;
- AES_KEY ref_k;
u8 key[AES_256_KEY_SIZE];
u8 ptext[AES_BLOCK_SIZE];
u8 ctext[AES_BLOCK_SIZE];
u8 ref_ctext[AES_BLOCK_SIZE];
u8 decrypted[AES_BLOCK_SIZE];
+ int outl, res;
rand_bytes(key, keysize);
rand_bytes(ptext, AES_BLOCK_SIZE);
@@ -682,14 +700,18 @@ static void test_aes_keysize(int keysize)
aes_setkey(&k, key, keysize);
aes_encrypt(&k, ptext, ctext);
- ASSERT(AES_set_encrypt_key(key, keysize*8, &ref_k) == 0);
- AES_encrypt(ptext, ref_ctext, &ref_k);
-
+ res = EVP_EncryptInit_ex(ctx, evp_cipher, NULL, key, NULL);
+ ASSERT(res > 0);
+ res = EVP_EncryptUpdate(ctx, ref_ctext, &outl, ptext,
+ AES_BLOCK_SIZE);
+ ASSERT(res > 0);
+ ASSERT(outl == AES_BLOCK_SIZE);
ASSERT(memcmp(ctext, ref_ctext, AES_BLOCK_SIZE) == 0);
aes_decrypt(&k, ctext, decrypted);
ASSERT(memcmp(ptext, decrypted, AES_BLOCK_SIZE) == 0);
}
+ EVP_CIPHER_CTX_free(ctx);
}
static void test_aes(void)
--
2.40.0
next prev parent reply other threads:[~2023-03-19 19:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-19 19:38 [PATCH 0/3] xfstests: make fscrypt-crypt-util self-tests work with OpenSSL 3.0 Eric Biggers
2023-03-19 19:38 ` [PATCH 1/3] fscrypt-crypt-util: fix HKDF self-test with latest OpenSSL Eric Biggers
2023-03-19 19:38 ` Eric Biggers [this message]
2023-03-19 19:38 ` [PATCH 3/3] fscrypt-crypt-util: fix XTS " Eric Biggers
2023-03-20 14:03 ` [PATCH 0/3] xfstests: make fscrypt-crypt-util self-tests work with OpenSSL 3.0 Zorro Lang
2023-03-20 16:20 ` Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230319193847.106872-3-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox