09 Jan, 2020

2 commits

  • The CRYPTO_TFM_RES_* flags were apparently meant as a way to make the
    ->setkey() functions provide more information about errors. But these
    flags weren't actually being used or tested, and in many cases they
    weren't being set correctly anyway. So they've now been removed.

    Also, if someone ever actually needs to start better distinguishing
    ->setkey() errors (which is somewhat unlikely, as this has been unneeded
    for a long time), we'd be much better off just defining different return
    values, like -EINVAL if the key is invalid for the algorithm vs.
    -EKEYREJECTED if the key was rejected by a policy like "no weak keys".
    That would be much simpler, less error-prone, and easier to test.

    So just remove CRYPTO_TFM_RES_MASK and all the unneeded logic that
    propagates these flags around.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     
  • The CRYPTO_TFM_RES_BAD_KEY_LEN flag was apparently meant as a way to
    make the ->setkey() functions provide more information about errors.

    However, no one actually checks for this flag, which makes it pointless.

    Also, many algorithms fail to set this flag when given a bad length key.
    Reviewing just the generic implementations, this is the case for
    aes-fixed-time, cbcmac, echainiv, nhpoly1305, pcrypt, rfc3686, rfc4309,
    rfc7539, rfc7539esp, salsa20, seqiv, and xcbc. But there are probably
    many more in arch/*/crypto/ and drivers/crypto/.

    Some algorithms can even set this flag when the key is the correct
    length. For example, authenc and authencesn set it when the key payload
    is malformed in any way (not just a bad length), the atmel-sha and ccree
    drivers can set it if a memory allocation fails, and the chelsio driver
    sets it for bad auth tag lengths, not just bad key lengths.

    So even if someone actually wanted to start checking this flag (which
    seems unlikely, since it's been unused for a long time), there would be
    a lot of work needed to get it working correctly. But it would probably
    be much better to go back to the drawing board and just define different
    return values, like -EINVAL if the key is invalid for the algorithm vs.
    -EKEYREJECTED if the key was rejected by a policy like "no weak keys".
    That would be much simpler, less error-prone, and easier to test.

    So just remove this flag.

    Signed-off-by: Eric Biggers
    Reviewed-by: Horia Geantă
    Signed-off-by: Herbert Xu

    Eric Biggers
     

11 Dec, 2019

1 commit

  • Of the three fields in crt_u.cipher (struct cipher_tfm), ->cit_setkey()
    is pointless because it always points to setkey() in crypto/cipher.c.

    ->cit_decrypt_one() and ->cit_encrypt_one() are slightly less pointless,
    since if the algorithm doesn't have an alignmask, they are set directly
    to ->cia_encrypt() and ->cia_decrypt(). However, this "optimization"
    isn't worthwhile because:

    - The "cipher" algorithm type is the only algorithm still using crt_u,
    so it's bloating every struct crypto_tfm for every algorithm type.

    - If the algorithm has an alignmask, this "optimization" actually makes
    things slower, as it causes 2 indirect calls per block rather than 1.

    - It adds extra code complexity.

    - Some templates already call ->cia_encrypt()/->cia_decrypt() directly
    instead of going through ->cit_encrypt_one()/->cit_decrypt_one().

    - The "cipher" algorithm type never gives optimal performance anyway.
    For that, a higher-level type such as skcipher needs to be used.

    Therefore, just remove the extra indirection, and make
    crypto_cipher_setkey(), crypto_cipher_encrypt_one(), and
    crypto_cipher_decrypt_one() be direct calls into crypto/cipher.c.

    Also remove the unused function crypto_cipher_cast().

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 3029 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070032.746973796@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

21 Apr, 2018

1 commit

  • We avoid various VLAs[1] by using constant expressions for block size
    and alignment mask.

    [1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

    Signed-off-by: Salvatore Mesoraca
    Signed-off-by: Herbert Xu

    Salvatore Mesoraca
     

21 Oct, 2016

1 commit


16 Feb, 2010

1 commit


11 Oct, 2007

1 commit


06 Aug, 2007

1 commit


11 Jul, 2007

1 commit


07 Feb, 2007

1 commit


21 Sep, 2006

6 commits

  • Mark the parts of the cipher interface that have been replaced by
    block ciphers as deprecated. Thanks to Andrew Morton for suggesting
    doing this before removing them completely.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • This patch prepares the scatterwalk code for use by the new block cipher
    type.

    Firstly it halves the size of scatter_walk on 32-bit platforms. This
    is important as we allocate at least two of these objects on the stack
    for each block cipher operation.

    It also exports the symbols since the block cipher code can be built as
    a module.

    Finally there is a hack in scatterwalk_unmap that relies on progress
    being made. Unfortunately, for hardware crypto we can't guarantee
    progress to be made since the hardware can fail.

    So this also gets rid of the hack by not advancing the address returned
    by scatterwalk_map.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • This patch adds two new operations for the simple cipher that encrypts or
    decrypts a single block at a time. This will be the main interface after
    the existing block operations have moved over to the new block ciphers.

    It also adds the crypto_cipher type which is currently only used on the
    new operations but will be extended to setkey as well once existing users
    have been converted to use block ciphers where applicable.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • The sleeping flag used to determine whether crypto_yield can actually
    yield is really a per-operation flag rather than a per-tfm flag. This
    patch changes crypto_yield to take a flag directly so that we can start
    using a per-operation flag instead the tfm flag.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • This patch makes IV operations on ECB fail through nocrypt_iv rather than
    calling BUG(). This is needed to generalise CBC/ECB using the template
    mechanism.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • Now that the tfm is passed directly to setkey instead of the ctx, we no
    longer need to pass the &tfm->crt_flags pointer.

    This patch also gets rid of a few unnecessary checks on the key length
    for ciphers as the cipher layer guarantees that the key length is within
    the bounds specified by the algorithm.

    Rather than testing dia_setkey every time, this patch does it only once
    during crypto_alloc_tfm. The redundant check from crypto_digest_setkey
    is also removed.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

26 Jun, 2006

1 commit

  • Up until now algorithms have been happy to get a context pointer since
    they know everything that's in the tfm already (e.g., alignment, block
    size).

    However, once we have parameterised algorithms, such information will
    be specific to each tfm. So the algorithm API needs to be changed to
    pass the tfm structure instead of the context pointer.

    This patch is basically a text substitution. The only tricky bit is
    the assembly routines that need to get the context pointer offset
    through asm-offsets.h.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

10 Jan, 2006

1 commit


07 Sep, 2005

1 commit


02 Sep, 2005

1 commit

  • The crypto layer currently uses in_atomic() to determine whether it is
    allowed to sleep. This is incorrect since spin locks don't always cause
    in_atomic() to return true.

    Instead of that, this patch returns to an earlier idea of a per-tfm flag
    which determines whether sleeping is allowed. Unlike the earlier version,
    the default is to not allow sleeping. This ensures that no existing code
    can break.

    As usual, this flag may either be set through crypto_alloc_tfm(), or
    just before a specific crypto operation.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     

15 Jul, 2005

1 commit


07 Jul, 2005

6 commits

  • Even though cit_iv is now always aligned, the user can still supply an
    unaligned iv through crypto_cipher_encrypt_iv/crypto_cipher_decrypt_iv.
    This patch will check the alignment of the user-supplied iv and copy
    it if necessary.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     
  • This patch ensures that cit_iv is aligned according to cra_alignmask
    by allocating it as part of the tfm structure. As a side effect the
    crypto layer will also guarantee that the tfm ctx area has enough space
    to be aligned by cra_alignmask. This allows us to remove the extra
    space reservation from the Padlock driver.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     
  • The VIA Padlock device requires the input and output buffers to
    be aligned on 16-byte boundaries. This patch adds the alignmask
    attribute for low-level cipher implementations to indicate their
    alignment requirements.

    The mid-level crypt() function will copy the input/output buffers
    if they are not aligned correctly before they are passed to the
    low-level implementation.

    Strictly speaking, some of the software implementations require
    the buffers to be aligned on 4-byte boundaries as they do 32-bit
    loads. However, it is not clear whether it is better to copy
    the buffers or pay the penalty for unaligned loads/stores.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     
  • This patch adds hooks for cipher algorithms to implement multi-block
    ECB/CBC operations directly. This is expected to provide significant
    performance boots to the VIA Padlock.

    It could also be used for improving software implementations such as
    AES where operating on multiple blocks at a time may enable certain
    optimisations.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     
  • The VIA Padlock device is able to perform much better when multiple
    blocks are fed to it at once. As this device offers an exceptional
    throughput rate it is worthwhile to optimise the infrastructure
    specifically for it.

    We shift the existing page-sized fast path down to the CBC/ECB functions.
    We can then replace the CBC/ECB functions with functions provided by the
    underlying algorithm that performs the multi-block operations.

    As a side-effect this improves the performance of large cipher operations
    for all existing algorithm implementations. I've measured the gain to be
    around 5% for 3DES and 15% for AES.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     
  • Checking a pointer for NULL before calling kfree() on it is redundant.
    This patch removes such checks from crypto/

    Signed-off-by: Jesper Juhl
    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Jesper Juhl
     

17 Apr, 2005

1 commit

  • Initial git repository build. I'm not bothering with the full history,
    even though we have it. We can create a separate "historical" git
    archive of that later if we want to, and in the meantime it's about
    3.2GB when imported into git - space that would just make the early
    git days unnecessarily complicated, when we don't have a lot of good
    infrastructure for it.

    Let it rip!

    Linus Torvalds