1. 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
  2. 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
  3. 30 5月, 2019 4 次提交
  4. 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
  5. 09 5月, 2019 1 次提交
  6. 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
  7. 18 4月, 2019 1 次提交
  8. 07 3月, 2019 1 次提交
  9. 15 2月, 2019 3 次提交
  10. 08 2月, 2019 1 次提交
  11. 01 2月, 2019 1 次提交
  12. 10 1月, 2019 1 次提交
  13. 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
  14. 16 11月, 2018 3 次提交
  15. 17 10月, 2018 1 次提交
  16. 21 9月, 2018 1 次提交
    • H
      crypto: caam/jr - fix ablkcipher_edesc pointer arithmetic · 13cc6f48
      Horia Geantă 提交于
      In some cases the zero-length hw_desc array at the end of
      ablkcipher_edesc struct requires for 4B of tail padding.
      
      Due to tail padding and the way pointers to S/G table and IV
      are computed:
      	edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
      			 desc_bytes;
      	iv = (u8 *)edesc->hw_desc + desc_bytes + sec4_sg_bytes;
      first 4 bytes of IV are overwritten by S/G table.
      
      Update computation of pointer to S/G table to rely on offset of hw_desc
      member and not on sizeof() operator.
      
      Cc: <stable@vger.kernel.org> # 4.13+
      Fixes: 115957bb ("crypto: caam - fix IV DMA mapping and updating")
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      13cc6f48
  17. 04 9月, 2018 3 次提交
  18. 21 4月, 2018 2 次提交
  19. 31 3月, 2018 1 次提交
  20. 15 2月, 2018 1 次提交
  21. 28 12月, 2017 2 次提交
  22. 22 9月, 2017 1 次提交
  23. 18 7月, 2017 1 次提交
    • H
      crypto: caam/qi - fix compilation with DEBUG enabled · 972b812b
      Horia Geantă 提交于
      caam/qi driver does not compile when DEBUG is enabled
      (CRYPTO_DEV_FSL_CAAM_DEBUG=y):
      
      drivers/crypto/caam/caamalg_qi.c: In function 'ablkcipher_done':
      drivers/crypto/caam/caamalg_qi.c:794:2: error: implicit declaration of function 'dbg_dump_sg' [-Werror=implicit-function-declaration]
        dbg_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
      
      Since dbg_dump_sg() is shared between caam/jr and caam/qi, move it
      in a shared location and export it.
      
      At the same time:
      -reduce ifdeferry by providing a no-op implementation for !DEBUG case
      -rename it to caam_dump_sg() to be consistent in terms of
      exported symbols namespace (caam_*)
      
      Cc: <stable@vger.kernel.org>
      Fixes: b189817c ("crypto: caam/qi - add ablkcipher and authenc algorithms")
      Signed-off-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      972b812b
  24. 12 7月, 2017 1 次提交
    • D
      crypto: caam - properly set IV after {en,de}crypt · 854b06f7
      David Gstir 提交于
      Certain cipher modes like CTS expect the IV (req->info) of
      ablkcipher_request (or equivalently req->iv of skcipher_request) to
      contain the last ciphertext block when the {en,de}crypt operation is done.
      This is currently not the case for the CAAM driver which in turn breaks
      e.g. cts(cbc(aes)) when the CAAM driver is enabled.
      
      This patch fixes the CAAM driver to properly set the IV after the
      {en,de}crypt operation of ablkcipher finishes.
      
      This issue was revealed by the changes in the SW CTS mode in commit
      0605c41c ("crypto: cts - Convert to skcipher")
      
      Cc: <stable@vger.kernel.org> # 4.8+
      Signed-off-by: NDavid Gstir <david@sigma-star.at>
      Reviewed-by: NHoria Geantă <horia.geanta@nxp.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      854b06f7
  25. 22 6月, 2017 1 次提交