Commit Graph

303 Commits

Author SHA1 Message Date
Baoquan He 78ef223d06 use less confusing names for iov_iter direction initializers
JIRA: https://issues.redhat.com/browse/RHEL-32199

Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Note: The core of this patch was already backported in commit 0d33f8e1f3.
      And later commit a9e6d7970e back ported cifs part. This patch tries
      to back port the remaining parts which doesn't have conficts. This
      change is easing code reading and understanding, not related to
      functionality or features, hence leave those parts to module developer
      to back port when dependency is met.

commit de4eda9de2d957ef2d6a8365a01e26a435e958cb
Author: Al Viro <viro@zeniv.linux.org.uk>
Date:   Thu Sep 15 20:25:47 2022 -0400

    use less confusing names for iov_iter direction initializers

    READ/WRITE proved to be actively confusing - the meanings are
    "data destination, as used with read(2)" and "data source, as
    used with write(2)", but people keep interpreting those as
    "we read data from it" and "we write data to it", i.e. exactly
    the wrong way.

    Call them ITER_DEST and ITER_SOURCE - at least that is harder
    to misinterpret...

    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Baoquan He <bhe@redhat.com>
2024-05-15 13:56:26 +08:00
Lucas Zampieri 7f664f6544 Merge: crypto: akcipher - Disable signing and decryption
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3755

JIRA: https://issues.redhat.com/browse/RHEL-17113
Upstream Status: RHEL only
CVE: CVE-2023-6240

    The decryption and signing capabilities are never used within the
    kernel.  However, they are exposed to user-space through the keyctl
    system call.

    As these operations may cause security issues, disable them by
    stubbing out the relevant entry points.

Signed-off-by: Herbert Xu <herbert.xu@redhat.com>

Approved-by: Vladis Dronov <vdronov@redhat.com>
Approved-by: John B. Wyatt IV <jwyatt@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-03-14 09:46:52 -03:00
Herbert Xu 3709c35cf1 crypto: akcipher - Disable signing and decryption
JIRA: https://issues.redhat.com/browse/RHEL-17113
Upstream Status: RHEL only
CVE: CVE-2023-6240

The decryption and signing capabilities are never used within the
kernel.  However, they are exposed to user-space through the keyctl
system call.

As these operations may cause security issues, disable them by
stubbing out the relevant entry points.

Signed-off-by: Herbert Xu <herbert.xu@redhat.com>
2024-02-15 11:47:40 +08:00
Vladis Dronov cd1de8cd66 crypto: iaa - Add support for deflate-iaa compression algorithm
JIRA: https://issues.redhat.com/browse/RHEL-20145
Upstream Status: merged into the linux.git

commit 2ec6761df889fdf896fde761abd447596dd8f8c2
Author: Tom Zanussi <tom.zanussi@linux.intel.com>
Date:   Tue Dec 5 15:25:27 2023 -0600

    crypto: iaa - Add support for deflate-iaa compression algorithm

    This patch registers the deflate-iaa deflate compression algorithm and
    hooks it up to the IAA hardware using the 'fixed' compression mode
    introduced in the previous patch.

    Because the IAA hardware has a 4k history-window limitation, only
    buffers <= 4k, or that have been compressed using a <= 4k history
    window, are technically compliant with the deflate spec, which allows
    for a window of up to 32k.  Because of this limitation, the IAA fixed
    mode deflate algorithm is given its own algorithm name, 'deflate-iaa'.

    With this change, the deflate-iaa crypto algorithm is registered and
    operational, and compression and decompression operations are fully
    enabled following the successful binding of the first IAA workqueue
    to the iaa_crypto sub-driver.

    when there are no IAA workqueues bound to the driver, the IAA crypto
    algorithm can be unregistered by removing the module.

    A new iaa_crypto 'verify_compress' driver attribute is also added,
    allowing the user to toggle compression verification.  If set, each
    compress will be internally decompressed and the contents verified,
    returning error codes if unsuccessful.  This can be toggled with 0/1:

      echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress

    The default setting is '1' - verify all compresses.

    The verify_compress value setting at the time the algorithm is
    registered is captured in the algorithm's crypto_ctx and used for all
    compresses when using the algorithm.

    [ Based on work originally by George Powley, Jing Lin and Kyung Min
    Park ]

    Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2024-01-17 15:29:12 +01:00
Ivan Vecera b2b9e94d48 crypto: testmgr - fix RNG performance in fuzz tests
JIRA: https://issues.redhat.com/browse/RHEL-3646

