30 Dec, 2020

1 commit

  • [ Upstream commit 5bdad829c31a09069fd508534f03c2ea1576ac75 ]

    Clang warns:

    drivers/crypto/amcc/crypto4xx_core.c:921:60: warning: operator '?:' has
    lower precedence than '|'; '|' will be evaluated first
    [-Wbitwise-conditional-parentheses]
    (crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AEAD) ?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
    drivers/crypto/amcc/crypto4xx_core.c:921:60: note: place parentheses
    around the '|' expression to silence this warning
    (crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AEAD) ?
    ^
    )
    drivers/crypto/amcc/crypto4xx_core.c:921:60: note: place parentheses
    around the '?:' expression to evaluate it first
    (crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AEAD) ?
    ^
    (
    1 warning generated.

    It looks like this should have been a logical OR so that
    PD_CTL_HASH_FINAL gets added to the w bitmask if crypto_tfm_alg_type
    is either CRYPTO_ALG_TYPE_AHASH or CRYPTO_ALG_TYPE_AEAD. Change the
    operator so that everything works properly.

    Fixes: 4b5b79998af6 ("crypto: crypto4xx - fix stalls under heavy load")
    Link: https://github.com/ClangBuiltLinux/linux/issues/1198
    Signed-off-by: Nathan Chancellor
    Reviewed-by: Christian Lamparter
    Signed-off-by: Herbert Xu
    Signed-off-by: Sasha Levin

    Nathan Chancellor
     

02 Oct, 2020

1 commit


20 Aug, 2020

1 commit

  • The header file algapi.h includes skbuff.h unnecessarily since
    all we need is a forward declaration for struct sk_buff. This
    patch removes that inclusion.

    Unfortunately skbuff.h pulls in a lot of things and drivers over
    the years have come to rely on it so this patch adds a lot of
    missing inclusions that result from this.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

09 Jan, 2020

4 commits

  • 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: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • 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: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • 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: Eric Biggers
    Signed-off-by: Herbert Xu

    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: Eric Biggers
    Reviewed-by: Horia Geantă
    Signed-off-by: Herbert Xu

    Eric Biggers
     

08 Nov, 2019

1 commit

  • This patch fixes a crash that can happen during probe
    when the available dma memory is not enough (this can
    happen if the crypto4xx is built as a module).

    The descriptor window mapping would end up being free'd
    twice, once in crypto4xx_build_pdr() and the second time
    in crypto4xx_destroy_sdr().

    Fixes: 5d59ad6eea82 ("crypto: crypto4xx - fix crypto4xx_build_pdr, crypto4xx_build_sdr leak")
    Cc:
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     

26 Jul, 2019

1 commit


20 Jul, 2019

1 commit

  • Pull crypto fixes from Herbert Xu:

    - Fix missed wake-up race in padata

    - Use crypto_memneq in ccp

    - Fix version check in ccp

    - Fix fuzz test failure in ccp

    - Fix potential double free in crypto4xx

    - Fix compile warning in stm32

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
    padata: use smp_mb in padata_reorder to avoid orphaned padata jobs
    crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL
    crypto: ccp/gcm - use const time tag comparison.
    crypto: ccp - memset structure fields to zero before reuse
    crypto: crypto4xx - fix a potential double free in ppc4xx_trng_probe
    crypto: stm32/hash - Fix incorrect printk modifier for size_t

    Linus Torvalds
     

12 Jul, 2019

1 commit

  • There is a possible double free issue in ppc4xx_trng_probe():

    85: dev->trng_base = of_iomap(trng, 0);
    86: of_node_put(trng); ---> released here
    87: if (!dev->trng_base)
    88: goto err_out;
    ...
    110: ierr_out:
    111: of_node_put(trng); ---> double released here
    ...

    This issue was detected by using the Coccinelle software.
    We fix it by removing the unnecessary of_node_put().

    Fixes: 5343e674f32f ("crypto4xx: integrate ppc4xx-rng into crypto4xx")
    Signed-off-by: Wen Yang
    Cc:
    Cc: "David S. Miller"
    Cc: Thomas Gleixner
    Cc: Greg Kroah-Hartman
    Cc: Allison Randal
    Cc: Armijn Hemel
    Cc: Julia Lawall
    Cc: linux-crypto@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Acked-by: Julia Lawall
    Signed-off-by: Herbert Xu

    Wen Yang
     

09 Jul, 2019

1 commit

  • Pull crypto updates from Herbert Xu:
    "Here is the crypto update for 5.3:

    API:
    - Test shash interface directly in testmgr
    - cra_driver_name is now mandatory

    Algorithms:
    - Replace arc4 crypto_cipher with library helper
    - Implement 5 way interleave for ECB, CBC and CTR on arm64
    - Add xxhash
    - Add continuous self-test on noise source to drbg
    - Update jitter RNG

    Drivers:
    - Add support for SHA204A random number generator
    - Add support for 7211 in iproc-rng200
    - Fix fuzz test failures in inside-secure
    - Fix fuzz test failures in talitos
    - Fix fuzz test failures in qat"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (143 commits)
    crypto: stm32/hash - remove interruptible condition for dma
    crypto: stm32/hash - Fix hmac issue more than 256 bytes
    crypto: stm32/crc32 - rename driver file
    crypto: amcc - remove memset after dma_alloc_coherent
    crypto: ccp - Switch to SPDX license identifiers
    crypto: ccp - Validate the the error value used to index error messages
    crypto: doc - Fix formatting of new crypto engine content
    crypto: doc - Add parameter documentation
    crypto: arm64/aes-ce - implement 5 way interleave for ECB, CBC and CTR
    crypto: arm64/aes-ce - add 5 way interleave routines
    crypto: talitos - drop icv_ool
    crypto: talitos - fix hash on SEC1.
    crypto: talitos - move struct talitos_edesc into talitos.h
    lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE
    crypto/NX: Set receive window credits to max number of CRBs in RxFIFO
    crypto: asymmetric_keys - select CRYPTO_HASH where needed
    crypto: serpent - mark __serpent_setkey_sbox noinline
    crypto: testmgr - dynamically allocate crypto_shash
    crypto: testmgr - dynamically allocate testvec_config
    crypto: talitos - eliminate unneeded 'done' functions at build time
    ...

    Linus Torvalds
     

03 Jul, 2019

1 commit


05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation version 2 of the license

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 315 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Armijn Hemel
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190531190115.503150771@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

31 May, 2019

1 commit

  • Based on 3 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [kishon] [vijay] [abraham]
    [i] [kishon]@[ti] [com] this program is distributed in the hope that
    it will be useful but without any warranty without even the implied
    warranty of merchantability or fitness for a particular purpose see
    the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [graeme] [gregory]
    [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i]
    [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema]
    [hk] [hemahk]@[ti] [com] this program is distributed in the hope
    that it will be useful but without any warranty without even the
    implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1105 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

23 May, 2019

3 commits

  • The hardware automatically zero pads incomplete block ciphers
    blocks without raising any errors. This is a screw-up. This
    was noticed by CONFIG_CRYPTO_MANAGER_EXTRA_TESTS tests that
    sent a incomplete blocks and expect them to fail.

    This fixes:
    cbc-aes-ppc4xx encryption unexpectedly succeeded on test vector
    "random: len=2409 klen=32"; expected_error=-22, cfg="random:
    may_sleep use_digest src_divs=[96.90%@+2295, 2.34%@+4066,
    0.32%@alignmask+12, 0.34%@+4087, 0.9%@alignmask+1787, 0.1%@+3767]
    iv_offset=6"

    ecb-aes-ppc4xx encryption unexpectedly succeeded on test vector
    "random: len=1011 klen=32"; expected_error=-22, cfg="random:
    may_sleep use_digest src_divs=[100.0%@alignmask+20]
    dst_divs=[3.12%@+3001, 96.88%@+4070]"

    Cc: Eric Biggers
    Cc: stable@vger.kernel.org [4.19, 5.0 and 5.1]
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • While the hardware consider them to be blockciphers, the
    reference implementation defines them as streamciphers.

    Do the right thing and set the blocksize to 1. This
    was found by CONFIG_CRYPTO_MANAGER_EXTRA_TESTS.

    This fixes the following issues:
    skcipher: blocksize for ofb-aes-ppc4xx (16) doesn't match generic impl (1)
    skcipher: blocksize for cfb-aes-ppc4xx (16) doesn't match generic impl (1)

    Cc: Eric Biggers
    Cc: stable@vger.kernel.org
    Fixes: f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This patch fixes a issue with crypto4xx's ctr(aes) that was
    discovered by libcapi's kcapi-enc-test.sh test.

    The some of the ctr(aes) encryptions test were failing on the
    non-power-of-two test:

    kcapi-enc - Error: encryption failed with error 0
    kcapi-enc - Error: decryption failed with error 0
    [FAILED: 32-bit - 5.1.0-rc1+] 15 bytes: STDIN / STDOUT enc test (128 bits):
    original file (1d100e..cc96184c) and generated file (e3b0c442..1b7852b855)
    [FAILED: 32-bit - 5.1.0-rc1+] 15 bytes: STDIN / STDOUT enc test (128 bits)
    (openssl generated CT): original file (e3b0..5) and generated file (3..8e)
    [PASSED: 32-bit - 5.1.0-rc1+] 15 bytes: STDIN / STDOUT enc test (128 bits)
    (openssl generated PT)
    [FAILED: 32-bit - 5.1.0-rc1+] 15 bytes: STDIN / STDOUT enc test (password):
    original file (1d1..84c) and generated file (e3b..852b855)

    But the 16, 32, 512, 65536 tests always worked.

    Thankfully, this isn't a hidden hardware problem like previously,
    instead this turned out to be a copy and paste issue.

    With this patch, all the tests are passing with and
    kcapi-enc-test.sh gives crypto4xx's a clean bill of health:
    "Number of failures: 0" :).

    Cc: stable@vger.kernel.org
    Fixes: 98e87e3d933b ("crypto: crypto4xx - add aes-ctr support")
    Fixes: f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     

