From: Eric Biggers <ebiggers@kernel.org> To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel <ardb@kernel.org>, Sami Tolvanen <samitolvanen@google.com>, Bart Van Assche <bvanassche@acm.org> Subject: [RFC PATCH 3/8] crypto: testmgr - add tests for finup2x Date: Mon, 15 Apr 2024 14:37:14 -0700 [thread overview] Message-ID: <20240415213719.120673-4-ebiggers@kernel.org> (raw) In-Reply-To: <20240415213719.120673-1-ebiggers@kernel.org> From: Eric Biggers <ebiggers@google.com> Update the shash self-tests to test the new finup2x method when CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y. Signed-off-by: Eric Biggers <ebiggers@google.com> --- crypto/testmgr.c | 53 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 2200d70e2aa9d..e6d42db6f344e 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -227,10 +227,12 @@ enum flush_type { /* finalization function for hash algorithms */ enum finalization_type { FINALIZATION_TYPE_FINAL, /* use final() */ FINALIZATION_TYPE_FINUP, /* use finup() */ + FINALIZATION_TYPE_FINUP2X_BUF1, /* use 1st buffer of finup2x() */ + FINALIZATION_TYPE_FINUP2X_BUF2, /* use 2nd buffer of finup2x() */ FINALIZATION_TYPE_DIGEST, /* use digest() */ }; /* * Whether the crypto operation will occur in-place, and if so whether the @@ -1105,19 +1107,27 @@ static void generate_random_testvec_config(struct rnd_state *rng, if (prandom_bool(rng)) { cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP; p += scnprintf(p, end - p, " may_sleep"); } - switch (prandom_u32_below(rng, 4)) { + switch (prandom_u32_below(rng, 6)) { case 0: cfg->finalization_type = FINALIZATION_TYPE_FINAL; p += scnprintf(p, end - p, " use_final"); break; case 1: cfg->finalization_type = FINALIZATION_TYPE_FINUP; p += scnprintf(p, end - p, " use_finup"); break; + case 2: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF1; + p += scnprintf(p, end - p, " use_finup2x_buf1"); + break; + case 3: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF2; + p += scnprintf(p, end - p, " use_finup2x_buf2"); + break; default: cfg->finalization_type = FINALIZATION_TYPE_DIGEST; p += scnprintf(p, end - p, " use_digest"); break; } @@ -1342,11 +1352,14 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, return -EINVAL; } goto result_ready; } - /* Using init(), zero or more update(), then final() or finup() */ + /* + * Using init(), zero or more update(), then either final(), finup(), or + * finup2x(). + */ if (cfg->nosimd) crypto_disable_simd_for_test(); err = crypto_shash_init(desc); if (cfg->nosimd) @@ -1354,28 +1367,50 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, err = check_shash_op("init", err, driver, vec_name, cfg); if (err) return err; for (i = 0; i < tsgl->nents; i++) { + const u8 *data = sg_virt(&tsgl->sgl[i]); + unsigned int len = tsgl->sgl[i].length; + if (i + 1 == tsgl->nents && - cfg->finalization_type == FINALIZATION_TYPE_FINUP) { + (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF1 || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF2)) { + const u8 *unused_data = tsgl->bufs[XBUFSIZE - 1]; + u8 unused_result[HASH_MAX_DIGESTSIZE]; + const char *op; + if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_finup(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length, result); + if (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + !crypto_shash_supports_finup2x(tfm)) { + err = crypto_shash_finup(desc, data, len, + result); + op = "finup"; + } else if (cfg->finalization_type == + FINALIZATION_TYPE_FINUP2X_BUF1) { + err = crypto_shash_finup2x( + desc, data, unused_data, len, + result, unused_result); + op = "finup2x_buf1"; + } else { /* FINALIZATION_TYPE_FINUP2X_BUF2 */ + err = crypto_shash_finup2x( + desc, unused_data, data, len, + unused_result, result); + op = "finup2x_buf2"; + } if (divs[i]->nosimd) crypto_reenable_simd_for_test(); - err = check_shash_op("finup", err, driver, vec_name, - cfg); + err = check_shash_op(op, err, driver, vec_name, cfg); if (err) return err; goto result_ready; } if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_update(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length); + err = crypto_shash_update(desc, data, len); if (divs[i]->nosimd) crypto_reenable_simd_for_test(); err = check_shash_op("update", err, driver, vec_name, cfg); if (err) return err; -- 2.44.0
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org> To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel <ardb@kernel.org>, Sami Tolvanen <samitolvanen@google.com>, Bart Van Assche <bvanassche@acm.org> Subject: [RFC PATCH 3/8] crypto: testmgr - add tests for finup2x Date: Mon, 15 Apr 2024 14:37:14 -0700 [thread overview] Message-ID: <20240415213719.120673-4-ebiggers@kernel.org> (raw) In-Reply-To: <20240415213719.120673-1-ebiggers@kernel.org> From: Eric Biggers <ebiggers@google.com> Update the shash self-tests to test the new finup2x method when CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y. Signed-off-by: Eric Biggers <ebiggers@google.com> --- crypto/testmgr.c | 53 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 2200d70e2aa9d..e6d42db6f344e 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -227,10 +227,12 @@ enum flush_type { /* finalization function for hash algorithms */ enum finalization_type { FINALIZATION_TYPE_FINAL, /* use final() */ FINALIZATION_TYPE_FINUP, /* use finup() */ + FINALIZATION_TYPE_FINUP2X_BUF1, /* use 1st buffer of finup2x() */ + FINALIZATION_TYPE_FINUP2X_BUF2, /* use 2nd buffer of finup2x() */ FINALIZATION_TYPE_DIGEST, /* use digest() */ }; /* * Whether the crypto operation will occur in-place, and if so whether the @@ -1105,19 +1107,27 @@ static void generate_random_testvec_config(struct rnd_state *rng, if (prandom_bool(rng)) { cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP; p += scnprintf(p, end - p, " may_sleep"); } - switch (prandom_u32_below(rng, 4)) { + switch (prandom_u32_below(rng, 6)) { case 0: cfg->finalization_type = FINALIZATION_TYPE_FINAL; p += scnprintf(p, end - p, " use_final"); break; case 1: cfg->finalization_type = FINALIZATION_TYPE_FINUP; p += scnprintf(p, end - p, " use_finup"); break; + case 2: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF1; + p += scnprintf(p, end - p, " use_finup2x_buf1"); + break; + case 3: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF2; + p += scnprintf(p, end - p, " use_finup2x_buf2"); + break; default: cfg->finalization_type = FINALIZATION_TYPE_DIGEST; p += scnprintf(p, end - p, " use_digest"); break; } @@ -1342,11 +1352,14 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, return -EINVAL; } goto result_ready; } - /* Using init(), zero or more update(), then final() or finup() */ + /* + * Using init(), zero or more update(), then either final(), finup(), or + * finup2x(). + */ if (cfg->nosimd) crypto_disable_simd_for_test(); err = crypto_shash_init(desc); if (cfg->nosimd) @@ -1354,28 +1367,50 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, err = check_shash_op("init", err, driver, vec_name, cfg); if (err) return err; for (i = 0; i < tsgl->nents; i++) { + const u8 *data = sg_virt(&tsgl->sgl[i]); + unsigned int len = tsgl->sgl[i].length; + if (i + 1 == tsgl->nents && - cfg->finalization_type == FINALIZATION_TYPE_FINUP) { + (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF1 || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF2)) { + const u8 *unused_data = tsgl->bufs[XBUFSIZE - 1]; + u8 unused_result[HASH_MAX_DIGESTSIZE]; + const char *op; + if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_finup(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length, result); + if (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + !crypto_shash_supports_finup2x(tfm)) { + err = crypto_shash_finup(desc, data, len, + result); + op = "finup"; + } else if (cfg->finalization_type == + FINALIZATION_TYPE_FINUP2X_BUF1) { + err = crypto_shash_finup2x( + desc, data, unused_data, len, + result, unused_result); + op = "finup2x_buf1"; + } else { /* FINALIZATION_TYPE_FINUP2X_BUF2 */ + err = crypto_shash_finup2x( + desc, unused_data, data, len, + unused_result, result); + op = "finup2x_buf2"; + } if (divs[i]->nosimd) crypto_reenable_simd_for_test(); - err = check_shash_op("finup", err, driver, vec_name, - cfg); + err = check_shash_op(op, err, driver, vec_name, cfg); if (err) return err; goto result_ready; } if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_update(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length); + err = crypto_shash_update(desc, data, len); if (divs[i]->nosimd) crypto_reenable_simd_for_test(); err = check_shash_op("update", err, driver, vec_name, cfg); if (err) return err; -- 2.44.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-15 21:38 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-15 21:37 [RFC PATCH 0/8] Optimize dm-verity and fsverity using multibuffer hashing Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 1/8] crypto: shash - add support for finup2x Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-19 10:35 ` Herbert Xu 2024-04-19 10:35 ` Herbert Xu 2024-04-19 16:30 ` Eric Biggers 2024-04-19 16:30 ` Eric Biggers 2024-04-26 8:56 ` Herbert Xu 2024-04-26 8:56 ` Herbert Xu 2024-04-15 21:37 ` [RFC PATCH 2/8] crypto: testmgr - generate power-of-2 lengths more often Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` Eric Biggers [this message] 2024-04-15 21:37 ` [RFC PATCH 3/8] crypto: testmgr - add tests for finup2x Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 4/8] crypto: x86/sha256-ni - add support " Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 5/8] crypto: arm64/sha256-ce " Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 6/8] fsverity: improve performance by using multibuffer hashing Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 7/8] dm-verity: hash blocks with shash import+finup when possible Eric Biggers 2024-04-15 21:37 ` Eric Biggers 2024-04-15 21:37 ` [RFC PATCH 8/8] dm-verity: improve performance by using multibuffer hashing Eric Biggers 2024-04-15 21:37 ` 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=20240415213719.120673-4-ebiggers@kernel.org \ --to=ebiggers@kernel.org \ --cc=ardb@kernel.org \ --cc=bvanassche@acm.org \ --cc=dm-devel@lists.linux.dev \ --cc=fsverity@lists.linux.dev \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-crypto@vger.kernel.org \ --cc=samitolvanen@google.com \ --cc=x86@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.