1. 09 Jan, 2020 40 commits
    • Eric Biggers's avatar
      crypto: cryptd - convert to new way of freeing instances · 758ec5ac
      Eric Biggers authored
      Convert the "cryptd" template to the new way of freeing instances, where
      a ->free() method is installed to the instance struct itself.  This
      replaces the weakly-typed method crypto_template::free().
      
      This will allow removing support for the old way of freeing instances.
      
      Note that the 'default' case in cryptd_free() was already unreachable.
      So, we aren't missing anything by keeping only the ahash and aead parts.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      758ec5ac
    • Eric Biggers's avatar
      crypto: geniv - convert to new way of freeing instances · 0f8f6d86
      Eric Biggers authored
      Convert the "seqiv" template to the new way of freeing instances where a
      ->free() method is installed to the instance struct itself.  Also remove
      the unused implementation of the old way of freeing instances from the
      "echainiv" template, since it's already using the new way too.
      
      In doing this, also simplify the code by making the helper function
      aead_geniv_alloc() install the ->free() method, instead of making seqiv
      and echainiv do this themselves.  This is analogous to how
      skcipher_alloc_instance_simple() works.
      
      This will allow removing support for the old way of freeing instances.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      0f8f6d86
    • Eric Biggers's avatar
      crypto: hash - add support for new way of freeing instances · 48fb3e57
      Eric Biggers authored
      Add support to shash and ahash for the new way of freeing instances
      (already used for skcipher, aead, and akcipher) where a ->free() method
      is installed to the instance struct itself.  These methods are more
      strongly-typed than crypto_template::free(), which they replace.
      
      This will allow removing support for the old way of freeing instances.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      48fb3e57
    • Eric Biggers's avatar
      crypto: algapi - fold crypto_init_spawn() into crypto_grab_spawn() · aed11cf5
      Eric Biggers authored
      Now that crypto_init_spawn() is only called by crypto_grab_spawn(),
      simplify things by moving its functionality into crypto_grab_spawn().
      
      In the process of doing this, also be more consistent about when the
      spawn and instance are updated, and remove the crypto_spawn::dropref
      flag since now it's always set.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      aed11cf5
    • Eric Biggers's avatar
      crypto: ahash - unexport crypto_ahash_type · 6d1b41fc
      Eric Biggers authored
      Now that all the templates that need ahash spawns have been converted to
      use crypto_grab_ahash() rather than look up the algorithm directly,
      crypto_ahash_type is no longer used outside of ahash.c.  Make it static.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      6d1b41fc
    • Eric Biggers's avatar
      crypto: algapi - remove obsoleted instance creation helpers · 629f1afc
      Eric Biggers authored
      Remove lots of helper functions that were previously used for
      instantiating crypto templates, but are now unused:
      
      - crypto_get_attr_alg() and similar functions looked up an inner
        algorithm directly from a template parameter.  These were replaced
        with getting the algorithm's name, then calling crypto_grab_*().
      
      - crypto_init_spawn2() and similar functions initialized a spawn, given
        an algorithm.  Similarly, these were replaced with crypto_grab_*().
      
      - crypto_alloc_instance() and similar functions allocated an instance
        with a single spawn, given the inner algorithm.  These aren't useful
        anymore since crypto_grab_*() need the instance allocated first.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      629f1afc
    • Eric Biggers's avatar
      crypto: cipher - make crypto_spawn_cipher() take a crypto_cipher_spawn · d5ed3b65
      Eric Biggers authored
      Now that all users of single-block cipher spawns have been converted to
      use 'struct crypto_cipher_spawn' rather than the less specifically typed
      'struct crypto_spawn', make crypto_spawn_cipher() take a pointer to a
      'struct crypto_cipher_spawn' rather than a 'struct crypto_spawn'.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      d5ed3b65
    • Eric Biggers's avatar
      crypto: xcbc - use crypto_grab_cipher() and simplify error paths · 1e212a6a
      Eric Biggers authored
      Make the xcbc template use the new function crypto_grab_cipher() to
      initialize its cipher spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making xcbc_create() allocate the instance directly rather
      than use shash_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1e212a6a
    • Eric Biggers's avatar
      crypto: vmac - use crypto_grab_cipher() and simplify error paths · 3b4e73d8
      Eric Biggers authored
      Make the vmac64 template use the new function crypto_grab_cipher() to
      initialize its cipher spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making vmac_create() allocate the instance directly rather
      than use shash_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3b4e73d8
    • Eric Biggers's avatar
      crypto: cmac - use crypto_grab_cipher() and simplify error paths · 1d0459cd
      Eric Biggers authored
      Make the cmac template use the new function crypto_grab_cipher() to
      initialize its cipher spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making cmac_create() allocate the instance directly rather
      than use shash_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1d0459cd
    • Eric Biggers's avatar
      crypto: cbcmac - use crypto_grab_cipher() and simplify error paths · 16672970
      Eric Biggers authored
      Make the cbcmac template use the new function crypto_grab_cipher() to
      initialize its cipher spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making cbcmac_create() allocate the instance directly
      rather than use shash_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      16672970
    • Eric Biggers's avatar
      crypto: skcipher - use crypto_grab_cipher() and simplify error paths · aacd5b4c
      Eric Biggers authored
      Make skcipher_alloc_instance_simple() use the new function
      crypto_grab_cipher() to initialize its cipher spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      aacd5b4c
    • Eric Biggers's avatar
      crypto: chacha20poly1305 - use crypto_grab_ahash() and simplify error paths · c282586f
      Eric Biggers authored
      Make the rfc7539 and rfc7539esp templates use the new function
      crypto_grab_ahash() to initialize their ahash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c282586f
    • Eric Biggers's avatar
      crypto: ccm - use crypto_grab_ahash() and simplify error paths · 05b3bbb5
      Eric Biggers authored
      Make the ccm and ccm_base templates use the new function
      crypto_grab_ahash() to initialize their ahash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      05b3bbb5
    • Eric Biggers's avatar
      crypto: gcm - use crypto_grab_ahash() and simplify error paths · ab6ffd36
      Eric Biggers authored
      Make the gcm and gcm_base templates use the new function
      crypto_grab_ahash() to initialize their ahash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ab6ffd36
    • Eric Biggers's avatar
      crypto: authencesn - use crypto_grab_ahash() and simplify error paths · 37073882
      Eric Biggers authored
      Make the authencesn template use the new function crypto_grab_ahash() to
      initialize its ahash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      37073882
    • Eric Biggers's avatar
      crypto: authenc - use crypto_grab_ahash() and simplify error paths · 37a861ad
      Eric Biggers authored
      Make the authenc template use the new function crypto_grab_ahash() to
      initialize its ahash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      37a861ad
    • Eric Biggers's avatar
      crypto: hmac - use crypto_grab_shash() and simplify error paths · 39e7a283
      Eric Biggers authored
      Make the hmac template use the new function crypto_grab_shash() to
      initialize its shash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making hmac_create() allocate the instance directly rather
      than use shash_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      39e7a283
    • Eric Biggers's avatar
      crypto: cryptd - use crypto_grab_shash() and simplify error paths · 218c5035
      Eric Biggers authored
      Make the cryptd template (in the hash case) use the new function
      crypto_grab_shash() to initialize its shash spawn.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      This required making cryptd_create_hash() allocate the instance directly
      rather than use cryptd_alloc_instance().
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      218c5035
    • Eric Biggers's avatar
      crypto: adiantum - use crypto_grab_{cipher,shash} and simplify error paths · ba448407
      Eric Biggers authored
      Make the adiantum template use the new functions crypto_grab_cipher()
      and crypto_grab_shash() to initialize its cipher and shash spawns.
      
      This is needed to make all spawns be initialized in a consistent way.
      
      Also simplify the error handling by taking advantage of crypto_drop_*()
      now accepting (as a no-op) spawns that haven't been initialized yet, and
      by taking advantage of crypto_grab_*() now handling ERR_PTR() names.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ba448407
    • Eric Biggers's avatar
      crypto: cipher - introduce crypto_cipher_spawn and crypto_grab_cipher() · 0764ac28
      Eric Biggers authored
      Currently, "cipher" (single-block cipher) spawns are usually initialized
      by using crypto_get_attr_alg() to look up the algorithm, then calling
      crypto_init_spawn().  In one case, crypto_grab_spawn() is used directly.
      
      The former way is different from how skcipher, aead, and akcipher spawns
      are initialized (they use crypto_grab_*()), and for no good reason.
      This difference introduces unnecessary complexity.
      
      The crypto_grab_*() functions used to have some problems, like not
      holding a reference to the algorithm and requiring the caller to
      initialize spawn->base.inst.  But those problems are fixed now.
      
      Also, the cipher spawns are not strongly typed; e.g., the API requires
      that the user manually specify the flags CRYPTO_ALG_TYPE_CIPHER and
      CRYPTO_ALG_TYPE_MASK.  Though the "cipher" algorithm type itself isn't
      yet strongly typed, we can start by making the spawns strongly typed.
      
      So, let's introduce a new 'struct crypto_cipher_spawn', and functions
      crypto_grab_cipher() and crypto_drop_cipher() to grab and drop them.
      
      Later patches will convert all cipher spawns to use these, then make
      crypto_spawn_cipher() take 'struct crypto_cipher_spawn' as well, instead
      of a bare 'struct crypto_spawn' as it currently does.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      0764ac28
    • Eric Biggers's avatar
      crypto: ahash - introduce crypto_grab_ahash() · 84a9c938
      Eric Biggers authored
      Currently, ahash spawns are initialized by using ahash_attr_alg() or
      crypto_find_alg() to look up the ahash algorithm, then calling
      crypto_init_ahash_spawn().
      
      This is different from how skcipher, aead, and akcipher spawns are
      initialized (they use crypto_grab_*()), and for no good reason.  This
      difference introduces unnecessary complexity.
      
      The crypto_grab_*() functions used to have some problems, like not
      holding a reference to the algorithm and requiring the caller to
      initialize spawn->base.inst.  But those problems are fixed now.
      
      So, let's introduce crypto_grab_ahash() so that we can convert all
      templates to the same way of initializing their spawns.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      84a9c938
    • Eric Biggers's avatar
      crypto: shash - introduce crypto_grab_shash() · fdfad1ff
      Eric Biggers authored
      Currently, shash spawns are initialized by using shash_attr_alg() or
      crypto_alg_mod_lookup() to look up the shash algorithm, then calling
      crypto_init_shash_spawn().
      
      This is different from how skcipher, aead, and akcipher spawns are
      initialized (they use crypto_grab_*()), and for no good reason.  This
      difference introduces unnecessary complexity.
      
      The crypto_grab_*() functions used to have some problems, like not
      holding a reference to the algorithm and requiring the caller to
      initialize spawn->base.inst.  But those problems are fixed now.
      
      So, let's introduce crypto_grab_shash() so that we can convert all
      templates to the same way of initializing their spawns.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      fdfad1ff
    • Eric Biggers's avatar
      crypto: algapi - pass instance to crypto_grab_spawn() · de95c957
      Eric Biggers authored
      Currently, crypto_spawn::inst is first used temporarily to pass the
      instance to crypto_grab_spawn().  Then crypto_init_spawn() overwrites it
      with crypto_spawn::next, which shares the same union.  Finally,
      crypto_spawn::inst is set again when the instance is registered.
      
      Make this less convoluted by just passing the instance as an argument to
      crypto_grab_spawn() instead.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      de95c957
    • Eric Biggers's avatar
      crypto: akcipher - pass instance to crypto_grab_akcipher() · 73bed26f
      Eric Biggers authored
      Initializing a crypto_akcipher_spawn currently requires:
      
      1. Set spawn->base.inst to point to the instance.
      2. Call crypto_grab_akcipher().
      
      But there's no reason for these steps to be separate, and in fact this
      unneeded complication has caused at least one bug, the one fixed by
      commit 6db43410 ("crypto: adiantum - initialize crypto_spawn::inst")
      
      So just make crypto_grab_akcipher() take the instance as an argument.
      
      To keep the function call from getting too unwieldy due to this extra
      argument, also introduce a 'mask' variable into pkcs1pad_create().
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      73bed26f
    • Eric Biggers's avatar
      crypto: aead - pass instance to crypto_grab_aead() · cd900f0c
      Eric Biggers authored
      Initializing a crypto_aead_spawn currently requires:
      
      1. Set spawn->base.inst to point to the instance.
      2. Call crypto_grab_aead().
      
      But there's no reason for these steps to be separate, and in fact this
      unneeded complication has caused at least one bug, the one fixed by
      commit 6db43410 ("crypto: adiantum - initialize crypto_spawn::inst")
      
      So just make crypto_grab_aead() take the instance as an argument.
      
      To keep the function calls from getting too unwieldy due to this extra
      argument, also introduce a 'mask' variable into the affected places
      which weren't already using one.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      cd900f0c
    • Eric Biggers's avatar
      crypto: skcipher - pass instance to crypto_grab_skcipher() · b9f76ddd
      Eric Biggers authored
      Initializing a crypto_skcipher_spawn currently requires:
      
      1. Set spawn->base.inst to point to the instance.
      2. Call crypto_grab_skcipher().
      
      But there's no reason for these steps to be separate, and in fact this
      unneeded complication has caused at least one bug, the one fixed by
      commit 6db43410 ("crypto: adiantum - initialize crypto_spawn::inst")
      
      So just make crypto_grab_skcipher() take the instance as an argument.
      
      To keep the function calls from getting too unwieldy due to this extra
      argument, also introduce a 'mask' variable into the affected places
      which weren't already using one.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b9f76ddd
    • Eric Biggers's avatar
      crypto: ahash - make struct ahash_instance be the full size · 77f7e94d
      Eric Biggers authored
      Define struct ahash_instance in a way analogous to struct
      skcipher_instance, struct aead_instance, and struct akcipher_instance,
      where the struct is defined to include both the algorithm structure at
      the beginning and the additional crypto_instance fields at the end.
      
      This is needed to allow allocating ahash instances directly using
      kzalloc(sizeof(*inst) + sizeof(*ictx), ...) in the same way as skcipher,
      aead, and akcipher instances.  In turn, that's needed to make spawns be
      initialized in a consistent way everywhere.
      
      Also take advantage of the addition of the base instance to struct
      ahash_instance by simplifying the ahash_crypto_instance() and
      ahash_instance() functions.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      77f7e94d
    • Eric Biggers's avatar
      crypto: shash - make struct shash_instance be the full size · 1b84e7d0
      Eric Biggers authored
      Define struct shash_instance in a way analogous to struct
      skcipher_instance, struct aead_instance, and struct akcipher_instance,
      where the struct is defined to include both the algorithm structure at
      the beginning and the additional crypto_instance fields at the end.
      
      This is needed to allow allocating shash instances directly using
      kzalloc(sizeof(*inst) + sizeof(*ictx), ...) in the same way as skcipher,
      aead, and akcipher instances.  In turn, that's needed to make spawns be
      initialized in a consistent way everywhere.
      
      Also take advantage of the addition of the base instance to struct
      shash_instance by simplifying the shash_crypto_instance() and
      shash_instance() functions.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1b84e7d0
    • Eric Biggers's avatar
      crypto: algapi - make crypto_grab_spawn() handle an ERR_PTR() name · ca94e937
      Eric Biggers authored
      To allow further simplifying template ->create() functions, make
      crypto_grab_spawn() handle an ERR_PTR() name by passing back the error.
      
      For most templates, this will allow the result of crypto_attr_alg_name()
      to be passed directly to crypto_grab_*(), rather than first having to
      assign it to a variable [where it can then potentially be misused, as it
      was in the rfc7539 template prior to commit 5e27f38f ("crypto:
      chacha20poly1305 - set cra_name correctly")] and check it for error.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ca94e937
    • Eric Biggers's avatar
      crypto: algapi - make crypto_drop_spawn() a no-op on uninitialized spawns · ff670627
      Eric Biggers authored
      Make crypto_drop_spawn() do nothing when the spawn hasn't been
      initialized with an algorithm yet.  This will allow simplifying error
      handling in all the template ->create() functions, since on error they
      will be able to just call their usual "free instance" function, rather
      than having to handle dropping just the spawns that have been
      initialized so far.
      
      This does assume the spawn starts out zero-filled, but that's always the
      case since instances are allocated with kzalloc().  And some other code
      already assumes this anyway.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ff670627
    • Gary R Hook's avatar
      crypto: ccp - Update MAINTAINERS for CCP driver · e91e785e
      Gary R Hook authored
      Remove Gary R Hook as CCP maintainer.
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      e91e785e
    • Christian Lamparter's avatar
      crypto: crypto4xx - use GFP_KERNEL for big allocations · 30a50e44
      Christian Lamparter authored
      The driver should use GFP_KERNEL for the bigger allocation
      during the driver's crypto4xx_probe() and not GFP_ATOMIC in
      my opinion.
      Signed-off-by: default avatarChristian Lamparter <chunkeey@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      30a50e44
    • Christian Lamparter's avatar
      crypto: crypto4xx - reduce memory fragmentation · b87b2c4d
      Christian Lamparter authored
      With recent kernels (>5.2), the driver fails to probe, as the
      allocation of the driver's scatter buffer fails with -ENOMEM.
      
      This happens in crypto4xx_build_sdr(). Where the driver tries
      to get 512KiB (=PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD) of
      continuous memory. This big chunk is by design, since the driver
      uses this circumstance in the crypto4xx_copy_pkt_to_dst() to
      its advantage:
      "all scatter-buffers are all neatly organized in one big
      continuous ringbuffer; So scatterwalk_map_and_copy() can be
      instructed to copy a range of buffers in one go."
      
      The PowerPC arch does not have support for DMA_CMA. Hence,
      this patch reorganizes the order in which the memory
      allocations are done. Since the driver itself is responsible
      for some of the issues.
      Signed-off-by: default avatarChristian Lamparter <chunkeey@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b87b2c4d
    • Eric Biggers's avatar
      crypto: remove propagation of CRYPTO_TFM_RES_* flags · af5034e8
      Eric Biggers authored
      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: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      af5034e8
    • Eric Biggers's avatar
      crypto: remove CRYPTO_TFM_RES_WEAK_KEY · c4c4db0d
      Eric Biggers authored
      The CRYPTO_TFM_RES_WEAK_KEY 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.
      There are also no tests that verify that all algorithms actually set (or
      don't set) it correctly.
      
      This is also the last remaining CRYPTO_TFM_RES_* flag, which means that
      it's the only thing still needing all the boilerplate code which
      propagates these flags around from child => parent tfms.
      
      And if someone ever needs to distinguish this error in the future (which
      is somewhat unlikely, as it's been unneeded for a long time), it would
      be much better to just define a new return value like -EKEYREJECTED.
      That would be much simpler, less error-prone, and easier to test.
      
      So just remove this flag.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c4c4db0d
    • Eric Biggers's avatar
      crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN · 674f368a
      Eric Biggers authored
      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: default avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: default avatarHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      674f368a
    • Eric Biggers's avatar
      crypto: remove CRYPTO_TFM_RES_BAD_BLOCK_LEN · 5c925e8b
      Eric Biggers authored
      The flag CRYPTO_TFM_RES_BAD_BLOCK_LEN is never checked for, and it's
      only set by one driver.  And even that single driver's use is wrong
      because the driver is setting the flag from ->encrypt() and ->decrypt()
      with no locking, which is unsafe because ->encrypt() and ->decrypt() can
      be executed by many threads in parallel on the same tfm.
      
      Just remove this flag.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      5c925e8b
    • Eric Biggers's avatar
      crypto: remove unused tfm result flags · f9d89b85
      Eric Biggers authored
      The tfm result flags CRYPTO_TFM_RES_BAD_KEY_SCHED and
      CRYPTO_TFM_RES_BAD_FLAGS are never used, so remove them.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      f9d89b85
    • Eric Biggers's avatar
      crypto: atmel-sha - fix error handling when setting hmac key · b529f198
      Eric Biggers authored
      HMAC keys can be of any length, and atmel_sha_hmac_key_set() can only
      fail due to -ENOMEM.  But atmel_sha_hmac_setkey() incorrectly treated
      any error as a "bad key length" error.  Fix it to correctly propagate
      the -ENOMEM error code and not set any tfm result flags.
      
      Fixes: 81d8750b ("crypto: atmel-sha - add support to hmac(shaX)")
      Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Reviewed-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b529f198