1. 16 7月, 2020 1 次提交
    • E
      crypto: algapi - use common mechanism for inheriting flags · 7bcb2c99
      Eric Biggers 提交于
      The flag CRYPTO_ALG_ASYNC is "inherited" in the sense that when a
      template is instantiated, the template will have CRYPTO_ALG_ASYNC set if
      any of the algorithms it uses has CRYPTO_ALG_ASYNC set.
      
      We'd like to add a second flag (CRYPTO_ALG_ALLOCATES_MEMORY) that gets
      "inherited" in the same way.  This is difficult because the handling of
      CRYPTO_ALG_ASYNC is hardcoded everywhere.  Address this by:
      
        - Add CRYPTO_ALG_INHERITED_FLAGS, which contains the set of flags that
          have these inheritance semantics.
      
        - Add crypto_algt_inherited_mask(), for use by template ->create()
          methods.  It returns any of these flags that the user asked to be
          unset and thus must be passed in the 'mask' to crypto_grab_*().
      
        - Also modify crypto_check_attr_type() to handle computing the 'mask'
          so that most templates can just use this.
      
        - Make crypto_grab_*() propagate these flags to the template instance
          being created so that templates don't have to do this themselves.
      
      Make crypto/simd.c propagate these flags too, since it "wraps" another
      algorithm, similar to a template.
      
      Based on a patch by Mikulas Patocka <mpatocka@redhat.com>
      (https://lore.kernel.org/r/alpine.LRH.2.02.2006301414580.30526@file01.intranet.prod.int.rdu2.redhat.com).
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      7bcb2c99
  2. 08 5月, 2020 1 次提交
  3. 09 1月, 2020 6 次提交
    • E
      crypto: algapi - remove crypto_template::{alloc,free}() · a24a1fd7
      Eric Biggers 提交于
      Now that all templates provide a ->create() method which creates an
      instance, installs a strongly-typed ->free() method directly to it, and
      registers it, the older ->alloc() and ->free() methods in
      'struct crypto_template' are no longer used.  Remove them.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      a24a1fd7
    • E
      crypto: algapi - fold crypto_init_spawn() into crypto_grab_spawn() · aed11cf5
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      aed11cf5
    • E
      crypto: algapi - remove obsoleted instance creation helpers · 629f1afc
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      629f1afc
    • E
      crypto: cipher - make crypto_spawn_cipher() take a crypto_cipher_spawn · d5ed3b65
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d5ed3b65
    • E
      crypto: cipher - introduce crypto_cipher_spawn and crypto_grab_cipher() · 0764ac28
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      0764ac28
    • E
      crypto: algapi - pass instance to crypto_grab_spawn() · de95c957
      Eric Biggers 提交于
      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: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      de95c957
  4. 27 12月, 2019 1 次提交
    • H
      crypto: api - Retain alg refcount in crypto_grab_spawn · 5f567fff
      Herbert Xu 提交于
      This patch changes crypto_grab_spawn to retain the reference count
      on the algorithm.  This is because the caller needs to access the
      algorithm parameters and without the reference count the algorithm
      can be freed at any time.
      
      The reference count will be subsequently dropped by the crypto API
      once the instance has been registered.  The helper crypto_drop_spawn
      will also conditionally drop the reference count depending on whether
      it has been registered.
      
      Note that the code is actually added to crypto_init_spawn.  However,
      unless the caller activates this by setting spawn->dropref beforehand
      then nothing happens.  The only caller that sets dropref is currently
      crypto_grab_spawn.
      
      Once all legacy users of crypto_init_spawn disappear, then we can
      kill the dropref flag.
      
      Internally each instance will maintain a list of its spawns prior
      to registration.  This memory used by this list is shared with
      other fields that are only used after registration.  In order for
      this to work a new flag spawn->registered is added to indicate
      whether spawn->inst can be used.
      
      Fixes: d6ef2f19 ("crypto: api - Add crypto_grab_spawn primitive")
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      5f567fff
  5. 20 12月, 2019 1 次提交
    • E
      crypto: algapi - make unregistration functions return void · c6d633a9
      Eric Biggers 提交于
      Some of the algorithm unregistration functions return -ENOENT when asked
      to unregister a non-registered algorithm, while others always return 0
      or always return void.  But no users check the return value, except for
      two of the bulk unregistration functions which print a message on error
      but still always return 0 to their caller, and crypto_del_alg() which
      calls crypto_unregister_instance() which always returns 0.
      
      Since unregistering a non-registered algorithm is always a kernel bug
      but there isn't anything callers should do to handle this situation at
      runtime, let's simplify things by making all the unregistration
      functions return void, and moving the error message into
      crypto_unregister_alg() and upgrading it to a WARN().
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      c6d633a9
  6. 11 12月, 2019 1 次提交
    • H
      crypto: api - Do not zap spawn->alg · 4f87ee11
      Herbert Xu 提交于
      Currently when a spawn is removed we will zap its alg field.
      This is racy because the spawn could belong to an unregistered
      instance which may dereference the spawn->alg field.
      
      This patch fixes this by keeping spawn->alg constant and instead
      adding a new spawn->dead field to indicate that a spawn is going
      away.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      4f87ee11
  7. 17 11月, 2019 1 次提交
  8. 01 11月, 2019 1 次提交
    • E
      crypto: skcipher - remove the "blkcipher" algorithm type · c65058b7
      Eric Biggers 提交于
      Now that all "blkcipher" algorithms have been converted to "skcipher",
      remove the blkcipher algorithm type.
      
      The skcipher (symmetric key cipher) algorithm type was introduced a few
      years ago to replace both blkcipher and ablkcipher (synchronous and
      asynchronous block cipher).  The advantages of skcipher include:
      
        - A much less confusing name, since none of these algorithm types have
          ever actually been for raw block ciphers, but rather for all
          length-preserving encryption modes including block cipher modes of
          operation, stream ciphers, and other length-preserving modes.
      
        - It unified blkcipher and ablkcipher into a single algorithm type
          which supports both synchronous and asynchronous implementations.
          Note, blkcipher already operated only on scatterlists, so the fact
          that skcipher does too isn't a regression in functionality.
      
        - Better type safety by using struct skcipher_alg, struct
          crypto_skcipher, etc. instead of crypto_alg, crypto_tfm, etc.
      
        - It sometimes simplifies the implementations of algorithms.
      
      Also, the blkcipher API was no longer being tested.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      c65058b7
  9. 02 8月, 2019 1 次提交
    • T
      crypto: api - Remove redundant #ifdef in crypto_yield() · f9981bc5
      Thomas Gleixner 提交于
      While looking at CONFIG_PREEMPT dependencies treewide the #ifdef in
      crypto_yield() matched.
      
      CONFIG_PREEMPT and CONFIG_PREEMPT_VOLUNTARY are mutually exclusive so the
      extra !CONFIG_PREEMPT conditional is redundant.
      
      cond_resched() has only an effect when CONFIG_PREEMPT_VOLUNTARY is set,
      otherwise it's a stub which the compiler optimizes out.
      
      Remove the whole conditional.
      
      No functional change.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: linux-crypto@vger.kernel.org
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: "David S. Miller" <davem@davemloft.net>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      f9981bc5
  10. 31 5月, 2019 1 次提交
  11. 30 5月, 2019 1 次提交
  12. 25 1月, 2019 1 次提交
  13. 11 1月, 2019 1 次提交
  14. 04 9月, 2018 2 次提交
  15. 21 4月, 2018 1 次提交
  16. 31 3月, 2018 1 次提交
  17. 04 8月, 2017 2 次提交
  18. 27 2月, 2017 1 次提交
  19. 11 2月, 2017 1 次提交
    • A
      crypto: algapi - make crypto_xor() and crypto_inc() alignment agnostic · db91af0f
      Ard Biesheuvel 提交于
      Instead of unconditionally forcing 4 byte alignment for all generic
      chaining modes that rely on crypto_xor() or crypto_inc() (which may
      result in unnecessary copying of data when the underlying hardware
      can perform unaligned accesses efficiently), make those functions
      deal with unaligned input explicitly, but only if the Kconfig symbol
      HAVE_EFFICIENT_UNALIGNED_ACCESS is set. This will allow us to drop
      the alignmasks from the CBC, CMAC, CTR, CTS, PCBC and SEQIV drivers.
      
      For crypto_inc(), this simply involves making the 4-byte stride
      conditional on HAVE_EFFICIENT_UNALIGNED_ACCESS being set, given that
      it typically operates on 16 byte buffers.
      
      For crypto_xor(), an algorithm is implemented that simply runs through
      the input using the largest strides possible if unaligned accesses are
      allowed. If they are not, an optimal sequence of memory accesses is
      emitted that takes the relative alignment of the input buffers into
      account, e.g., if the relative misalignment of dst and src is 4 bytes,
      the entire xor operation will be completed using 4 byte loads and stores
      (modulo unaligned bits at the start and end). Note that all expressions
      involving misalign are simply eliminated by the compiler when
      HAVE_EFFICIENT_UNALIGNED_ACCESS is defined.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      db91af0f
  20. 07 9月, 2016 1 次提交
  21. 18 7月, 2016 1 次提交
  22. 01 7月, 2016 1 次提交
  23. 06 2月, 2016 1 次提交
  24. 01 2月, 2016 2 次提交
  25. 14 7月, 2015 2 次提交
  26. 13 5月, 2015 2 次提交
    • H
      crypto: aead - Convert top level interface to new style · 5d1d65f8
      Herbert Xu 提交于
      This patch converts the top-level aead interface to the new style.
      All user-level AEAD interface code have been moved into crypto/aead.h.
      
      The allocation/free functions have switched over to the new way of
      allocating tfms.
      
      This patch also removes the double indrection on setkey so the
      indirection now exists only at the alg level.
      
      Apart from these there are no user-visible changes.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      5d1d65f8
    • H
      crypto: api - Add crypto_grab_spawn primitive · d6ef2f19
      Herbert Xu 提交于
      This patch adds a new primitive crypto_grab_spawn which is meant
      to replace crypto_init_spawn and crypto_init_spawn2.  Under the
      new scheme the user no longer has to worry about reference counting
      the alg object before it is subsumed by the spawn.
      
      It is pretty much an exact copy of crypto_grab_aead.
      
      Prior to calling this function spawn->frontend and spawn->inst
      must have been set.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d6ef2f19
  27. 03 4月, 2015 1 次提交
  28. 20 6月, 2014 1 次提交
  29. 10 3月, 2014 2 次提交