commit f900fde28883602b6c5e1027a6c912b673382aaf
Author: Eric Biggers <ebiggers@google.com>
Date:   Mon Feb 27 10:29:47 2023 -0800

    crypto: testmgr - fix RNG performance in fuzz tests

    The performance of the crypto fuzz tests has greatly regressed since
    v5.18.  When booting a kernel on an arm64 dev board with all software
    crypto algorithms and CONFIG_CRYPTO_MANAGER_EXTRA_TESTS enabled, the
    fuzz tests now take about 200 seconds to run, or about 325 seconds with
    lockdep enabled, compared to about 5 seconds before.

    The root cause is that the random number generation has become much
    slower due to commit d4150779e60f ("random32: use real rng for
    non-deterministic randomness").  On my same arm64 dev board, at the time
    the fuzz tests are run, get_random_u8() is about 345x slower than
    prandom_u32_state(), or about 469x if lockdep is enabled.

    Lockdep makes a big difference, but much of the rest comes from the
    get_random_*() functions taking a *very* slow path when the CRNG is not
    yet initialized.  Since the crypto self-tests run early during boot,
    even having a hardware RNG driver enabled (CONFIG_CRYPTO_DEV_QCOM_RNG in
    my case) doesn't prevent this.  x86 systems don't have this issue, but
    they still see a significant regression if lockdep is enabled.

    Converting the "Fully random bytes" case in generate_random_bytes() to
    use get_random_bytes() helps significantly, improving the test time to
    about 27 seconds.  But that's still over 5x slower than before.

    This is all a bit silly, though, since the fuzz tests don't actually
    need cryptographically secure random numbers.  So let's just make them
    use a non-cryptographically-secure RNG as they did before.  The original
    prandom_u32() is gone now, so let's use prandom_u32_state() instead,
    with an explicitly managed state, like various other self-tests in the
    kernel source tree (rbtree_test.c, test_scanf.c, etc.) already do.  This
    also has the benefit that no locking is required anymore, so performance
    should be even better than the original version that used prandom_u32().

    Fixes: d4150779e60f ("random32: use real rng for non-deterministic randomness")
    Cc: stable@vger.kernel.org
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:29 +02:00
Ivan Vecera 2f9aed229d crypto/testmgr: use get_random_u32_inclusive() when possible
JIRA: https://issues.redhat.com/browse/RHEL-3646

Conflicts:
- only crypto/testmgr.c to be able to apply later follow-up
  f900fde28883 ("crypto: testmgr - fix RNG performance in fuzz tests")

commit e8a533cbeb79809206f8724e89961e0079508c3c
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Sun Oct 9 20:44:02 2022 -0600

    treewide: use get_random_u32_inclusive() when possible

    These cases were done with this Coccinelle:

    @@
    expression H;
    expression L;
    @@
    - (get_random_u32_below(H) + L)
    + get_random_u32_inclusive(L, H + L - 1)

    @@
    expression H;
    expression L;
    expression E;
    @@
      get_random_u32_inclusive(L,
      H
    - + E
    - - E
      )

    @@
    expression H;
    expression L;
    expression E;
    @@
      get_random_u32_inclusive(L,
      H
    - - E
    - + E
      )

    @@
    expression H;
    expression L;
    expression E;
    expression F;
    @@
      get_random_u32_inclusive(L,
      H
    - - E
      + F
    - + E
      )

    @@
    expression H;
    expression L;
    expression E;
    expression F;
    @@
      get_random_u32_inclusive(L,
      H
    - + E
      + F
    - - E
      )

    And then subsequently cleaned up by hand, with several automatic cases
    rejected if it didn't make sense contextually.

    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> # for infiniband
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:29 +02:00
Ivan Vecera cf6ddd8a3f crypto/testmgr: use get_random_u32_below() instead of deprecated function
JIRA: https://issues.redhat.com/browse/RHEL-3646

Conflicts:
- only crypto/testmgr.c to be able to apply later follow-up
  f900fde28883 ("crypto: testmgr - fix RNG performance in fuzz tests")

commit 8032bf1233a74627ce69b803608e650f3f35971c
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Sun Oct 9 20:44:02 2022 -0600

    treewide: use get_random_u32_below() instead of deprecated function

    This is a simple mechanical transformation done by:

    @@
    expression E;
    @@
    - prandom_u32_max
    + get_random_u32_below
      (E)

    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
    Reviewed-by: SeongJae Park <sj@kernel.org> # for damon
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> # for infiniband
    Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> # for arm
    Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:29 +02:00
Ivan Vecera a6814d519e crypto/testmgr: use get_random_{u8,u16}() when possible, part 1
JIRA: https://issues.redhat.com/browse/RHEL-3646

Conflicts:
- only crypto/testmgr.c to be able to apply later follow-up
  f900fde28883 ("crypto: testmgr - fix RNG performance in fuzz tests")

commit 7e3cf0843fe505491baa05e355e83e6997e089dd
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Wed Oct 5 17:23:53 2022 +0200

    treewide: use get_random_{u8,u16}() when possible, part 1

    Rather than truncate a 32-bit value to a 16-bit value or an 8-bit value,
    simply use the get_random_{u8,u16}() functions, which are faster than
    wasting the additional bytes from a 32-bit value. This was done
    mechanically with this coccinelle script:

    @@
    expression E;
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u16;
    typedef __be16;
    typedef __le16;
    typedef u8;
    @@
    (
    - (get_random_u32() & 0xffff)
    + get_random_u16()
    |
    - (get_random_u32() & 0xff)
    + get_random_u8()
    |
    - (get_random_u32() % 65536)
    + get_random_u16()
    |
    - (get_random_u32() % 256)
    + get_random_u8()
    |
    - (get_random_u32() >> 16)
    + get_random_u16()
    |
    - (get_random_u32() >> 24)
    + get_random_u8()
    |
    - (u16)get_random_u32()
    + get_random_u16()
    |
    - (u8)get_random_u32()
    + get_random_u8()
    |
    - (__be16)get_random_u32()
    + (__be16)get_random_u16()
    |
    - (__le16)get_random_u32()
    + (__le16)get_random_u16()
    |
    - prandom_u32_max(65536)
    + get_random_u16()
    |
    - prandom_u32_max(256)
    + get_random_u8()
    |
    - E->inet_id = get_random_u32()
    + E->inet_id = get_random_u16()
    )

    @@
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u16;
    identifier v;
    @@
    - u16 v = get_random_u32();
    + u16 v = get_random_u16();

    @@
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u8;
    identifier v;
    @@
    - u8 v = get_random_u32();
    + u8 v = get_random_u8();

    @@
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u16;
    u16 v;
    @@
    -  v = get_random_u32();
    +  v = get_random_u16();

    @@
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u8;
    u8 v;
    @@
    -  v = get_random_u32();
    +  v = get_random_u8();

    // Find a potential literal
    @literal_mask@
    expression LITERAL;
    type T;
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    position p;
    @@

            ((T)get_random_u32()@p & (LITERAL))

    // Examine limits
    @script:python add_one@
    literal << literal_mask.LITERAL;
    RESULT;
    @@

    value = None
    if literal.startswith('0x'):
            value = int(literal, 16)
    elif literal[0] in '123456789':
            value = int(literal, 10)
    if value is None:
            print("I don't know how to handle %s" % (literal))
            cocci.include_match(False)
    elif value < 256:
            coccinelle.RESULT = cocci.make_ident("get_random_u8")
    elif value < 65536:
            coccinelle.RESULT = cocci.make_ident("get_random_u16")
    else:
            print("Skipping large mask of %s" % (literal))
            cocci.include_match(False)

    // Replace the literal mask with the calculated result.
    @plus_one@
    expression literal_mask.LITERAL;
    position literal_mask.p;
    identifier add_one.RESULT;
    identifier FUNC;
    @@

    -       (FUNC()@p & (LITERAL))
    +       (RESULT() & LITERAL)

    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Yury Norov <yury.norov@gmail.com>
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Acked-by: Toke Høiland-Jørgensen <toke@toke.dk> # for sch_cake
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:29 +02:00
Ivan Vecera 929224d00b crypto/testmgr: use prandom_u32_max() when possible, part 1
JIRA: https://issues.redhat.com/browse/RHEL-3646

Conflicts:
- only crypto/testmgr.c to be able to apply later follow-up
  f900fde28883 ("crypto: testmgr - fix RNG performance in fuzz tests")

commit 81895a65ec63ee1daec3255dc1a06675d2fbe915
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Wed Oct 5 16:43:38 2022 +0200

    treewide: use prandom_u32_max() when possible, part 1

    Rather than incurring a division or requesting too many random bytes for
    the given range, use the prandom_u32_max() function, which only takes
    the minimum required bytes from the RNG and avoids divisions. This was
    done mechanically with this coccinelle script:

    @basic@
    expression E;
    type T;
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    typedef u64;
    @@
    (
    - ((T)get_random_u32() % (E))
    + prandom_u32_max(E)
    |
    - ((T)get_random_u32() & ((E) - 1))
    + prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2)
    |
    - ((u64)(E) * get_random_u32() >> 32)
    + prandom_u32_max(E)
    |
    - ((T)get_random_u32() & ~PAGE_MASK)
    + prandom_u32_max(PAGE_SIZE)
    )

    @multi_line@
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    identifier RAND;
    expression E;
    @@

    -       RAND = get_random_u32();
            ... when != RAND
    -       RAND %= (E);
    +       RAND = prandom_u32_max(E);

    // Find a potential literal
    @literal_mask@
    expression LITERAL;
    type T;
    identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
    position p;
    @@

            ((T)get_random_u32()@p & (LITERAL))

    // Add one to the literal.
    @script:python add_one@
    literal << literal_mask.LITERAL;
    RESULT;
    @@

    value = None
    if literal.startswith('0x'):
            value = int(literal, 16)
    elif literal[0] in '123456789':
            value = int(literal, 10)
    if value is None:
            print("I don't know how to handle %s" % (literal))
            cocci.include_match(False)
    elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1:
            print("Skipping 0x%x for cleanup elsewhere" % (value))
            cocci.include_match(False)
    elif value & (value + 1) != 0:
            print("Skipping 0x%x because it's not a power of two minus one" % (value))
            cocci.include_match(False)
    elif literal.startswith('0x'):
            coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1))
    else:
            coccinelle.RESULT = cocci.make_expr("%d" % (value + 1))

    // Replace the literal mask with the calculated result.
    @plus_one@
    expression literal_mask.LITERAL;
    position literal_mask.p;
    expression add_one.RESULT;
    identifier FUNC;
    @@

    -       (FUNC()@p & (LITERAL))
    +       prandom_u32_max(RESULT)

    @collapse_ret@
    type T;
    identifier VAR;
    expression E;
    @@

     {
    -       T VAR;
    -       VAR = (E);
    -       return VAR;
    +       return E;
     }

    @drop_var@
    type T;
    identifier VAR;
    @@

     {
    -       T VAR;
            ... when != VAR
     }

    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Yury Norov <yury.norov@gmail.com>
    Reviewed-by: KP Singh <kpsingh@kernel.org>
    Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 and sbitmap
    Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> # for drbd
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390
    Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
    Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:28 +02:00
