08 Oct, 2020

1 commit

  • The setkey function for GCM/CCM algorithms didn't verify the key
    length before copying the key and subtracting the salt length.

    This patch delays the copying of the key til after the verification
    has been done. It also adds checks on the key length to ensure
    that it's at least as long as the salt.

    Fixes: 9d12ba86f818 ("crypto: brcm - Add Broadcom SPU driver")
    Cc:
    Reported-by: kiyin(尹亮)
    Signed-off-by: Herbert Xu

    Herbert Xu
     

11 Sep, 2020

1 commit


16 Jul, 2020

1 commit

  • Set the flag CRYPTO_ALG_ALLOCATES_MEMORY in the crypto drivers that
    allocate memory.

    drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c: sun8i_ce_cipher
    drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c: sun8i_ss_cipher
    drivers/crypto/amlogic/amlogic-gxl-core.c: meson_cipher
    drivers/crypto/axis/artpec6_crypto.c: artpec6_crypto_common_init
    drivers/crypto/bcm/cipher.c: spu_skcipher_rx_sg_create
    drivers/crypto/caam/caamalg.c: aead_edesc_alloc
    drivers/crypto/caam/caamalg_qi.c: aead_edesc_alloc
    drivers/crypto/caam/caamalg_qi2.c: aead_edesc_alloc
    drivers/crypto/caam/caamhash.c: hash_digest_key
    drivers/crypto/cavium/cpt/cptvf_algs.c: process_request
    drivers/crypto/cavium/nitrox/nitrox_aead.c: nitrox_process_se_request
    drivers/crypto/cavium/nitrox/nitrox_skcipher.c: nitrox_process_se_request
    drivers/crypto/ccp/ccp-crypto-aes-cmac.c: ccp_do_cmac_update
    drivers/crypto/ccp/ccp-crypto-aes-galois.c: ccp_crypto_enqueue_request
    drivers/crypto/ccp/ccp-crypto-aes-xts.c: ccp_crypto_enqueue_request
    drivers/crypto/ccp/ccp-crypto-aes.c: ccp_crypto_enqueue_request
    drivers/crypto/ccp/ccp-crypto-des3.c: ccp_crypto_enqueue_request
    drivers/crypto/ccp/ccp-crypto-sha.c: ccp_crypto_enqueue_request
    drivers/crypto/chelsio/chcr_algo.c: create_cipher_wr
    drivers/crypto/hisilicon/sec/sec_algs.c: sec_alloc_and_fill_hw_sgl
    drivers/crypto/hisilicon/sec2/sec_crypto.c: sec_alloc_req_id
    drivers/crypto/inside-secure/safexcel_cipher.c: safexcel_queue_req
    drivers/crypto/inside-secure/safexcel_hash.c: safexcel_ahash_enqueue
    drivers/crypto/ixp4xx_crypto.c: ablk_perform
    drivers/crypto/marvell/cesa/cipher.c: mv_cesa_skcipher_dma_req_init
    drivers/crypto/marvell/cesa/hash.c: mv_cesa_ahash_dma_req_init
    drivers/crypto/marvell/octeontx/otx_cptvf_algs.c: create_ctx_hdr
    drivers/crypto/n2_core.c: n2_compute_chunks
    drivers/crypto/picoxcell_crypto.c: spacc_sg_to_ddt
    drivers/crypto/qat/qat_common/qat_algs.c: qat_alg_skcipher_encrypt
    drivers/crypto/qce/skcipher.c: qce_skcipher_async_req_handle
    drivers/crypto/talitos.c : talitos_edesc_alloc
    drivers/crypto/virtio/virtio_crypto_algs.c: __virtio_crypto_skcipher_do_req
    drivers/crypto/xilinx/zynqmp-aes-gcm.c: zynqmp_aes_aead_cipher

    Signed-off-by: Mikulas Patocka
    [EB: avoid overly-long lines]
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Mikulas Patocka
     

08 May, 2020

1 commit


30 Apr, 2020

2 commits


24 Apr, 2020

1 commit


20 Mar, 2020

1 commit


09 Jan, 2020

2 commits

  • 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
     

17 Nov, 2019

1 commit

  • Commit 7a7ffe65c8c5 ("crypto: skcipher - Add top-level skcipher interface")
    dated 20 august 2015 introduced the new skcipher API which is supposed to
    replace both blkcipher and ablkcipher. While all consumers of the API have
    been converted long ago, some producers of the ablkcipher remain, forcing
    us to keep the ablkcipher support routines alive, along with the matching
    code to expose [a]blkciphers via the skcipher API.

    So switch this driver to the skcipher API, allowing us to finally drop the
    ablkcipher code in the near future.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     

