Skip to content
Snippets Groups Projects
  1. Jul 16, 2020
    • Eric Biggers's avatar
      crypto: algapi - use common mechanism for inheriting flags · 7bcb2c99
      Eric Biggers authored
      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: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7bcb2c99
  2. Mar 06, 2020
  3. Jan 09, 2020
    • 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: 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: 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: 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
  4. Nov 01, 2019
    • Eric Biggers's avatar
      crypto: skcipher - remove the "blkcipher" algorithm type · c65058b7
      Eric Biggers authored
      
      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: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c65058b7
  5. Aug 15, 2019
  6. Jul 03, 2019
  7. May 30, 2019
  8. Apr 25, 2019
    • Eric Biggers's avatar
      crypto: shash - remove shash_desc::flags · 877b5691
      Eric Biggers authored
      
      The flags field in 'struct shash_desc' never actually does anything.
      The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP.
      However, no shash algorithm ever sleeps, making this flag a no-op.
      
      With this being the case, inevitably some users who can't sleep wrongly
      pass MAY_SLEEP.  These would all need to be fixed if any shash algorithm
      actually started sleeping.  For example, the shash_ahash_*() functions,
      which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP
      from the ahash API to the shash API.  However, the shash functions are
      called under kmap_atomic(), so actually they're assumed to never sleep.
      
      Even if it turns out that some users do need preemption points while
      hashing large buffers, we could easily provide a helper function
      crypto_shash_update_large() which divides the data into smaller chunks
      and calls crypto_shash_update() and cond_resched() for each chunk.  It's
      not necessary to have a flag in 'struct shash_desc', nor is it necessary
      to make individual shash algorithms aware of this at all.
      
      Therefore, remove shash_desc::flags, and document that the
      crypto_shash_*() functions can be called from any context.
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      877b5691
  9. Apr 18, 2019
  10. Dec 23, 2018
    • Eric Biggers's avatar
      crypto: skcipher - remove remnants of internal IV generators · c79b411e
      Eric Biggers authored
      
      Remove dead code related to internal IV generators, which are no longer
      used since they've been replaced with the "seqiv" and "echainiv"
      templates.  The removed code includes:
      
      - The "givcipher" (GIVCIPHER) algorithm type.  No algorithms are
        registered with this type anymore, so it's unneeded.
      
      - The "const char *geniv" member of aead_alg, ablkcipher_alg, and
        blkcipher_alg.  A few algorithms still set this, but it isn't used
        anymore except to show via /proc/crypto and CRYPTO_MSG_GETALG.
        Just hardcode "<default>" or "<none>" in those cases.
      
      - The 'skcipher_givcrypt_request' structure, which is never used.
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      c79b411e
  11. Sep 28, 2018
  12. Jan 12, 2018
    • Eric Biggers's avatar
      crypto: hash - annotate algorithms taking optional key · a208fa8f
      Eric Biggers authored
      
      We need to consistently enforce that keyed hashes cannot be used without
      setting the key.  To do this we need a reliable way to determine whether
      a given hash algorithm is keyed or not.  AF_ALG currently does this by
      checking for the presence of a ->setkey() method.  However, this is
      actually slightly broken because the CRC-32 algorithms implement
      ->setkey() but can also be used without a key.  (The CRC-32 "key" is not
      actually a cryptographic key but rather represents the initial state.
      If not overridden, then a default initial state is used.)
      
      Prepare to fix this by introducing a flag CRYPTO_ALG_OPTIONAL_KEY which
      indicates that the algorithm has a ->setkey() method, but it is not
      required to be called.  Then set it on all the CRC-32 algorithms.
      
      The same also applies to the Adler-32 implementation in Lustre.
      
      Also, the cryptd and mcryptd templates have to pass through the flag
      from their underlying algorithm.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      a208fa8f
    • Eric Biggers's avatar
      crypto: cryptd - pass through absence of ->setkey() · 841a3ff3
      Eric Biggers authored
      
      When the cryptd template is used to wrap an unkeyed hash algorithm,
      don't install a ->setkey() method to the cryptd instance.  This change
      is necessary for cryptd to keep working with unkeyed hash algorithms
      once we start enforcing that ->setkey() is called when present.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      841a3ff3
  13. Dec 11, 2017
  14. Nov 29, 2017
  15. Nov 03, 2017
    • Gilad Ben-Yossef's avatar
      crypto: change transient busy return code to -ENOSPC · 6b80ea38
      Gilad Ben-Yossef authored
      
      The crypto API was using the -EBUSY return value to indicate
      both a hard failure to submit a crypto operation into a
      transformation provider when the latter was busy and the backlog
      mechanism was not enabled as well as a notification that the
      operation was queued into the backlog when the backlog mechanism
      was enabled.
      
      Having the same return code indicate two very different conditions
      depending on a flag is both error prone and requires extra runtime
      check like the following to discern between the cases:
      
      	if (err == -EINPROGRESS ||
      	    (err == -EBUSY && (ahash_request_flags(req) &
      			       CRYPTO_TFM_REQ_MAY_BACKLOG)))
      
      This patch changes the return code used to indicate a crypto op
      failed due to the transformation provider being transiently busy
      to -ENOSPC.
      
      Signed-off-by: default avatarGilad Ben-Yossef <gilad@benyossef.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      6b80ea38
  16. Nov 28, 2016
  17. Nov 01, 2016
  18. Sep 07, 2016
  19. Aug 31, 2016
  20. Jun 23, 2016
  21. Dec 04, 2015
  22. Nov 27, 2015
  23. Aug 17, 2015
  24. Jul 14, 2015
  25. Jul 07, 2015
  26. Jun 03, 2015
  27. May 22, 2015
    • Herbert Xu's avatar
      crypto: cryptd - Use crypto_grab_aead · 9b8c456e
      Herbert Xu authored
      
      As AEAD has switched over to using frontend types, the function
      crypto_init_spawn must not be used since it does not specify a
      frontend type.  Otherwise it leads to a crash when the spawn is
      used.
      
      This patch fixes it by switching over to crypto_grab_aead instead.
      
      Fixes: 5d1d65f8 ("crypto: aead - Convert top level interface to new style")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      9b8c456e
  28. May 13, 2015
  29. Mar 31, 2015
  30. Nov 26, 2014
  31. Aug 01, 2014
Loading