Ivan Vecera 7016644d9c crypto: testmgr - test in-place en/decryption with two sglists
JIRA: https://issues.redhat.com/browse/RHEL-3646

commit f17f9e9069f20f4400ae0bb3ee830d34104ff8f7
Author: Eric Biggers <ebiggers@google.com>
Date:   Sat Mar 26 00:11:59 2022 -0700

    crypto: testmgr - test in-place en/decryption with two sglists

    As was established in the thread
    https://lore.kernel.org/linux-crypto/20220223080400.139367-1-gilad@benyossef.com/T/#u,
    many crypto API users doing in-place en/decryption don't use the same
    scatterlist pointers for the source and destination, but rather use
    separate scatterlists that point to the same memory.  This case isn't
    tested by the self-tests, resulting in bugs.

    This is the natural usage of the crypto API in some cases, so requiring
    API users to avoid this usage is not reasonable.

    Therefore, update the self-tests to start testing this case.

    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-09-13 18:51:28 +02:00
Coiby Xu 1b43c9e5ca crypto: testmgr - allow ecdsa-nist-p256 and -p384 in FIPS mode
Bugzilla: https://bugzilla.redhat.com/2055205

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit c27b2d2012e1826674255b9e45b61c172a267e1c
Author: Nicolai Stange <nstange@suse.de>
Date:   Thu Dec 29 22:17:10 2022 +0100

    crypto: testmgr - allow ecdsa-nist-p256 and -p384 in FIPS mode

    The kernel provides implementations of the NIST ECDSA signature
    verification primitives. For key sizes of 256 and 384 bits respectively
    they are approved and can be enabled in FIPS mode. Do so.

    Signed-off-by: Nicolai Stange <nstange@suse.de>
    Signed-off-by: Vladis Dronov <vdronov@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Coiby Xu <coxu@redhat.com>