21 May, 2019

1 commit


03 May, 2019

4 commits

  • using_sd is used as a stand-in for sa_command_0.bf.scatter
    that we need to set anyway, so we might as well just prevent
    double-accounting.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This replaces struct crypto_skcipher and the extra request size
    with struct crypto_sync_skcipher and SYNC_SKCIPHER_REQUEST_ON_STACK(),
    which uses a fixed stack size.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • Currently, crypto4xx CFB and OFB AES ciphers are
    failing testmgr's test vectors.

    |cfb-aes-ppc4xx encryption overran dst buffer on test vector 3, cfg="in-place"
    |ofb-aes-ppc4xx encryption overran dst buffer on test vector 1, cfg="in-place"

    This is because of a very subtile "bug" in the hardware that
    gets indirectly mentioned in 18.1.3.5 Encryption/Decryption
    of the hardware spec:

    the OFB and CFB modes for AES are listed there as operation
    modes for >>> "Block ciphers" <<num_gd
    and pd_uinfo->num_sd setters since the value has already been
    set before.

    Cc: stable@vger.kernel.org
    Fixes: f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • Commit 8efd972ef96a ("crypto: testmgr - support checking skcipher output IV")
    caused the crypto4xx driver to produce the following error:

    | ctr-aes-ppc4xx encryption test failed (wrong output IV)
    | on test vector 0, cfg="in-place"

    This patch fixes this by reworking the crypto4xx_setkey_aes()
    function to:

    - not save the iv for ECB (as per 18.2.38 CRYP0_SA_CMD_0:
    "This bit mut be cleared for DES ECB mode or AES ECB mode,
    when no IV is used.")

    - instruct the hardware to save the generated IV for all
    other modes of operations that have IV and then supply
    it back to the callee in pretty much the same way as we
    do it for cbc-aes already.

    - make it clear that the DIR_(IN|OUT)BOUND is the important
    bit that tells the hardware to encrypt or decrypt the data.
    (this is cosmetic - but it hopefully prevents me from
    getting confused again).

    - don't load any bogus hash when we don't use any hash
    operation to begin with.

    Cc: stable@vger.kernel.org
    Fixes: f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     

06 Mar, 2019

1 commit

  • Pull crypto update from Herbert Xu:
    "API:
    - Add helper for simple skcipher modes.
    - Add helper to register multiple templates.
    - Set CRYPTO_TFM_NEED_KEY when setkey fails.
    - Require neither or both of export/import in shash.
    - AEAD decryption test vectors are now generated from encryption
    ones.
    - New option CONFIG_CRYPTO_MANAGER_EXTRA_TESTS that includes random
    fuzzing.

    Algorithms:
    - Conversions to skcipher and helper for many templates.
    - Add more test vectors for nhpoly1305 and adiantum.

    Drivers:
    - Add crypto4xx prng support.
    - Add xcbc/cmac/ecb support in caam.
    - Add AES support for Exynos5433 in s5p.
    - Remove sha384/sha512 from artpec7 as hardware cannot do partial
    hash"

    [ There is a merge of the Freescale SoC tree in order to pull in changes
    required by patches to the caam/qi2 driver. ]

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (174 commits)
    crypto: s5p - add AES support for Exynos5433
    dt-bindings: crypto: document Exynos5433 SlimSSS
    crypto: crypto4xx - add missing of_node_put after of_device_is_available
    crypto: cavium/zip - fix collision with generic cra_driver_name
    crypto: af_alg - use struct_size() in sock_kfree_s()
    crypto: caam - remove redundant likely/unlikely annotation
    crypto: s5p - update iv after AES-CBC op end
    crypto: x86/poly1305 - Clear key material from stack in SSE2 variant
    crypto: caam - generate hash keys in-place
    crypto: caam - fix DMA mapping xcbc key twice
    crypto: caam - fix hash context DMA unmap size
    hwrng: bcm2835 - fix probe as platform device
    crypto: s5p-sss - Use AES_BLOCK_SIZE define instead of number
    crypto: stm32 - drop pointless static qualifier in stm32_hash_remove()
    crypto: chelsio - Fixed Traffic Stall
    crypto: marvell - Remove set but not used variable 'ivsize'
    crypto: ccp - Update driver messages to remove some confusion
    crypto: adiantum - add 1536 and 4096-byte test vectors
    crypto: nhpoly1305 - add a test vector with len % 16 != 0
    crypto: arm/aes-ce - update IV after partial final CTR block
    ...

    Linus Torvalds
     

28 Feb, 2019

1 commit

  • Add an of_node_put when a tested device node is not available.

    The semantic patch that fixes this problem is as follows
    (http://coccinelle.lip6.fr):

    //
    @@
    identifier f;
    local idexpression e;
    expression x;
    @@

    e = f(...);
    ... when != of_node_put(e)
    when != x = e
    when != e = x
    when any
    if () {
    ... when != of_node_put(e)
    (
    return e;
    |
    + of_node_put(e);
    return ...;
    )
    }
    //

    Fixes: 5343e674f32fb ("crypto4xx: integrate ppc4xx-rng into crypto4xx")
    Signed-off-by: Julia Lawall
    Signed-off-by: Herbert Xu

    Julia Lawall
     

01 Feb, 2019

1 commit

  • When building without CONFIG_HW_RANDOM_PPC4XX, I hit the following build failure:
    drivers/crypto/amcc/crypto4xx_core.c: In function 'crypto4xx_probe':
    drivers/crypto/amcc/crypto4xx_core.c:1407:20: error: passing argument 1 of 'ppc4xx_trng_probe' from incompatible pointer type [-Werror=incompatible-pointer-types]
    In file included from drivers/crypto/amcc/crypto4xx_core.c:50:0:
    drivers/crypto/amcc/crypto4xx_trng.h:28:20: note: expected 'struct crypto4xx_device *' but argument is of type 'struct crypto4xx_core_device *'
    drivers/crypto/amcc/crypto4xx_core.c: In function 'crypto4xx_remove':
    drivers/crypto/amcc/crypto4xx_core.c:1434:21: error: passing argument 1 of 'ppc4xx_trng_remove' from incompatible pointer type [-Werror=incompatible-pointer-types]
    In file included from drivers/crypto/amcc/crypto4xx_core.c:50:0:
    drivers/crypto/amcc/crypto4xx_trng.h:30:20: note: expected 'struct crypto4xx_device *' but argument is of type 'struct crypto4xx_core_device *'

    This patch fix the needed argument of ppc4xx_trng_probe()/ppc4xx_trng_remove() in that case.

    Fixes: 5343e674f32f ("crypto4xx: integrate ppc4xx-rng into crypto4xx")
    Signed-off-by: Corentin Labbe
    Signed-off-by: Herbert Xu

    Corentin Labbe
     

11 Jan, 2019

1 commit

  • This patch adds support for crypto4xx's ANSI X9.17 Annex C compliant
    pseudo random number generator which provides a pseudo random source
    for the purpose of generating Initialization Vectors (IV's) for AES
    algorithms to the Packet Engine and other pseudo random number
    requirements.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     

08 Jan, 2019

1 commit

  • We already need to zero out memory for dma_alloc_coherent(), as such
    using dma_zalloc_coherent() is superflous. Phase it out.

    This change was generated with the following Coccinelle SmPL patch:

    @ replace_dma_zalloc_coherent @
    expression dev, size, data, handle, flags;
    @@

    -dma_zalloc_coherent(dev, size, handle, flags)
    +dma_alloc_coherent(dev, size, handle, flags)

    Suggested-by: Christoph Hellwig
    Signed-off-by: Luis Chamberlain
    [hch: re-ran the script on the latest tree]
    Signed-off-by: Christoph Hellwig

    Luis Chamberlain
     

28 Dec, 2018

1 commit

  • Pull crypto updates from Herbert Xu:
    "API:
    - Add 1472-byte test to tcrypt for IPsec
    - Reintroduced crypto stats interface with numerous changes
    - Support incremental algorithm dumps

    Algorithms:
    - Add xchacha12/20
    - Add nhpoly1305
    - Add adiantum
    - Add streebog hash
    - Mark cts(cbc(aes)) as FIPS allowed

    Drivers:
    - Improve performance of arm64/chacha20
    - Improve performance of x86/chacha20
    - Add NEON-accelerated nhpoly1305
    - Add SSE2 accelerated nhpoly1305
    - Add AVX2 accelerated nhpoly1305
    - Add support for 192/256-bit keys in gcmaes AVX
    - Add SG support in gcmaes AVX
    - ESN for inline IPsec tx in chcr
    - Add support for CryptoCell 703 in ccree
    - Add support for CryptoCell 713 in ccree
    - Add SM4 support in ccree
    - Add SM3 support in ccree
    - Add support for chacha20 in caam/qi2
    - Add support for chacha20 + poly1305 in caam/jr
    - Add support for chacha20 + poly1305 in caam/qi2
    - Add AEAD cipher support in cavium/nitrox"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (130 commits)
    crypto: skcipher - remove remnants of internal IV generators
    crypto: cavium/nitrox - Fix build with !CONFIG_DEBUG_FS
    crypto: salsa20-generic - don't unnecessarily use atomic walk
    crypto: skcipher - add might_sleep() to skcipher_walk_virt()
    crypto: x86/chacha - avoid sleeping under kernel_fpu_begin()
    crypto: cavium/nitrox - Added AEAD cipher support
    crypto: mxc-scc - fix build warnings on ARM64
    crypto: api - document missing stats member
    crypto: user - remove unused dump functions
    crypto: chelsio - Fix wrong error counter increments
    crypto: chelsio - Reset counters on cxgb4 Detach
    crypto: chelsio - Handle PCI shutdown event
    crypto: chelsio - cleanup:send addr as value in function argument
    crypto: chelsio - Use same value for both channel in single WR
    crypto: chelsio - Swap location of AAD and IV sent in WR
    crypto: chelsio - remove set but not used variable 'kctx_len'
    crypto: ux500 - Use proper enum in hash_set_dma_transfer
    crypto: ux500 - Use proper enum in cryp_set_dma_transfer
    crypto: aesni - Add scatter/gather avx stubs, and use them in C
    crypto: aesni - Introduce partial block macro
    ..

    Linus Torvalds
     

20 Dec, 2018

1 commit

  • This function is internal to the DMA API implementation. Instead use
    the DMA API to properly unmap. Note that the DMA API usage in this
    driver is a disaster and urgently needs some work - it is missing all
    the unmaps, seems to do a secondary map where it looks like it should
    to a unmap in one place to work around cache coherency and the
    directions passed in seem to be partially wrong.

    Signed-off-by: Christoph Hellwig
    Tested-by: Christian Lamparter
    Signed-off-by: Michael Ellerman

    Christoph Hellwig
     

20 Nov, 2018

1 commit

  • 'cipher' algorithms (single block ciphers) are always synchronous, so
    passing CRYPTO_ALG_ASYNC in the mask to crypto_alloc_cipher() has no
    effect. Many users therefore already don't pass it, but some still do.
    This inconsistency can cause confusion, especially since the way the
    'mask' argument works is somewhat counterintuitive.

    Thus, just remove the unneeded CRYPTO_ALG_ASYNC flags.

    This patch shouldn't change any actual behavior.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

09 Jul, 2018

1 commit

  • Some skcipher algorithms set .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER. But
    this is redundant with the C structure type ('struct skcipher_alg'), and
    crypto_register_skcipher() already sets the type flag automatically,
    clearing any type flag that was already there. Apparently the useless
    assignment has just been copy+pasted around.

    So, remove the useless assignment from all the skcipher algorithms.

    This patch shouldn't change any actual behavior.

    Signed-off-by: Eric Biggers
    Acked-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu

    Eric Biggers
     

13 Jun, 2018

1 commit

  • The kzalloc() function has a 2-factor argument form, kcalloc(). This
    patch replaces cases of:

    kzalloc(a * b, gfp)

    with:
    kcalloc(a * b, gfp)

    as well as handling cases of:

    kzalloc(a * b * c, gfp)

    with:

    kzalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kzalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kzalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kzalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kzalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kzalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kzalloc
    + kcalloc
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kzalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kzalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kzalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kzalloc(sizeof(THING) * C2, ...)
    |
    kzalloc(sizeof(TYPE) * C2, ...)
    |
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(C1 * C2, ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

28 Apr, 2018

7 commits

  • This patch fixes a crash that happens when testing rfc4543(gcm(aes))

    Unable to handle kernel paging request for data at address 0xf59b3420
    Faulting instruction address: 0xc0012994
    Oops: Kernel access of bad area, sig: 11 [#1]
    BE PowerPC 44x Platform
    Modules linked in: tcrypt(+) crypto4xx [...]
    CPU: 0 PID: 0 Comm: swapper Tainted: G O 4.17.0-rc1+ #23
    NIP: c0012994 LR: d3077934 CTR: 06026d49
    REGS: cfff7e30 TRAP: 0300 Tainted: G O (4.17.0-rc1+)
    MSR: 00029000 CR: 44744822 XER: 00000000
    DEAR: f59b3420 ESR: 00000000
    NIP [c0012994] __dma_sync+0x58/0x10c
    LR [d3077934] crypto4xx_bh_tasklet_cb+0x188/0x3c8 [crypto4xx]

    __dma_sync was fed the temporary _dst that crypto4xx_build_pd()
    had in it's function stack. This clearly never worked.
    This patch therefore overhauls the code from the original driver
    and puts the temporary dst sg list into aead's request context.

    Fixes: a0aae821ba3d3 ("crypto: crypto4xx - prepare for AEAD support")
    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • 1020 bytes is the limit for associated data. Any more
    and it will no longer fit into hash_crypto_offset anymore.

    The hardware will not process aead requests with plaintext
    that have less than AES_BLOCK_SIZE bytes. When decrypting
    aead requests the authsize has to be taken in account as
    well, as it is part of the cryptlen. Otherwise the hardware
    will think it has been misconfigured and will return:

    aead return err status = 0x98

    For rtc4543(gcm(aes)), the hardware has a dedicated GMAC
    mode as part of the hash function set.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This patch fixes cts(cbc(aes)) test when cbc-aes-ppc4xx is used.
    alg: skcipher: Test 1 failed (invalid result) on encryption for cts(cbc-aes-ppc4xx)
    00000000: 4b 10 75 fc 2f 14 1b 6a 27 35 37 33 d1 b7 70 05
    00000010: 97
    alg: skcipher: Failed to load transform for cts(cbc(aes)): -2

    The CTS cipher mode expect the IV (req->iv) of skcipher_request
    to contain the last ciphertext block after the {en,de}crypt
    operation is complete.

    Fix this issue for the AMCC Crypto4xx hardware engine.
    The tcrypt test case for cts(cbc(aes)) is now correctly passed.

    name : cts(cbc(aes))
    driver : cts(cbc-aes-ppc4xx)
    module : cts
    priority : 300
    refcnt : 1
    selftest : passed
    internal : no
    type : skcipher
    async : yes
    blocksize : 16
    min keysize : 16
    max keysize : 32
    ivsize : 16
    chunksize : 16
    walksize : 16

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This patch adds support for the aes-ctr skcipher.

    name : ctr(aes)
    driver : ctr-aes-ppc4xx
    module : crypto4xx
    priority : 300
    refcnt : 1
    selftest : passed
    internal : no
    type : skcipher
    async : yes
    blocksize : 16
    min keysize : 16
    max keysize : 32
    ivsize : 16
    chunksize : 16
    walksize : 16

    The hardware uses only the last 32-bits as the counter while the
    kernel tests (aes_ctr_enc_tv_template[4] for example) expect that
    the whole IV is a counter. To make this work, the driver will
    fallback if the counter is going to overlow.

    The aead's crypto4xx_setup_fallback() function is renamed to
    crypto4xx_aead_setup_fallback.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This patch fixes some of the -Wvla warnings.

    crypto4xx_alg.c:83:19: warning: Variable length array is used.
    crypto4xx_alg.c:273:56: warning: Variable length array is used.
    crypto4xx_alg.c:380:32: warning: Variable length array is used.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • The ablkcipher APIs have been effectively deprecated since [1].
    This patch converts the crypto4xx driver to the new skcipher APIs.

    [1]

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter
     
  • This patch provides a cheap 2MiB/s+ (~ 6%) performance
    improvement over the current code. This is because the
    compiler can now optimize several endian swap memcpy.

    Signed-off-by: Christian Lamparter
    Signed-off-by: Herbert Xu

    Christian Lamparter