22 Aug, 2019

1 commit


27 Jul, 2019

1 commit

  • Validated assoclen for RFC4543 which expects an assoclen
    of 16 or 20, the same as RFC4106.
    Based on seqiv, IPsec ESP and RFC4543/RFC4106 the assoclen is sizeof
    IP Header (spi, seq_no, extended seq_no) and IV len. This can be 16 or
    20 bytes.

    Signed-off-by: Iuliana Prodan
    Signed-off-by: Herbert Xu

    Iuliana Prodan
     

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
     

19 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 version 2 as
    published by the free software foundation the gpl 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
    version 2 gplv2 for more details you should have received a copy of
    the gnu general public license version 2 gplv2 along with this
    source code

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

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

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

    Thomas Gleixner
     

13 Jun, 2019

1 commit

  • Fix sparse warnings:

    drivers/crypto/bcm/cipher.c:99:6: warning: symbol 'BCMHEADER' was not declared. Should it be static?
    drivers/crypto/bcm/cipher.c:2096:6: warning: symbol 'spu_no_incr_hash' was not declared. Should it be static?
    drivers/crypto/bcm/cipher.c:4823:5: warning: symbol 'bcm_spu_probe' was not declared. Should it be static?
    drivers/crypto/bcm/cipher.c:4867:5: warning: symbol 'bcm_spu_remove' was not declared. Should it be static?
    drivers/crypto/bcm/spu2.c:52:6: warning: symbol 'spu2_cipher_type_names' was not declared. Should it be static?
    drivers/crypto/bcm/spu2.c:56:6: warning: symbol 'spu2_cipher_mode_names' was not declared. Should it be static?
    drivers/crypto/bcm/spu2.c:60:6: warning: symbol 'spu2_hash_type_names' was not declared. Should it be static?
    drivers/crypto/bcm/spu2.c:66:6: warning: symbol 'spu2_hash_mode_names' was not declared. Should it be static?

    Reported-by: Hulk Robot
    Signed-off-by: YueHaibing
    Signed-off-by: Herbert Xu

    YueHaibing
     

21 May, 2019

1 commit


25 Apr, 2019

1 commit

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

    Eric Biggers
     

18 Apr, 2019

1 commit


28 Mar, 2019

1 commit


15 Feb, 2019

1 commit

  • Some arc4 cipher algorithm defines show up in two places:
    crypto/arc4.c and drivers/crypto/bcm/cipher.h.
    Let's export them in a common header and update their users.

    Signed-off-by: Iuliana Prodan
    Reviewed-by: Horia Geantă
    Signed-off-by: Herbert Xu

    Iuliana Prodan
     

01 Feb, 2019

1 commit

  • The header search path -I. in kernel Makefiles is very suspicious;
    it allows the compiler to search for headers in the top of $(srctree),
    where obviously no header file exists.

    'git grep BCMDRIVER' has no hit. So, this macro is not referenced.

    I was able to build this driver without the extra compiler options.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Herbert Xu

    Masahiro Yamada
     

25 Jan, 2019

2 commits

  • CRYPTO_TFM_REQ_WEAK_KEY confuses newcomers to the crypto API because it
    sounds like it is requesting a weak key. Actually, it is requesting
    that weak keys be forbidden (for algorithms that have the notion of
    "weak keys"; currently only DES and XTS do).

    Also it is only one letter away from CRYPTO_TFM_RES_WEAK_KEY, with which
    it can be easily confused. (This in fact happened in the UX500 driver,
    though just in some debugging messages.)

    Therefore, make the intent clear by renaming it to
    CRYPTO_TFM_REQ_FORBID_WEAK_KEYS.

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

    Eric Biggers
     
  • The do_decrypt() function in util.c in the BCM crypto driver is never
    used, so remove it.

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

    Eric Biggers
     

18 Jan, 2019

1 commit

  • Fixes gcc '-Wunused-but-set-variable' warning:

    drivers/crypto/bcm/cipher.c: In function 'handle_ahash_req':
    drivers/crypto/bcm/cipher.c:720:15: warning:
    variable 'chunk_start' set but not used [-Wunused-but-set-variable]

    drivers/crypto/bcm/cipher.c: In function 'spu_rx_callback':
    drivers/crypto/bcm/cipher.c:1679:31: warning:
    variable 'areq' set but not used [-Wunused-but-set-variable]

    drivers/crypto/bcm/cipher.c:1678:22: warning:
    variable 'ctx' set but not used [-Wunused-but-set-variable]

    Fixes: 9d12ba86f818 ("crypto: brcm - Add Broadcom SPU driver")
    Signed-off-by: YueHaibing
    Reviewed-by: Raveendra Padasalagi
    Signed-off-by: Herbert Xu

    YueHaibing
     