2023-05-27 08:41:18 +08:00
Vladis Dronov 64846a28e3 crypto: testmgr - disallow certain DRBG hash functions in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152131
Upstream Status: merged into herbert/cryptodev-2.6.git

commit 1b4744e107e3d6eeda6473fefee5e2b904b85b8b
Author: Vladis Dronov <vdronov@redhat.com>
Date:   Tue Jan 17 18:20:06 2023 +0100

    crypto: testmgr - disallow certain DRBG hash functions in FIPS mode

    According to FIPS 140-3 IG, section D.R "Hash Functions Acceptable for
    Use in the SP 800-90A DRBGs", modules certified after May 16th, 2023
    must not support the use of: SHA-224, SHA-384, SHA512-224, SHA512-256,
    SHA3-224, SHA3-384. Disallow HMAC and HASH DRBGs using SHA-384 in FIPS
    mode.

    Signed-off-by: Vladis Dronov <vdronov@redhat.com>
    Reviewed-by: Stephan Müller <smueller@chronox.de>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2023-01-27 16:51:47 +01:00
Chris Leech 0a2e5b9090 crypto: testmgr - add known answer tests for ffdheXYZ(dh) templates
Add known answer tests for the ffdhe2048(dh), ffdhe3072(dh), ffdhe4096(dh),
ffdhe6144(dh) and ffdhe8192(dh) templates introduced with the previous
patch to the testmgr. All TVs have been generated with OpenSSL.

Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 60a273e9aecd8ee8a7d84f78f366795a67607829)
Signed-off-by: Chris Leech <cleech@redhat.com>
Bugzilla: http://bugzilla.redhat.com/2143836
2022-11-18 13:19:51 -08:00
Vladis Dronov 9240d3a6b9 crypto: ecdh - disallow plain "ecdh" usage in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2126683
Upstream Status: RHEL-only

We do not certify ECDH against FIPS 140-3 for the C9S/RHEL9 kernel.
As a consequence, this algorithm must not be marked with .fips_allowed = 1.

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2022-10-11 17:46:53 +02:00
Vladis Dronov 91dafb97b2 crypto: dh - disallow plain "dh" usage in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2126683
Upstream Status: merged into the linux.git

commit 32f07cc40c9bb41452dc9d6c514a2012d9682b39
Author: Nicolai Stange <nstange@suse.de>
Date:   Mon Feb 21 13:10:59 2022 +0100

    crypto: dh - disallow plain "dh" usage in FIPS mode

    SP800-56Arev3, sec. 5.5.2 ("Assurance of Domain-Parameter Validity")
    asserts that an implementation needs to verify domain paramtere validity,
    which boils down to either
    - the domain parameters corresponding to some known safe-prime group
      explicitly listed to be approved in the document or
    - for parameters conforming to a "FIPS 186-type parameter-size set",
      that the implementation needs to perform an explicit domain parameter
      verification, which would require access to the "seed" and "counter"
      values used in their generation.

    The latter is not easily feasible and moreover, SP800-56Arev3 states that
    safe-prime groups are preferred and that FIPS 186-type parameter sets
    should only be supported for backward compatibility, if it all.

    Mark "dh" as not fips_allowed in testmgr. Note that the safe-prime
    ffdheXYZ(dh) wrappers are not affected by this change: as these enforce
    some approved safe-prime group each, their usage is still allowed in FIPS
    mode.

    This change will effectively render the keyctl(KEYCTL_DH_COMPUTE) syscall
    unusable in FIPS mode, but it has been brought up that this might even be
    a good thing ([1]).

    [1] https://lore.kernel.org/r/20211217055227.GA20698@gondor.apana.org.au

    Signed-off-by: Nicolai Stange <nstange@suse.de>
    Reviewed-by: Hannes Reinecke <hare@suse.de>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2022-10-11 17:46:53 +02:00
