Skip to contentSkip to conversation

crypto: adiantum - Switch to the ChaCha library

RFC Laveesh Bansal 2 participants 2 messages Nov 27 – Nov 28 Crypto API

lore
Share & tools
lore
#0 lore raw

Hi Eric

In the thread for your setkey patch

Quoted 2 lines · (https://lore.kernel.org/all/20261127184407.GB1974@quark/) you wrote:

Later we should shrink the required stack space by switching from crypto_skcipher to the ChaCha library.

If you have not started on this, I would like to do it as a follow-up once your setkey and AES library patches are applied. I have a prototype and would like to check the approach with you first.

It is two patches on top of yours. The first makes adiantum_setkey() derive the subkeys with chacha_init(), hchacha_block() and chacha_crypt(), so the skcipher request on the stack goes away. The second makes adiantum_crypt() call the library directly. It walks src and dst with two scatter_walks, rounds each step down to a multiple of 64 bytes unless it is the last, and uses a 64-byte bounce buffer for shorter pieces. It removes the child tfm and the spawn. The algorithm names stay the same.

I tested on arm64 with gcc 13.3.0 and KASAN, lockdep and CRYPTO_SELFTESTS enabled (and _FULL with both patches applied). Random cases through AF_ALG give the same ciphertext as the code with and without your patches. A test module with odd scatterlist splits, in and out of place, also passes. I saw no KASAN or lockdep reports and no selftest failures. The adiantum_setkey() stack frame is much smaller than with your patch. The adiantum_crypt() frame is larger than before, and the data path as a whole stays about the same depth. I have not tried x86_64 or s390x yet.

There is no second adiantum driver for testmgr to compare against, so its vectors are the only in-tree check. None of them has full ChaCha blocks followed by a partial one. Before the cleanup I can add a few that do.

Do the overall design and direction look fine to you? If so, I can start with the vectors and then send the cleanup patch series.

Thanks
Laveesh

#1 lore raw
Quoted 31 lines · Laveesh Bansal

Hi Eric

In the thread for your setkey patch

Quoted 2 lines · (https://lore.kernel.org/all/20261127184407.GB1974@quark/) you wrote:

Later we should shrink the required stack space by switching from crypto_skcipher to the ChaCha library.

If you have not started on this, I would like to do it as a follow-up once your setkey and AES library patches are applied. I have a prototype and would like to check the approach with you first.

It is two patches on top of yours. The first makes adiantum_setkey() derive the subkeys with chacha_init(), hchacha_block() and chacha_crypt(), so the skcipher request on the stack goes away. The second makes adiantum_crypt() call the library directly. It walks src and dst with two scatter_walks, rounds each step down to a multiple of 64 bytes unless it is the last, and uses a 64-byte bounce buffer for shorter pieces. It removes the child tfm and the spawn. The algorithm names stay the same.

I tested on arm64 with gcc 13.3.0 and KASAN, lockdep and CRYPTO_SELFTESTS enabled (and _FULL with both patches applied). Random cases through AF_ALG give the same ciphertext as the code with and without your patches. A test module with odd scatterlist splits, in and out of place, also passes. I saw no KASAN or lockdep reports and no selftest failures. The adiantum_setkey() stack frame is much smaller than with your patch. The adiantum_crypt() frame is larger than before, and the data path as a whole stays about the same depth. I have not tried x86_64 or s390x yet.

Quoted 7 lines

There is no second adiantum driver for testmgr to compare against, so its vectors are the only in-tree check. None of them has full ChaCha blocks followed by a partial one. Before the cleanup I can add a few that do.

Do the overall design and direction look fine to you? If so, I can start with the vectors and then send the cleanup patch series.

Probably. I'd like to provide Adiantum support in lib/crypto/, but this might be another worthwhile intermediate step. If you want to do what you proposed, go ahead and send the patches, making sure to include the base-commit and prerequisite-patch-id lines so that it's clear how to apply them. Besides that, the pace of everything has picked up due to AI coding tools, so I don't think I can be expected to give detailed feedback on an AI-assisted email like this where there are no patches. Once there are patches it will be more concrete what you mean.

- Eric