1. 06 3月, 2020 1 次提交
  2. 22 2月, 2020 4 次提交
  3. 09 1月, 2020 1 次提交
    • E
      crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN · 674f368a
      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: NEric Biggers <ebiggers@google.com>
      Reviewed-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      674f368a
  4. 30 8月, 2019 1 次提交
    • A
      crypto: caam - make CAAM_PTR_SZ dynamic · 1a3daadc
      Andrey Smirnov 提交于
      In order to be able to configure CAAM pointer size at run-time, which
      needed to support i.MX8MQ, which is 64-bit SoC with 32-bit pointer
      size, convert CAAM_PTR_SZ to refer to a global variable of the same
      name ("caam_ptr_sz") and adjust the rest of the code accordingly. No
      functional change intended.
      Signed-off-by: NAndrey Smirnov <andrew.smirnov@gmail.com>
      Cc: Chris Spencer <christopher.spencer@sea.co.uk>
      Cc: Cory Tusar <cory.tusar@zii.aero>
      Cc: Chris Healy <cphealy@gmail.com>
      Cc: Lucas Stach <l.stach@pengutronix.de>
      Cc: Horia Geantă <horia.geanta@nxp.com>
      Cc: Aymen Sghaier <aymen.sghaier@nxp.com>
      Cc: Leonard Crestez <leonard.crestez@nxp.com>
      Cc: linux-crypto@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1a3daadc
  5. 22 8月, 2019 1 次提交
  6. 09 8月, 2019 7 次提交
  7. 20 6月, 2019 2 次提交
    • H
      crypto: caam - update IV using HW support · 334d37c9
      Horia Geantă 提交于
      Modify drivers to perform skcipher IV update using the crypto engine,
      instead of performing the operation in SW.
      
      Besides being more efficient, this also fixes IV update for CTR mode.
      
      Output HW S/G table is appended with an entry pointing to the same
      IV buffer used as input (which is now mapped BIDIRECTIONAL).
      
      AS (Algorithm State) parameter of the OPERATION command is changed
      from INIFINAL to INIT in descriptors used by ctr(aes), cbc(aes).
      This is needed since in case FINAL bit is set, HW skips IV updating
      in the Context Register for the last data block.
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      334d37c9
    • H
      crypto: caam - use len instead of nents for bulding HW S/G table · 059d73ee
      Horia Geantă 提交于
      Currently, conversion of SW S/G table into HW S/G layout relies on
      nents returned by sg_nents_for_len(sg, len).
      However this leaves the possibility of HW S/G referencing more data
      then needed: since buffer length in HW S/G entries is filled using
      sg_dma_len(sg), the last entry in HW S/G table might have a length
      that is bigger than needed for the crypto request.
      
      This way of S/G table conversion is fine, unless after converting a table
      more entries have to be appended to the HW S/G table.
      In this case, crypto engine would access data from the S/G entry having
      the incorrect length, instead of advancing in the S/G table.
      This situation doesn't exist, but the upcoming implementation of
      IV update for skcipher algorithms needs to add a S/G entry after
      req->dst S/G (corresponding to output IV).
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      059d73ee
  8. 06 6月, 2019 1 次提交
    • A
      crypto: caam - limit output IV to CBC to work around CTR mode DMA issue · ed527b13
      Ard Biesheuvel 提交于
      The CAAM driver currently violates an undocumented and slightly
      controversial requirement imposed by the crypto stack that a buffer
      referred to by the request structure via its virtual address may not
      be modified while any scatterlists passed via the same request
      structure are mapped for inbound DMA.
      
      This may result in errors like
      
        alg: aead: decryption failed on test 1 for gcm_base(ctr-aes-caam,ghash-generic): ret=74
        alg: aead: Failed to load transform for gcm(aes): -2
      
      on non-cache coherent systems, due to the fact that the GCM driver
      passes an IV buffer by virtual address which shares a cacheline with
      the auth_tag buffer passed via a scatterlist, resulting in corruption
      of the auth_tag when the IV is updated while the DMA mapping is live.
      
      Since the IV that is returned to the caller is only valid for CBC mode,
      and given that the in-kernel users of CBC (such as CTS) don't trigger the
      same issue as the GCM driver, let's just disable the output IV generation
      for all modes except CBC for the time being.
      
      Fixes: 854b06f7 ("crypto: caam - properly set IV after {en,de}crypt")
      Cc: Horia Geanta <horia.geanta@nxp.com>
      Cc: Iuliana Prodan <iuliana.prodan@nxp.com>
      Reported-by: NSascha Hauer <s.hauer@pengutronix.de>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: NHoria Geanta <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ed527b13
  9. 30 5月, 2019 4 次提交
  10. 23 5月, 2019 4 次提交
    • S
      crypto: caam - print debugging hex dumps after unmapping · bb992bc4
      Sascha Hauer 提交于
      For encryption the destination pointer was still mapped, so the hex dump
      may be wrong. The IV still contained the input IV while printing instead
      of the output IV as intended.
      
      For decryption the destination pointer was still mapped, so the hex dump
      may be wrong. The IV dump was correct.
      
      Do the hex dumps consistenly after the buffers have been unmapped and
      in case of IV copied to their final destination.
      Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
      Reviewed-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      bb992bc4
    • H
      crypto: caam - convert top level drivers to libraries · 1b46c90c
      Horia Geantă 提交于
      Currently we allow top level code, i.e. that which sits between the
      low level (HW-specific) drivers and crypto API, to be built as several
      drivers: caamalg, caamhash, caam_pkc, caamrng, caamalg_qi.
      
      There is no advantage in this, more it interferes with adding support
      for deferred probing (there are no corresponding devices and thus
      no bus).
      
      Convert these drivers and call init() / exit() manually at the right
      time.
      Move algorithms initialization at JR probe / remove time:
      -the first probed JR registers the crypto algs
      -the last removed JR unregisters the crypto algs
      
      Note: caam_qi_init() is called before JR platform devices creation
      (of_populate_bus()), such that QI interface is initialized when
      the caam/qi algorithms are registered in the JR driver (by calling
      caam_qi_algapi_init().
      
      While here, fix the Kconfig entries under CRYPTO_DEV_FSL_CAAM_JR
      to be aligned.
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1b46c90c
    • H
      crypto: caam - fix S/G table passing page boundary · a5e5c133
      Horia Geantă 提交于
      According to CAAM RM:
      -crypto engine reads 4 S/G entries (64 bytes) at a time,
      even if the S/G table has fewer entries
      -it's the responsibility of the user / programmer to make sure
      this HW behaviour has no side effect
      
      The drivers do not take care of this currently, leading to IOMMU faults
      when the S/G table ends close to a page boundary - since only one page
      is DMA mapped, while CAAM's DMA engine accesses two pages.
      
      Fix this by rounding up the number of allocated S/G table entries
      to a multiple of 4.
      Note that in case of two *contiguous* S/G tables, only the last table
      might needs extra entries.
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      a5e5c133
    • H
      crypto: caam - avoid S/G table fetching for AEAD zero-length output · dcd9c76e
      Horia Geantă 提交于
      When enabling IOMMU support, the following issue becomes visible
      in the AEAD zero-length case.
      
      Even though the output sequence length is set to zero, the crypto engine
      tries to prefetch 4 S/G table entries (since SGF bit is set
      in SEQ OUT PTR command - which is either generated in SW in case of
      caam/jr or in HW in case of caam/qi, caam/qi2).
      The DMA read operation will trigger an IOMMU fault since the address in
      the SEQ OUT PTR is "dummy" (set to zero / not obtained via DMA API
      mapping).
      
      1. In case of caam/jr, avoid the IOMMU fault by clearing the SGF bit
      in SEQ OUT PTR command.
      
      2. In case of caam/qi - setting address, bpid, length to zero for output
      entry in the compound frame has a special meaning (cf. CAAM RM):
      "Output frame = Unspecified, Input address = Y. A unspecified frame is
      indicated by an unused SGT entry (an entry in which the Address, Length,
      and BPID fields are all zero). SEC obtains output buffers from BMan as
      prescribed by the preheader."
      
      Since no output buffers are needed, modify the preheader by setting
      (ABS = 1, ADDBUF = 0):
      -"ABS = 1 means obtain the number of buffers in ADDBUF (0 or 1) from
      the pool POOL ID"
      -ADDBUF: "If ABS is set, ADD BUF specifies whether to allocate
      a buffer or not"
      
      3. In case of caam/qi2, since engine:
      -does not support FLE[FMT]=2'b11 ("unused" entry) mentioned in DPAA2 RM
      -requires output entry to be present, even if not used
      the solution chosen is to leave output frame list entry zeroized.
      
      Fixes: 763069ba ("crypto: caam - handle zero-length AEAD output")
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      dcd9c76e
  11. 09 5月, 2019 1 次提交
  12. 25 4月, 2019 1 次提交
    • H
      crypto: caam/jr - update gcm detection logic · df80bfd3
      Horia Geantă 提交于
      GCM detection logic has to change for two reasons:
      -some CAAM instantiations with Era < 10, even though they have AES LP,
      they now support GCM mode
      -Era 10 upwards, there is a dedicated bit in AESA_VERSION[AESA_MISC]
      field for GCM support
      
      For Era 9 and earlier, all AES accelerator versions support GCM,
      except for AES LP (CHAVID_LS[AESVID]=3) with revision CRNR[AESRN] < 8.
      
      For Era 10 and later, bit 9 of the AESA_VERSION register should be used
      to detect GCM support in AES accelerator.
      
      Note: caam/qi and caam/qi2 are drivers for QI (Queue Interface), which
      is used in DPAA-based SoCs; for now, we rely on CAAM having an AES HP
      and this AES accelerator having support for GCM.
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Reviewed-by: NIuliana Prodan <iuliana.prodan@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      df80bfd3
  13. 18 4月, 2019 1 次提交
  14. 07 3月, 2019 1 次提交
  15. 15 2月, 2019 3 次提交
  16. 08 2月, 2019 1 次提交
  17. 01 2月, 2019 1 次提交
  18. 10 1月, 2019 1 次提交
  19. 20 11月, 2018 1 次提交
    • E
      crypto: chacha20-generic - refactor to allow varying number of rounds · 1ca1b917
      Eric Biggers 提交于
      In preparation for adding XChaCha12 support, rename/refactor
      chacha20-generic to support different numbers of rounds.  The
      justification for needing XChaCha12 support is explained in more detail
      in the patch "crypto: chacha - add XChaCha12 support".
      
      The only difference between ChaCha{8,12,20} are the number of rounds
      itself; all other parts of the algorithm are the same.  Therefore,
      remove the "20" from all definitions, structures, functions, files, etc.
      that will be shared by all ChaCha versions.
      
      Also make ->setkey() store the round count in the chacha_ctx (previously
      chacha20_ctx).  The generic code then passes the round count through to
      chacha_block().  There will be a ->setkey() function for each explicitly
      allowed round count; the encrypt/decrypt functions will be the same.  I
      decided not to do it the opposite way (same ->setkey() function for all
      round counts, with different encrypt/decrypt functions) because that
      would have required more boilerplate code in architecture-specific
      implementations of ChaCha and XChaCha.
      Reviewed-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: NMartin Willi <martin@strongswan.org>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1ca1b917
  20. 16 11月, 2018 3 次提交