Vladis Dronov 4133901107 crypto: testmgr - disallow plain cbcmac(aes) and ghash in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2107596
Upstream Status: RHEL only

cbcmac(aes) and ghash may be used only as a part of the ccm(aes) and
gcm(aes) construction in FIPS mode. Mark plain cbcmac(aes) and ghash
as non-FIPS-approved.

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2022-07-27 15:43:16 +02:00
Vladis Dronov daec71d96c crypto: api - allow algs only in specific constructions in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2107596
Upstream Status: merged into the linux.git

commit d6097b8d5d55f26cd2244e7e7f00a5a077772a91
Author: Nicolai Stange <nstange@suse.de>
Date:   Mon Feb 21 13:10:58 2022 +0100

    crypto: api - allow algs only in specific constructions in FIPS mode

    Currently we do not distinguish between algorithms that fail on
    the self-test vs. those which are disabled in FIPS mode (not allowed).
    Both are marked as having failed the self-test.

    Recently the need arose to allow the usage of certain algorithms only
    as arguments to specific template instantiations in FIPS mode. For
    example, standalone "dh" must be blocked, but e.g. "ffdhe2048(dh)" is
    allowed. Other potential use cases include "cbcmac(aes)", which must
    only be used with ccm(), or "ghash", which must be used only for
    gcm().

    This patch allows this scenario by adding a new flag FIPS_INTERNAL to
    indicate those algorithms that are not FIPS-allowed. They can then be
    used as template arguments only, i.e. when looked up via
    crypto_grab_spawn() to be more specific. The FIPS_INTERNAL bit gets
    propagated upwards recursively into the surrounding template
    instances, until the construction eventually matches an explicit
    testmgr entry with ->fips_allowed being set, if any.

    The behaviour to skip !->fips_allowed self-test executions in FIPS
    mode will be retained. Note that this effectively means that
    FIPS_INTERNAL algorithms are handled very similarly to the INTERNAL
    ones in this regard. It is expected that the FIPS_INTERNAL algorithms
    will receive sufficient testing when the larger constructions they're
    a part of, if any, get exercised by testmgr.

    Note that as a side-effect of this patch algorithms which are not
    FIPS-allowed will now return ENOENT instead of ELIBBAD. Hopefully
    this is not an issue as some people were relying on this already.

    Link: https://lore.kernel.org/r/YeEVSaMEVJb3cQkq@gondor.apana.org.au
    Originally-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Nicolai Stange <nstange@suse.de>
    Reviewed-by: Hannes Reinecke <hare@suse.de>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
2022-07-27 15:43:15 +02:00
Ming Lei 865ff228f3 crypto: add rocksoft 64b crc guard tag framework
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083917

commit f3813f4b287e480b1fcd62ca798d8556644b8278
Author: Keith Busch <kbusch@kernel.org>
Date:   Thu Mar 3 12:13:10 2022 -0800

    crypto: add rocksoft 64b crc guard tag framework

    Hardware specific features may be able to calculate a crc64, so provide
    a framework for drivers to register their implementation. If nothing is
    registered, fallback to the generic table lookup implementation. The
    implementation is modeled after the crct10dif equivalent.

    Signed-off-by: Keith Busch <kbusch@kernel.org>
    Link: https://lore.kernel.org/r/20220303201312.3255347-7-kbusch@kernel.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Ming Lei <ming.lei@redhat.com>
2022-06-22 08:57:57 +08:00
Herbert Xu 7758974cb5 crypto: hmac - add fips_skip support
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2033512

commit c9c28ed0ab611b6ee3bfab88eba334e272642433
Author: Stephan Müller <smueller@chronox.de>
Date:   Tue Feb 1 09:40:58 2022 +0100

    crypto: hmac - add fips_skip support
    
    By adding the support for the flag fips_skip, hash / HMAC test vectors
    may be marked to be not applicable in FIPS mode. Such vectors are
    silently skipped in FIPS mode.
    
    Signed-off-by: Stephan Mueller <smueller@chronox.de>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Herbert Xu <zxu@redhat.com>
2022-03-04 13:34:58 +12:00
Herbert Xu 117d1c1b4d crypto: des - disallow des3 in FIPS mode
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2033512

commit 330507fbc9d8c3bc4525ea2ae9c3774738bc0c80
Author: Stephan Müller <smueller@chronox.de>
Date:   Sun Nov 21 16:10:33 2021 +0100

    crypto: des - disallow des3 in FIPS mode
    
    On Dec 31 2023 NIST sunsets TDES for FIPS use. To prevent FIPS
    validations to be completed in the future to be affected by the TDES
    sunsetting, disallow TDES already now. Otherwise a FIPS validation would
    need to be "touched again" end 2023 to handle TDES accordingly.
    
    Signed-off-by: Stephan Mueller <smueller@chronox.de>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Herbert Xu <zxu@redhat.com>
2022-03-04 13:33:36 +12:00
Stephan Müller 8833272d87 crypto: drbg - self test for HMAC(SHA-512)
Considering that the HMAC(SHA-512) DRBG is the default DRBG now, a self
test is to be provided.

