16 Jan, 2020

2 commits

  • If CRYPTO_CURVE25519 is y, CRYPTO_LIB_CURVE25519_GENERIC will be
    y, but CRYPTO_LIB_CURVE25519 may be set to m, this causes build
    errors:

    lib/crypto/curve25519-selftest.o: In function `curve25519':
    curve25519-selftest.c:(.text.unlikely+0xc): undefined reference to `curve25519_arch'
    lib/crypto/curve25519-selftest.o: In function `curve25519_selftest':
    curve25519-selftest.c:(.init.text+0x17e): undefined reference to `curve25519_base_arch'

    This is because the curve25519 self-test code is being controlled
    by the GENERIC option rather than the overall CURVE25519 option,
    as is the case with blake2s. To recap, the GENERIC and ARCH options
    for CURVE25519 are internal only and selected by users such as
    the Crypto API, or the externally visible CURVE25519 option which
    in turn is selected by wireguard. The self-test is specific to the
    the external CURVE25519 option and should not be enabled by the
    Crypto API.

    This patch fixes this by splitting the GENERIC module from the
    CURVE25519 module with the latter now containing just the self-test.

    Reported-by: Hulk Robot
    Fixes: aa127963f1ca ("crypto: lib/curve25519 - re-add selftests")
    Signed-off-by: Herbert Xu
    Reviewed-by: Jason A. Donenfeld
    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • These two C implementations from Zinc -- a 32x32 one and a 64x64 one,
    depending on the platform -- come from Andrew Moon's public domain
    poly1305-donna portable code, modified for usage in the kernel. The
    precomputation in the 32-bit version and the use of 64x64 multiplies in
    the 64-bit version make these perform better than the code it replaces.
    Moon's code is also very widespread and has received many eyeballs of
    scrutiny.

    There's a bit of interference between the x86 implementation, which
    relies on internal details of the old scalar implementation. In the next
    commit, the x86 implementation will be replaced with a faster one that
    doesn't rely on this, so none of this matters much. But for now, to keep
    this passing the tests, we inline the bits of the old implementation
    that the x86 implementation relied on. Also, since we now support a
    slightly larger key space, via the union, some offsets had to be fixed
    up.

    Nonce calculation was folded in with the emit function, to take
    advantage of 64x64 arithmetic. However, Adiantum appeared to rely on no
    nonce handling in emit, so this path was conditionalized. We also
    introduced a new struct, poly1305_core_key, to represent the precise
    amount of space that particular implementation uses.

    Testing with kbench9000, depending on the CPU, the update function for
    the 32x32 version has been improved by 4%-7%, and for the 64x64 by
    19%-30%. The 32x32 gains are small, but I think there's great value in
    having a parallel implementation to the 64x64 one so that the two can be
    compared side-by-side as nice stand-alone units.

    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Herbert Xu

    Jason A. Donenfeld
     

27 Dec, 2019

1 commit

  • Somehow these were dropped when Zinc was being integrated, which is
    problematic, because testing the library interface for Curve25519 is
    important.. This commit simply adds them back and wires them in in the
    same way that the blake2s selftests are wired in.

    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Herbert Xu

    Jason A. Donenfeld
     

17 Nov, 2019

6 commits

  • This incorporates the chacha20poly1305 from the Zinc library, retaining
    the library interface, but replacing the implementation with calls into
    the code that already existed in the kernel's crypto API.

    Note that this library API does not implement RFC7539 fully, given that
    it is limited to 64-bit nonces. (The 96-bit nonce version that was part
    of the selftest only has been removed, along with the 96-bit nonce test
    vectors that only tested the selftest but not the actual library itself)

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     
  • This contains two formally verified C implementations of the Curve25519
    scalar multiplication function, one for 32-bit systems, and one for
    64-bit systems whose compiler supports efficient 128-bit integer types.
    Not only are these implementations formally verified, but they are also
    the fastest available C implementations. They have been modified to be
    friendly to kernel space and to be generally less horrendous looking,
    but still an effort has been made to retain their formally verified
    characteristic, and so the C might look slightly unidiomatic.

    The 64-bit version comes from HACL*: https://github.com/project-everest/hacl-star
    The 32-bit version comes from Fiat: https://github.com/mit-plv/fiat-crypto

    Information: https://cr.yp.to/ecdh.html

    Signed-off-by: Jason A. Donenfeld
    [ardb: - move from lib/zinc to lib/crypto
    - replace .c #includes with Kconfig based object selection
    - drop simd handling and simplify support for per-arch versions ]
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Jason A. Donenfeld
     
  • The C implementation was originally based on Samuel Neves' public
    domain reference implementation but has since been heavily modified
    for the kernel. We're able to do compile-time optimizations by moving
    some scaffolding around the final function into the header file.

    Information: https://blake2.net/

    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Samuel Neves
    Co-developed-by: Samuel Neves
    [ardb: - move from lib/zinc to lib/crypto
    - remove simd handling
    - rewrote selftest for better coverage
    - use fixed digest length for blake2s_hmac() and rename to
    blake2s256_hmac() ]
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Jason A. Donenfeld
     
  • Move the core Poly1305 routines shared between the generic Poly1305
    shash driver and the Adiantum and NHPoly1305 drivers into a separate
    library so that using just this pieces does not pull in the crypto
    API pieces of the generic Poly1305 routine.

    In a subsequent patch, we will augment this generic library with
    init/update/final routines so that Poyl1305 algorithm can be used
    directly without the need for using the crypto API's shash abstraction.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     
  • Currently, our generic ChaCha implementation consists of a permute
    function in lib/chacha.c that operates on the 64-byte ChaCha state
    directly [and which is always included into the core kernel since it
    is used by the /dev/random driver], and the crypto API plumbing to
    expose it as a skcipher.

    In order to support in-kernel users that need the ChaCha streamcipher
    but have no need [or tolerance] for going through the abstractions of
    the crypto API, let's expose the streamcipher bits via a library API
    as well, in a way that permits the implementation to be superseded by
    an architecture specific one if provided.

    So move the streamcipher code into a separate module in lib/crypto,
    and expose the init() and crypt() routines to users of the library.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     
  • In preparation of introducing a set of crypto library interfaces, tidy
    up the Makefile and split off the Kconfig symbols into a separate file.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     

22 Aug, 2019

2 commits

  • Before this commit lib/crypto/sha256.c has only been used in the s390 and
    x86 purgatory code, make it suitable for generic use:

    * Export interesting symbols
    * Add -D__DISABLE_EXPORTS to CFLAGS_sha256.o for purgatory builds to
    avoid the exports for the purgatory builds
    * Add to lib/crypto/Makefile and crypto/Kconfig

    Signed-off-by: Hans de Goede
    Signed-off-by: Herbert Xu

    Hans de Goede
     
  • Another one for the cipher museum: split off DES core processing into
    a separate module so other drivers (mostly for crypto accelerators)
    can reuse the code without pulling in the generic DES cipher itself.
    This will also permit the cipher interface to be made private to the
    crypto API itself once we move the only user in the kernel (CIFS) to
    this library interface.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     

26 Jul, 2019

1 commit

  • Take the existing small footprint and mostly time invariant C code
    and turn it into a AES library that can be used for non-performance
    critical, casual use of AES, and as a fallback for, e.g., SIMD code
    that needs a secondary path that can be taken in contexts where the
    SIMD unit is off limits (e.g., in hard interrupts taken from kernel
    context)

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     

20 Jun, 2019

1 commit