mbox series

[v2,0/3] crypto: lib - create utils module

Message ID 20220716062920.210381-1-ebiggers@kernel.org
Headers show
Series crypto: lib - create utils module | expand

Message

Eric Biggers July 16, 2022, 6:29 a.m. UTC
Create a utils module in lib/crypto/, and move __crypto_memneq,
__crypto_xor, and crypto_simd_disabled_for_test into it.

This supersedes "crypto: xor - move __crypto_xor into lib/"
(https://lore.kernel.org/linux-crypto/20220709215453.262237-1-ebiggers@kernel.org/T/#u).

Eric Biggers (3):
  crypto: lib - create utils module and move __crypto_memneq into it
  crypto: lib - move __crypto_xor into utils
  crypto: lib - move crypto_simd_disabled_for_test into utils

 crypto/Kconfig            |  2 +-
 crypto/algapi.c           | 77 ---------------------------------
 lib/Kconfig               |  3 --
 lib/Makefile              |  1 -
 lib/crypto/Kconfig        |  8 ++--
 lib/crypto/Makefile       |  3 ++
 lib/{ => crypto}/memneq.c |  0
 lib/crypto/utils.c        | 91 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 100 insertions(+), 85 deletions(-)
 rename lib/{ => crypto}/memneq.c (100%)
 create mode 100644 lib/crypto/utils.c


base-commit: ec8f7f4821d5e70d71601519bc2325b311324a96

Comments

Jason A. Donenfeld July 16, 2022, 6:32 p.m. UTC | #1
Hi Eric,

On Fri, Jul 15, 2022 at 11:29:20PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Move the definition of crypto_simd_disabled_for_test into
> lib/crypto/utils.c so that it can be accessed by library code.
> 
> This is needed when code that is shared between a traditional crypto API
> implementation and a library implementation is built-in, but
> CRYPTO_ALGAPI=m.  The x86 blake2s previously was an example of this
> (https://lore.kernel.org/linux-crypto/20220517033630.1182-1-gaochao49@huawei.com/T/#u).
> Although that case was resolved by removing the blake2s shash support,
> this problem could easily come back in the future, so let's address it.

I'm not sure I see the reason in general for a utility library rather
than doing these piecemeal like the rest of lib functions. Why is crypto
special here? But in particular to this patch: nothing is actually using
crypto_simd_disabled_for_test in lib/crypto, right? So is this
necessary?

Jason
Eric Biggers July 19, 2022, 4:34 a.m. UTC | #2
On Sat, Jul 16, 2022 at 08:32:55PM +0200, Jason A. Donenfeld wrote:
> Hi Eric,
> 
> On Fri, Jul 15, 2022 at 11:29:20PM -0700, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > Move the definition of crypto_simd_disabled_for_test into
> > lib/crypto/utils.c so that it can be accessed by library code.
> > 
> > This is needed when code that is shared between a traditional crypto API
> > implementation and a library implementation is built-in, but
> > CRYPTO_ALGAPI=m.  The x86 blake2s previously was an example of this
> > (https://lore.kernel.org/linux-crypto/20220517033630.1182-1-gaochao49@huawei.com/T/#u).
> > Although that case was resolved by removing the blake2s shash support,
> > this problem could easily come back in the future, so let's address it.
> 
> I'm not sure I see the reason in general for a utility library rather
> than doing these piecemeal like the rest of lib functions. Why is crypto
> special here? But in particular to this patch: nothing is actually using
> crypto_simd_disabled_for_test in lib/crypto, right? So is this
> necessary?

Well, this is what Herbert wanted:
https://lore.kernel.org/r/YtEgzHuuMts0YBCz@gondor.apana.org.au.  It's
subjective, but for now I think I prefer this approach too, since the utility
functions are so small and are widely used.  A whole module is overkill for just
a few lines of code.

The commit message answers your second and third questions.

- Eric
Eric Biggers July 21, 2022, 7:01 a.m. UTC | #3
On Mon, Jul 18, 2022 at 09:34:23PM -0700, Eric Biggers wrote:
> On Sat, Jul 16, 2022 at 08:32:55PM +0200, Jason A. Donenfeld wrote:
> > Hi Eric,
> > 
> > On Fri, Jul 15, 2022 at 11:29:20PM -0700, Eric Biggers wrote:
> > > From: Eric Biggers <ebiggers@google.com>
> > > 
> > > Move the definition of crypto_simd_disabled_for_test into
> > > lib/crypto/utils.c so that it can be accessed by library code.
> > > 
> > > This is needed when code that is shared between a traditional crypto API
> > > implementation and a library implementation is built-in, but
> > > CRYPTO_ALGAPI=m.  The x86 blake2s previously was an example of this
> > > (https://lore.kernel.org/linux-crypto/20220517033630.1182-1-gaochao49@huawei.com/T/#u).
> > > Although that case was resolved by removing the blake2s shash support,
> > > this problem could easily come back in the future, so let's address it.
> > 
> > I'm not sure I see the reason in general for a utility library rather
> > than doing these piecemeal like the rest of lib functions. Why is crypto
> > special here? But in particular to this patch: nothing is actually using
> > crypto_simd_disabled_for_test in lib/crypto, right? So is this
> > necessary?
> 
> Well, this is what Herbert wanted:
> https://lore.kernel.org/r/YtEgzHuuMts0YBCz@gondor.apana.org.au.  It's
> subjective, but for now I think I prefer this approach too, since the utility
> functions are so small and are widely used.  A whole module is overkill for just
> a few lines of code.
> 
> The commit message answers your second and third questions.
> 

Herbert, any thoughts on this?

Note: I forgot to put a MODULE_LICENSE in the new module, so I'll need to resend
this patchset even if there are no other issues.

- Eric
Herbert Xu July 21, 2022, 7:36 a.m. UTC | #4
Hi Eric:

On Thu, Jul 21, 2022 at 12:01:47AM -0700, Eric Biggers wrote:
>
> Herbert, any thoughts on this?

I'm happy to drop the simd patch for now as there are no users
under lib/crypto.

> Note: I forgot to put a MODULE_LICENSE in the new module, so I'll need to resend
> this patchset even if there are no other issues.

Thanks!