The test vector is obtained from a successful NIST ACVP test run.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-06-28 11:28:08 +08:00
Hui Tang 8e568fc2a7 crypto: ecdh - add test suite for NIST P384
Add test vector params for NIST P384, add test vector for
NIST P384 on vector of tests.

Vector param from:
https://datatracker.ietf.org/doc/html/rfc5903#section-3.1

Signed-off-by: Hui Tang <tanghui20@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-05-28 15:11:47 +08:00
Hui Tang 6889fc2104 crypto: ecdh - fix ecdh-nist-p192's entry in testmgr
Add a comment that p192 will fail to register in FIPS mode.

Fix ecdh-nist-p192's entry in testmgr by removing the ifdefs
and not setting fips_allowed.

Signed-off-by: Hui Tang <tanghui20@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-05-28 15:11:47 +08:00
Herbert Xu 3877869d13 Merge branch 'ecc'
This pulls in the NIST P384/256/192 x509 changes.
2021-03-26 19:55:55 +11:00
Saulo Alessandre c12d448ba9 crypto: ecdsa - Register NIST P384 and extend test suite
Register NIST P384 as an akcipher and extend the testmgr with
NIST P384-specific test vectors.

Summary of changes:

* crypto/ecdsa.c
  - add ecdsa_nist_p384_init_tfm
  - register and unregister P384 tfm

* crypto/testmgr.c
  - add test vector for P384 on vector of tests

* crypto/testmgr.h
  - add test vector params for P384(sha1, sha224, sha256, sha384
    and sha512)

Signed-off-by: Saulo Alessandre <saulo.alessandre@tse.jus.br>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-26 19:41:58 +11:00
Stefan Berger 4e6602916b crypto: ecdsa - Add support for ECDSA signature verification
Add support for parsing the parameters of a NIST P256 or NIST P192 key.
Enable signature verification using these keys. The new module is
enabled with CONFIG_ECDSA:
  Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.)
  is A NIST cryptographic standard algorithm. Only signature verification
  is implemented.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-26 19:41:58 +11:00
Meng Yu 6763f5ea2d crypto: ecdh - move curve_id of ECDH from the key to algorithm name
1. crypto and crypto/atmel-ecc:
   Move curve id of ECDH from the key into the algorithm name instead
   in crypto and atmel-ecc, so ECDH algorithm name change form 'ecdh'
   to 'ecdh-nist-pxxx', and we cannot use 'curve_id' in 'struct ecdh';
2. crypto/testmgr and net/bluetooth:
   Modify 'testmgr.c', 'testmgr.h' and 'net/bluetooth' to adapt
   the modification.

Signed-off-by: Meng Yu <yumeng18@huawei.com>
Reviewed-by: Zaibo Xu <xuzaibo@huawei.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-13 00:04:03 +11:00
Kai Ye e40ff6f3ea crypto: testmgr - delete some redundant code
Delete sg_data function, because sg_data function definition same as
sg_virt(), so need to delete it and use sg_virt() replace to sg_data().

Signed-off-by: Kai Ye <yekai13@huawei.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-03-07 15:13:18 +11:00
Ard Biesheuvel 784506a1df crypto: serpent - get rid of obsolete tnepres variant
It is not trivial to trace back why exactly the tnepres variant of
serpent was added ~17 years ago - Google searches come up mostly empty,
but it seems to be related with the 'kerneli' version, which was based
on an incorrect interpretation of the serpent spec.

In other words, nobody is likely to care anymore today, so let's get rid
of it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-02-10 17:55:56 +11:00
Ard Biesheuvel 663f63ee6d crypto: salsa20 - remove Salsa20 stream cipher algorithm
Salsa20 is not used anywhere in the kernel, is not suitable for disk
encryption, and widely considered to have been superseded by ChaCha20.
So let's remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by:  Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-29 16:07:04 +11:00
Ard Biesheuvel 87cd723f89 crypto: tgr192 - remove Tiger 128/160/192 hash algorithms
Tiger is never referenced anywhere in the kernel, and unlikely
to be depended upon by userspace via AF_ALG. So let's remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-29 16:07:04 +11:00
Ard Biesheuvel 93f6420292 crypto: rmd320 - remove RIPE-MD 320 hash algorithm
RIPE-MD 320 is never referenced anywhere in the kernel, and unlikely
to be depended upon by userspace via AF_ALG. So let's remove it

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-29 16:07:04 +11:00
Ard Biesheuvel c15d4167f0 crypto: rmd256 - remove RIPE-MD 256 hash algorithm
RIPE-MD 256 is never referenced anywhere in the kernel, and unlikely
to be depended upon by userspace via AF_ALG. So let's remove it

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-29 16:07:03 +11:00
Ard Biesheuvel b21b9a5e0a crypto: rmd128 - remove RIPE-MD 128 hash algorithm
RIPE-MD 128 is never referenced anywhere in the kernel, and unlikely
to be depended upon by userspace via AF_ALG. So let's remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-29 16:07:03 +11:00
Ard Biesheuvel 0eb76ba29d crypto: remove cipher routines from public crypto API
The cipher routines in the crypto API are mostly intended for templates
implementing skcipher modes generically in software, and shouldn't be
used outside of the crypto subsystem. So move the prototypes and all
related definitions to a new header file under include/crypto/internal.
Also, let's use the new module namespace feature to move the symbol
exports into a new namespace CRYPTO_INTERNAL.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-01-03 08:41:35 +11:00
Eric Biggers 09a5ef9644 crypto: testmgr - WARN on test failure
Currently, by default crypto self-test failures only result in a
pr_warn() message and an "unknown" status in /proc/crypto.  Both of
these are easy to miss.  There is also an option to panic the kernel
when a test fails, but that can't be the default behavior.

