From patchwork Sun Mar 19 19:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13180566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FAA6C77B60 for ; Sun, 19 Mar 2023 19:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjCSTjg (ORCPT ); Sun, 19 Mar 2023 15:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjCSTj3 (ORCPT ); Sun, 19 Mar 2023 15:39:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C3F11E87; Sun, 19 Mar 2023 12:39:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 23FF861166; Sun, 19 Mar 2023 19:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E61EC433EF; Sun, 19 Mar 2023 19:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679254743; bh=wOFl1sorqP7Hib+xYi2OZdOJlqgfvdW/EjWY9nlzE3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gnM1JSCU1gPgGaK9fpb5UjGxqZBWXUq2MzWKOeQi2k4//FcJqZyCDRfycnXaCUbuv zuVvaQ6TH0bP43nO+jgcrMfn6QVMqRvQUdXyLcMuFdNzjMKOUaf1ZATotYMyHxlYkr W2sqIKEgidLg9tuc4uuO/IBObTyAUIv8Zw2w9gXENnJdp0QdroCQp3HO35hTHNP58K jYeOyv43yzLCAcFnLu9Y0OutC3XB+Gwaog4cmZjWiY/u4R7afR/XsDQXA2AZ4hrrNA yU/Ia0EFDau/9O14Xaxg7W/uvR8mK3jXhonqavjyjnTXZyERYL57BPYPC5swdWxJ3K KrJpllbmntiSQ== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org Subject: [PATCH 1/3] fscrypt-crypt-util: fix HKDF self-test with latest OpenSSL Date: Sun, 19 Mar 2023 12:38:45 -0700 Message-Id: <20230319193847.106872-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230319193847.106872-1-ebiggers@kernel.org> References: <20230319193847.106872-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Eric Biggers In OpenSSL 3.0, EVP_PKEY_derive() fails if the output is zero-length. Therefore, update test_hkdf_sha512() to not test this case. This only affects the algorithm self-tests within fscrypt-crypt-util, which are not compiled by default. Signed-off-by: Eric Biggers --- src/fscrypt-crypt-util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c index 087ae09a..4bb4f4e5 100644 --- a/src/fscrypt-crypt-util.c +++ b/src/fscrypt-crypt-util.c @@ -975,7 +975,9 @@ static void test_hkdf_sha512(void) size_t ikmlen = 1 + (rand() % sizeof(ikm)); size_t saltlen = rand() % (1 + sizeof(salt)); size_t infolen = rand() % (1 + sizeof(info)); - size_t outlen = rand() % (1 + sizeof(actual_output)); + // Don't test zero-length outputs, since OpenSSL 3.0 and later + // returns an error for those. + size_t outlen = 1 + (rand() % sizeof(actual_output)); rand_bytes(ikm, ikmlen); rand_bytes(salt, saltlen); From patchwork Sun Mar 19 19:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13180565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79175C76196 for ; Sun, 19 Mar 2023 19:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjCSTjf (ORCPT ); Sun, 19 Mar 2023 15:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjCSTja (ORCPT ); Sun, 19 Mar 2023 15:39:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 574C3125AD; Sun, 19 Mar 2023 12:39:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 56ABF61176; Sun, 19 Mar 2023 19:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3B00C4339B; Sun, 19 Mar 2023 19:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679254743; bh=7Fq+zUNk8rLcgq8ldpUhuOpwwcT0yhPQ3w5BR7Tsj9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZuRv4883nem2Ox4QLe65Byk3NVW5X6w6kceL7/SLO2zYFKttTd/m2JmhyBRhW97uj 2Z7ZpeiPz+Eqt+/gbpu0IM756JZ/HvuOdOT0aaiuzHNhxvgVVVYosRiMZ7F1EAijMr NWvhRcfbabLMDTTmX7SnBL4aGD0dDUv846jGW/iFMdwnnPQkG/NLGPrq8U6n2pVoBu V7UznT6/w0XXlDMNW/gNCR07DPL+bnW6mx27LvpqeyEOGlyw5It+JwUIu2HRsfcTk6 M+9QP9HTwOXHfpjZsnlwQCtT0NLOjSN5poFIqfOsvvgwZfsdeHPtOZPLr0q2SoklwY 3bTqUsIGBhQEg== From: Eric Biggers 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 Message-Id: <20230319193847.106872-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230319193847.106872-1-ebiggers@kernel.org> References: <20230319193847.106872-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Eric Biggers 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 --- 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 +#include 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) From patchwork Sun Mar 19 19:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13180564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EE57C76195 for ; Sun, 19 Mar 2023 19:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbjCSTje (ORCPT ); Sun, 19 Mar 2023 15:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjCSTj3 (ORCPT ); Sun, 19 Mar 2023 15:39:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573DD11E96; Sun, 19 Mar 2023 12:39:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8F26461179; Sun, 19 Mar 2023 19:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8C72C4339C; Sun, 19 Mar 2023 19:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679254743; bh=XBZDmxFeSpqtrCWRREzzaete3GA1/5ivnYhQM9sc2To=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjsAAjt0smsHGFtXoThmukbzqKa6Qvx3KeiZiCsRZwUDadGwGAKATY8a9wG2Fwgzq RONShGcRaG3RrSuuh7CH+GwGcTfzrT2zvz8EqjjAoC9/ltBnQKY0LoWRo4Rb3kL+ky UVwTdun3QWGdnn/3iz9adupHAgQdX0Vl7cj2m9ZCnhepGe7VfcC7U9hdgPUhZfPGtY sA6x51edtuVhZrktypybILkuh509TDbzd9DOOBMfdRaIfxj4PnmTfz04zECVINPoOl RIOnD+um9kuMetTQPDstwcHIZ8L/kZT8wEj6wKeU4iZwarobXoO8yiqqrR7PGqrYBJ aVUH3dlOJjmlw== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org Subject: [PATCH 3/3] fscrypt-crypt-util: fix XTS self-test with latest OpenSSL Date: Sun, 19 Mar 2023 12:38:47 -0700 Message-Id: <20230319193847.106872-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230319193847.106872-1-ebiggers@kernel.org> References: <20230319193847.106872-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Eric Biggers In OpenSSL 3.0, XTS encryption fails if the message is zero-length. Therefore, update test_aes_256_xts() to not test this case. This only affects the algorithm self-tests within fscrypt-crypt-util, which are not compiled by default. Signed-off-by: Eric Biggers --- src/fscrypt-crypt-util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c index 040b80c0..6edf0047 100644 --- a/src/fscrypt-crypt-util.c +++ b/src/fscrypt-crypt-util.c @@ -1107,12 +1107,16 @@ static void test_aes_256_xts(void) while (num_tests--) { u8 key[2 * AES_256_KEY_SIZE]; u8 iv[AES_BLOCK_SIZE]; - u8 ptext[512]; + u8 ptext[32 * AES_BLOCK_SIZE]; u8 ctext[sizeof(ptext)]; u8 ref_ctext[sizeof(ptext)]; u8 decrypted[sizeof(ptext)]; - const size_t datalen = ROUND_DOWN(rand() % (1 + sizeof(ptext)), - AES_BLOCK_SIZE); + // Don't test message lengths that aren't a multiple of the AES + // block size, since support for that is not implemented here. + // Also don't test zero-length messages, since OpenSSL 3.0 and + // later returns an error for those. + const size_t datalen = AES_BLOCK_SIZE * + (1 + rand() % (sizeof(ptext) / AES_BLOCK_SIZE)); int outl, res; rand_bytes(key, sizeof(key));