10 Jan, 2019

1 commit

  • Convert the bcm crypto driver to use crypto_authenc_extractkeys() so
    that it picks up the fix for broken validation of rtattr::rta_len.

    This also fixes the DES weak key check to actually be done on the right
    key. (It was checking the authentication key, not the encryption key...)

    Fixes: 9d12ba86f818 ("crypto: brcm - Add Broadcom SPU driver")
    Cc: # v4.11+
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

23 Dec, 2018

1 commit

  • 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 "" or "" in those cases.

    - The 'skcipher_givcrypt_request' structure, which is never used.

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

    Eric Biggers
     

20 Nov, 2018

1 commit

  • Some algorithms initialize their .cra_list prior to registration.
    But this is unnecessary since crypto_register_alg() will overwrite
    .cra_list when adding the algorithm to the 'crypto_alg_list'.
    Apparently the useless assignment has just been copy+pasted around.

    So, remove the useless assignments.

    Exception: paes_s390.c uses cra_list to check whether the algorithm is
    registered or not, so I left that as-is for now.

    This patch shouldn't change any actual behavior.

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

    Eric Biggers
     

16 Nov, 2018

1 commit


09 Jul, 2018

3 commits

  • Some aead algorithms set .cra_flags = CRYPTO_ALG_TYPE_AEAD. But this is
    redundant with the C structure type ('struct aead_alg'), and
    crypto_register_aead() 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 aead algorithms.

    This patch shouldn't change any actual behavior.

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

    Eric Biggers
     
  • Some ahash algorithms set .cra_type = &crypto_ahash_type. But this is
    redundant with the C structure type ('struct ahash_alg'), and
    crypto_register_ahash() already sets the .cra_type automatically.
    Apparently the useless assignment has just been copy+pasted around.

    So, remove the useless assignment from all the ahash 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
     
  • Many ahash algorithms set .cra_flags = CRYPTO_ALG_TYPE_AHASH. But this
    is redundant with the C structure type ('struct ahash_alg'), and
    crypto_register_ahash() 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 ahash 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
     

31 Mar, 2018

1 commit

  • In the AES cases enum spu_cipher_type and enum hash_type have
    the same values, so the assignment is fine. Explicitly cast
    the enum type conversion.

    This fixes two warnings when building with clang:
    drivers/crypto/bcm/cipher.c:821:34: warning: implicit conversion from
    enumeration type 'enum spu_cipher_type' to different enumeration
    type 'enum hash_type' [-Wenum-conversion]
    hash_parms.type = cipher_parms.type;
    ~ ~~~~~~~~~~~~~^~~~
    drivers/crypto/bcm/cipher.c:1412:26: warning: implicit conversion from
    enumeration type 'enum spu_cipher_type' to different enumeration
    type 'enum hash_type' [-Wenum-conversion]
    hash_parms.type = ctx->cipher_type;
    ~ ~~~~~^~~~~~~~~~~

    Signed-off-by: Stefan Agner
    Signed-off-by: Herbert Xu

    Stefan Agner
     

22 Feb, 2018

1 commit


22 Dec, 2017

1 commit


12 Oct, 2017

1 commit


07 Oct, 2017

1 commit


22 Sep, 2017

2 commits

  • Add support to explicity ACK mailbox message
    because after sending message we can know
    the send status via error attribute of brcm_message.

    This is needed to support "txdone_ack" supported in
    mailbox controller driver.

    Fixes: 9d12ba86f818 ("crypto: brcm - Add Broadcom SPU driver")
    Signed-off-by: Raveendra Padasalagi
    Reviewed-by: Anup Patel
    Reviewed-by: Scott Branden
    Cc: stable@vger.kernel.org
    Signed-off-by: Herbert Xu

    raveendra padasalagi
     
  • This patch replace GCM IV size value by their constant name.

    Signed-off-by: Corentin Labbe
    Signed-off-by: Herbert Xu

    Corentin LABBE
     

03 Aug, 2017

1 commit

  • Enhance code to generically support cases where DMA rings
    are greater than or equal to number of SPU engines.
    New hardware has underlying DMA engine-FlexRM with 32 rings
    which can be used to communicate to any of the available
    10 SPU engines.

    Signed-off-by: Raveendra Padasalagi
    Reviewed-by: Scott Branden
    Reviewed-by: Florian Fainelli
    Signed-off-by: Herbert Xu

    raveendra padasalagi