A crypto self-test failure always indicates a kernel bug, however, and
there's already a standard way to report (recoverable) kernel bugs --
the WARN() family of macros.  WARNs are noisier and harder to miss, and
existing test systems already know to look for them in dmesg or via
/proc/sys/kernel/tainted.

Therefore, call WARN() when an algorithm fails its self-tests.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-11-06 14:29:10 +11:00
Eric Biggers 6e5972fa4a crypto: testmgr - always print the actual skcipher driver name
When alg_test() is called from tcrypt.ko rather than from the algorithm
registration code, "driver" is actually the algorithm name, not the
driver name.  So it shouldn't be used in places where a driver name is
wanted, e.g. when reporting a test failure or when checking whether the
driver is the generic driver or not.

Fix this for the skcipher algorithm tests by getting the driver name
from the crypto_skcipher that actually got allocated.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-11-06 14:29:10 +11:00
Eric Biggers 2257f4712d crypto: testmgr - always print the actual AEAD driver name
When alg_test() is called from tcrypt.ko rather than from the algorithm
registration code, "driver" is actually the algorithm name, not the
driver name.  So it shouldn't be used in places where a driver name is
wanted, e.g. when reporting a test failure or when checking whether the
driver is the generic driver or not.

Fix this for the AEAD algorithm tests by getting the driver name from
the crypto_aead that actually got allocated.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-11-06 14:29:10 +11:00
Eric Biggers 79cafe9a8b crypto: testmgr - always print the actual hash driver name
When alg_test() is called from tcrypt.ko rather than from the algorithm
registration code, "driver" is actually the algorithm name, not the
driver name.  So it shouldn't be used in places where a driver name is
wanted, e.g. when reporting a test failure or when checking whether the
driver is the generic driver or not.

Fix this for the hash algorithm tests by getting the driver name from
the crypto_ahash or crypto_shash that actually got allocated.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-11-06 14:29:10 +11:00
Tianjia Zhang 8b805b97fc crypto: sm2 - add SM2 test vectors to testmgr
Add testmgr test vectors for SM2 algorithm. These vectors come
from `openssl pkeyutl -sign` and libgcrypt.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Tested-by: Xufeng Zhang <yunbo.xufeng@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-09-25 17:48:54 +10:00
Tianjia Zhang 2b40386774 crypto: testmgr - Fix potential memory leak in test_akcipher_one()
When the 'key' allocation fails, the 'req' will not be released,
which will cause memory leakage on this path. This patch adds a
'free_req' tag used to solve this problem, and two new err values
are added to reflect the real reason of the error.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-09-25 17:48:54 +10:00
Tianjia Zhang a1f62c217d crypto: testmgr - support test with different ciphertext per encryption
Some asymmetric algorithms will get different ciphertext after
each encryption, such as SM2, and let testmgr support the testing
of such algorithms.

In struct akcipher_testvec, set c and c_size to be empty, skip
the comparison of the ciphertext, and compare the decrypted
plaintext with m to achieve the test purpose.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Tested-by: Xufeng Zhang <yunbo.xufeng@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-09-25 17:48:54 +10:00
Herbert Xu 0c3dc787a6 crypto: algapi - Remove skbuff.h inclusion
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@gondor.apana.org.au>
2020-08-20 14:04:28 +10:00
Waiman Long 453431a549 mm, treewide: rename kzfree() to kfree_sensitive()
As said by Linus:

  A symmetric naming is only helpful if it implies symmetries in use.
  Otherwise it's actively misleading.

  In "kzalloc()", the z is meaningful and an important part of what the
  caller wants.

  In "kzfree()", the z is actively detrimental, because maybe in the
  future we really _might_ want to use that "memfill(0xdeadbeef)" or
  something. The "zero" part of the interface isn't even _relevant_.

The main reason that kzfree() exists is to clear sensitive information
that should not be leaked to other future users of the same memory
objects.

Rename kzfree() to kfree_sensitive() to follow the example of the recently
added kvfree_sensitive() and make the intention of the API more explicit.
In addition, memzero_explicit() is used to clear the memory to make sure
that it won't get optimized away by the compiler.

The renaming is done by using the command sequence:

  git grep -w --name-only kzfree |\
  xargs sed -i 's/kzfree/kfree_sensitive/'

followed by some editing of the kfree_sensitive() kerneldoc and adding
a kzfree backward compatibility macro in slab.h.

[akpm@linux-foundation.org: fs/crypto/inline_crypt.c needs linux/slab.h]
[akpm@linux-foundation.org: fix fs/crypto/inline_crypt.c some more]

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: David Howells <dhowells@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Joe Perches <joe@perches.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>
Link: http://lkml.kernel.org/r/20200616154311.12314-3-longman@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-07 11:33:22 -07:00
Linus Torvalds 72f35423e8 Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu:
 "API:
   - Fix out-of-sync IVs in self-test for IPsec AEAD algorithms

  Algorithms:
   - Use formally verified implementation of x86/curve25519

  Drivers:
   - Enhance hwrng support in caam

   - Use crypto_engine for skcipher/aead/rsa/hash in caam

   - Add Xilinx AES driver

   - Add uacce driver

   - Register zip engine to uacce in hisilicon

   - Add support for OCTEON TX CPT engine in marvell"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (162 commits)
  crypto: af_alg - bool type cosmetics
  crypto: arm[64]/poly1305 - add artifact to .gitignore files
  crypto: caam - limit single JD RNG output to maximum of 16 bytes
  crypto: caam - enable prediction resistance in HRWNG
  bus: fsl-mc: add api to retrieve mc version
  crypto: caam - invalidate entropy register during RNG initialization
  crypto: caam - check if RNG job failed
  crypto: caam - simplify RNG implementation
  crypto: caam - drop global context pointer and init_done
  crypto: caam - use struct hwrng's .init for initialization
  crypto: caam - allocate RNG instantiation descriptor with GFP_DMA
  crypto: ccree - remove duplicated include from cc_aead.c
  crypto: chelsio - remove set but not used variable 'adap'
  crypto: marvell - enable OcteonTX cpt options for build
  crypto: marvell - add the Virtual Function driver for CPT
  crypto: marvell - add support for OCTEON TX CPT engine
  crypto: marvell - create common Kconfig and Makefile for Marvell
  crypto: arm/neon - memzero_explicit aes-cbc key
  crypto: bcm - Use scnprintf() for avoiding potential buffer overflow
  crypto: atmel-i2c - Fix wakeup fail
  ...
2020-04-01 14:47:40 -07:00
Eric Biggers 8ff357a9d1 crypto: testmgr - do comparison tests before inauthentic input tests
Do test_aead_vs_generic_impl() before test_aead_inauthentic_inputs() so
that any differences with the generic driver are detected before getting
to the inauthentic input tests, which intentionally use only the driver
being tested (so that they run even if a generic driver is unavailable).

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-03-12 23:00:13 +11:00
Eric Biggers 6f3a06d959 crypto: testmgr - use consistent IV copies for AEADs that need it
rfc4543 was missing from the list of algorithms that may treat the end
of the AAD buffer specially.

Also, with rfc4106, rfc4309, rfc4543, and rfc7539esp, the end of the AAD
buffer is actually supposed to contain a second copy of the IV, and
we've concluded that if the IV copies don't match the behavior is
implementation-defined.  So, the fuzz tests can't easily test that case.

So, make the fuzz tests only use inputs where the two IV copies match.

Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Fixes: 40153b10d9 ("crypto: testmgr - fuzz AEADs against their generic implementation")
Cc: Stephan Mueller <smueller@chronox.de>
Originally-from: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-03-12 23:00:13 +11:00
Harald Freudenberger c7ff8573ad crypto/testmgr: enable selftests for paes-s390 ciphers
This patch enables the selftests for the s390 specific protected key
AES (PAES) cipher implementations:
  * cbc-paes-s390
  * ctr-paes-s390
  * ecb-paes-s390
  * xts-paes-s390
PAES is an AES cipher but with encrypted ('protected') key
material. However, the paes ciphers are able to derive an protected
key from clear key material with the help of the pkey kernel module.

So this patch now enables the generic AES tests for the paes
ciphers. Under the hood the setkey() functions rearrange the clear key
values as clear key token and so the pkey kernel module is able to
provide protected key blobs from the given clear key values. The
derived protected key blobs are then used within the paes cipers and
should produce the very same results as the generic AES implementation
with the clear key values.

The s390-paes cipher testlist entries are surrounded
by #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390) because they don't
make any sense on non s390 platforms or without the PAES
cipher implementation.

Link: http://lkml.kernel.org/r/20200213083946.zicarnnt3wizl5ty@gondor.apana.org.au
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2020-02-13 17:53:24 +01:00
Eric Biggers 49763fc6b1 crypto: testmgr - generate inauthentic AEAD test vectors
The whole point of using an AEAD over length-preserving encryption is
that the data is authenticated.  However currently the fuzz tests don't
test any inauthentic inputs to verify that the data is actually being
authenticated.  And only two algorithms ("rfc4543(gcm(aes))" and
"ccm(aes)") even have any inauthentic test vectors at all.

Therefore, update the AEAD fuzz tests to sometimes generate inauthentic
test vectors, either by generating a (ciphertext, AAD) pair without
using the key, or by mutating an authentic pair that was generated.

To avoid flakiness, only assume this works reliably if the auth tag is
at least 8 bytes.  Also account for the rfc4106, rfc4309, and rfc7539esp
algorithms intentionally ignoring the last 8 AAD bytes, and for some
algorithms doing extra checks that result in EINVAL rather than EBADMSG.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-12-11 16:37:01 +08:00
Eric Biggers 2ea915054c crypto: testmgr - create struct aead_extra_tests_ctx
In preparation for adding inauthentic input fuzz tests, which don't
require that a generic implementation of the algorithm be available,
refactor test_aead_vs_generic_impl() so that instead there's a
higher-level function test_aead_extra() which initializes a struct
aead_extra_tests_ctx and then calls test_aead_vs_generic_impl() with a
pointer to that struct.

As a bonus, this reduces stack usage.

Also switch from crypto_aead_alg(tfm)->maxauthsize to
crypto_aead_maxauthsize(), now that the latter is available in
<crypto/aead.h>.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-12-11 16:37:01 +08:00