07 Apr, 2020

1 commit

  • Fix the following warning:

    crypto/testmgr.c: In function ‘__test_tls’:
    crypto/testmgr.c:2648:12: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
    if (!ret == template[i].fail) {
    ^~

    Fixes: 8abdaaeda43 ("crypto: add support for TLS 1.0 record encryption")
    Signed-off-by: Iuliana Prodan
    Reviewed-by: Horia Geantă
    Reviewed-by: Valentin Ciocoi R?dulescu

    Iuliana Prodan
     

08 Mar, 2020

1 commit

  • Merge Linux stable release v5.4.24 into imx_5.4.y

    * tag 'v5.4.24': (3306 commits)
    Linux 5.4.24
    blktrace: Protect q->blk_trace with RCU
    kvm: nVMX: VMWRITE checks unsupported field before read-only field
    ...

    Signed-off-by: Jason Liu

    Conflicts:
    arch/arm/boot/dts/imx6sll-evk.dts
    arch/arm/boot/dts/imx7ulp.dtsi
    arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
    drivers/clk/imx/clk-composite-8m.c
    drivers/gpio/gpio-mxc.c
    drivers/irqchip/Kconfig
    drivers/mmc/host/sdhci-of-esdhc.c
    drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
    drivers/net/can/flexcan.c
    drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
    drivers/net/ethernet/mscc/ocelot.c
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
    drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
    drivers/net/phy/realtek.c
    drivers/pci/controller/mobiveil/pcie-mobiveil-host.c
    drivers/perf/fsl_imx8_ddr_perf.c
    drivers/tee/optee/shm_pool.c
    drivers/usb/cdns3/gadget.c
    kernel/sched/cpufreq.c
    net/core/xdp.c
    sound/soc/fsl/fsl_esai.c
    sound/soc/fsl/fsl_sai.c
    sound/soc/sof/core.c
    sound/soc/sof/imx/Kconfig
    sound/soc/sof/loader.c

    Jason Liu
     

15 Feb, 2020

1 commit

  • commit eb455dbd02cb1074b37872ffca30a81cb2a18eaa upstream.

    Currently if the comparison fuzz tests encounter an encryption error
    when generating an skcipher or AEAD test vector, they will still test
    the decryption side (passing it the uninitialized ciphertext buffer)
    and expect it to fail with the same error.

    This is sort of broken because it's not well-defined usage of the API to
    pass an uninitialized buffer, and furthermore in the AEAD case it's
    acceptable for the decryption error to be EBADMSG (meaning "inauthentic
    input") even if the encryption error was something else like EINVAL.

    Fix this for skcipher by explicitly initializing the ciphertext buffer
    on error, and for AEAD by skipping the decryption test on error.

    Reported-by: Pascal Van Leeuwen
    Fixes: d435e10e67be ("crypto: testmgr - fuzz skciphers against their generic implementation")
    Fixes: 40153b10d91c ("crypto: testmgr - fuzz AEADs against their generic implementation")
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

02 Dec, 2019

1 commit

  • This patch adds kernel support for encryption/decryption of TLS 1.0
    records using block ciphers. Implementation is similar to authenc in the
    sense that the base algorithms (AES, SHA1) are combined in a template to
    produce TLS encapsulation frames. The composite algorithm will be called
    "tls10(hmac(),cbc())". The cipher and hmac keys are
    wrapped in the same format used by authenc.c.

    Signed-off-by: Radu Alexe
    Signed-off-by: Cristian Stoica
    Signed-off-by: Horia Geantă

    Radu Alexe
     

30 Aug, 2019

1 commit


26 Jul, 2019

4 commits

  • Three variants of AEGIS were proposed for the CAESAR competition, and
    only one was selected for the final portfolio: AEGIS128.

    The other variants, AEGIS128L and AEGIS256, are not likely to ever turn
    up in networking protocols or other places where interoperability
    between Linux and other systems is a concern, nor are they likely to
    be subjected to further cryptanalysis. However, uninformed users may
    think that AEGIS128L (which is faster) is equally fit for use.

    So let's remove them now, before anyone starts using them and we are
    forced to support them forever.

    Note that there are no known flaws in the algorithms or in any of these
    implementations, but they have simply outlived their usefulness.

    Reviewed-by: Ondrej Mosnacek
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     
  • MORUS was not selected as a winner in the CAESAR competition, which
    is not surprising since it is considered to be cryptographically
    broken [0]. (Note that this is not an implementation defect, but a
    flaw in the underlying algorithm). Since it is unlikely to be in use
    currently, let's remove it before we're stuck with it.

    [0] https://eprint.iacr.org/2019/172.pdf

    Reviewed-by: Ondrej Mosnacek
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Ard Biesheuvel
     
  • Add self-tests for the lzo-rle algorithm.

    Signed-off-by: Hannah Pan
    Signed-off-by: Herbert Xu

    Hannah Pan
     
  • Crypto test failures in FIPS mode cause an immediate panic, but
    on some system the cryptographic boundary extends beyond just
    the Linux controlled domain.

    Add a simple atomic notification chain to allow interested parties
    to register to receive notification prior to us kicking the bucket.

    Signed-off-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu

    Gilad Ben-Yossef
     

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
     

27 Jun, 2019

2 commits

  • The largest stack object in this file is now the shash descriptor.
    Since there are many other stack variables, this can push it
    over the 1024 byte warning limit, in particular with clang and
    KASAN:

    crypto/testmgr.c:1693:12: error: stack frame size of 1312 bytes in function '__alg_test_hash' [-Werror,-Wframe-larger-than=]

    Make test_hash_vs_generic_impl() do the same thing as the
    corresponding eaed and skcipher functions by allocating the
    descriptor dynamically. We can still do better than this,
    but it brings us well below the 1024 byte limit.

    Suggested-by: Eric Biggers
    Fixes: 9a8a6b3f0950 ("crypto: testmgr - fuzz hashes against their generic implementation")
    Signed-off-by: Arnd Bergmann
    Reviewed-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Arnd Bergmann
     
  • On arm32, we get warnings about high stack usage in some of the functions:

    crypto/testmgr.c:2269:12: error: stack frame size of 1032 bytes in function 'alg_test_aead' [-Werror,-Wframe-larger-than=]
    static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
    ^
    crypto/testmgr.c:1693:12: error: stack frame size of 1312 bytes in function '__alg_test_hash' [-Werror,-Wframe-larger-than=]
    static int __alg_test_hash(const struct hash_testvec *vecs,
    ^

    On of the larger objects on the stack here is struct testvec_config, so
    change that to dynamic allocation.

    Fixes: 40153b10d91c ("crypto: testmgr - fuzz AEADs against their generic implementation")
    Fixes: d435e10e67be ("crypto: testmgr - fuzz skciphers against their generic implementation")
    Fixes: 9a8a6b3f0950 ("crypto: testmgr - fuzz hashes against their generic implementation")
    Signed-off-by: Arnd Bergmann
    Reviewed-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Arnd Bergmann
     

20 Jun, 2019

1 commit

  • There are no remaining users of the cipher implementation, and there
    are no meaningful ways in which the arc4 cipher can be combined with
    templates other than ECB (and the way we do provide that combination
    is highly dubious to begin with).

    So let's drop the arc4 cipher altogether, and only keep the ecb(arc4)
    skcipher, which is used in various places in the kernel.

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

    Ard Biesheuvel
     

13 Jun, 2019

1 commit

  • Call cond_resched() after each fuzz test iteration. This avoids stall
    warnings if fuzz_iterations is set very high for testing purposes.

    While we're at it, also call cond_resched() after finishing testing each
    test vector.

    Signed-off-by: Eric Biggers
    Acked-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Eric Biggers
     

06 Jun, 2019

2 commits

  • xxhash is currently implemented as a self-contained module in /lib.
    This patch enables that module to be used as part of the generic kernel
    crypto framework. It adds a simple wrapper to the 64bit version.

    I've also added test vectors (with help from Nick Terrell). The upstream
    xxhash code is tested by running hashing operation on random 222 byte
    data with seed values of 0 and a prime number. The upstream test
    suite can be found at https://github.com/Cyan4973/xxHash/blob/cf46e0c/xxhsum.c#L664

    Essentially hashing is run on data of length 0,1,14,222 with the
    aforementioned seed values 0 and prime 2654435761. The particular random
    222 byte string was provided to me by Nick Terrell by reading
    /dev/random and the checksums were calculated by the upstream xxsum
    utility with the following bash script:

    dd if=/dev/random of=TEST_VECTOR bs=1 count=222

    for a in 0 1; do
    for l in 0 1 14 222; do
    for s in 0 2654435761; do
    echo algo $a length $l seed $s;
    head -c $l TEST_VECTOR | ~/projects/kernel/xxHash/xxhsum -H$a -s$s
    done
    done
    done

    This produces output as follows:

    algo 0 length 0 seed 0
    02cc5d05 stdin
    algo 0 length 0 seed 2654435761
    02cc5d05 stdin
    algo 0 length 1 seed 0
    25201171 stdin
    algo 0 length 1 seed 2654435761
    25201171 stdin
    algo 0 length 14 seed 0
    c1d95975 stdin
    algo 0 length 14 seed 2654435761
    c1d95975 stdin
    algo 0 length 222 seed 0
    b38662a6 stdin
    algo 0 length 222 seed 2654435761
    b38662a6 stdin
    algo 1 length 0 seed 0
    ef46db3751d8e999 stdin
    algo 1 length 0 seed 2654435761
    ac75fda2929b17ef stdin
    algo 1 length 1 seed 0
    27c3f04c2881203a stdin
    algo 1 length 1 seed 2654435761
    4a15ed26415dfe4d stdin
    algo 1 length 14 seed 0
    3d33dc700231dfad stdin
    algo 1 length 14 seed 2654435761
    ea5f7ddef9a64f80 stdin
    algo 1 length 222 seed 0
    5f3d3c08ec2bef34 stdin
    algo 1 length 222 seed 2654435761
    6a9df59664c7ed62 stdin

    algo 1 is xx64 variant, algo 0 is the 32 bit variant which is currently
    not hooked up.

    Signed-off-by: Nikolay Borisov
    Reviewed-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Nikolay Borisov
     
  • For hash algorithms implemented using the "shash" algorithm type, test
    both the ahash and shash APIs, not just the ahash API.

    Testing the ahash API already tests the shash API indirectly, which is
    normally good enough. However, there have been corner cases where there
    have been shash bugs that don't get exposed through the ahash API. So,
    update testmgr to test the shash API too.

    This would have detected the arm64 SHA-1 and SHA-2 bugs for which fixes
    were just sent out (https://patchwork.kernel.org/patch/10964843/ and
    https://patchwork.kernel.org/patch/10965089/):

    alg: shash: sha1-ce test failed (wrong result) on test vector 0, cfg="init+finup aligned buffer"
    alg: shash: sha224-ce test failed (wrong result) on test vector 0, cfg="init+finup aligned buffer"
    alg: shash: sha256-ce test failed (wrong result) on test vector 0, cfg="init+finup aligned buffer"

    This also would have detected the bugs fixed by commit 307508d10729
    ("crypto: crct10dif-generic - fix use via crypto_shash_digest()") and
    commit dec3d0b1071a
    ("crypto: x86/crct10dif-pcl - fix use via crypto_shash_digest()").

    Signed-off-by: Eric Biggers
    Acked-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Eric Biggers
     

31 May, 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 either version 2 of the license or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

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

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

    Thomas Gleixner
     

25 Apr, 2019

2 commits

  • Mark sm4 and missing aes using protected keys which are indetical to
    same algs with no HW protected keys as tested.

    Signed-off-by: Gilad Ben-Yossef
    Signed-off-by: Herbert Xu

    Gilad Ben-Yossef
     
  • 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

9 commits

  • When the extra crypto self-tests are enabled, test each AEAD algorithm
    against its generic implementation when one is available. This
    involves: checking the algorithm properties for consistency, then
    randomly generating test vectors using the generic implementation and
    running them against the implementation under test. Both good and bad
    inputs are tested.

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

    Eric Biggers
     
  • When the extra crypto self-tests are enabled, test each skcipher
    algorithm against its generic implementation when one is available.
    This involves: checking the algorithm properties for consistency, then
    randomly generating test vectors using the generic implementation and
    running them against the implementation under test. Both good and bad
    inputs are tested.

    This has already detected a bug in the skcipher_walk API, a bug in the
    LRW template, and an inconsistency in the cts implementations.

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

    Eric Biggers
     
  • When the extra crypto self-tests are enabled, test each hash algorithm
    against its generic implementation when one is available. This
    involves: checking the algorithm properties for consistency, then
    randomly generating test vectors using the generic implementation and
    running them against the implementation under test. Both good and bad
    inputs are tested.

    This has already detected a bug in the x86 implementation of poly1305,
    bugs in crct10dif, and an inconsistency in cbcmac.

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

    Eric Biggers
     
  • Add some helper functions in preparation for fuzz testing algorithms
    against their generic implementation.

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

    Eric Biggers
     
  • In preparation for fuzz testing algorithms against their generic
    implementation, make error messages in testmgr identify test vectors by
    name rather than index. Built-in test vectors are simply "named" by
    their index in testmgr.h, as before. But (in later patches) generated
    test vectors will be given more descriptive names to help developers
    debug problems detected with them.

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

    Eric Biggers
     
  • Update testmgr to support testing for specific errors from setkey() and
    digest() for hashes; setkey() and encrypt()/decrypt() for skciphers and
    ciphers; and setkey(), setauthsize(), and encrypt()/decrypt() for AEADs.
    This is useful because algorithms usually restrict the lengths or format
    of the message, key, and/or authentication tag in some way. And bad
    inputs should be tested too, not just good inputs.

    As part of this change, remove the ambiguously-named 'fail' flag and
    replace it with 'setkey_error = -EINVAL' for the only test vector that
    used it -- the DES weak key test vector. Note that this tightens the
    test to require -EINVAL rather than any error code, but AFAICS this
    won't cause any test failure.

    Other than that, these new fields aren't set on any test vectors yet.
    Later patches will do so.

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

    Eric Biggers
     
  • Add testmgr test vectors for EC-RDSA algorithm for every of five
    supported parameters (curves). Because there are no officially published
    test vectors for the curves, the vectors are generated by gost-engine.

    Signed-off-by: Vitaly Chikunov
    Signed-off-by: Herbert Xu

    Vitaly Chikunov
     
  • Some public key algorithms (like EC-DSA) keep in parameters field
    important data such as digest and curve OIDs (possibly more for
    different EC-DSA variants). Thus, just setting a public key (as
    for RSA) is not enough.

    Append parameters into the key stream for akcipher_set_{pub,priv}_key.
    Appended data is: (u32) algo OID, (u32) parameters length, parameters
    data.

    This does not affect current akcipher API nor RSA ciphers (they could
    ignore it). Idea of appending parameters to the key stream is by Herbert
    Xu.

    Cc: David Howells
    Cc: Denis Kenzior
    Cc: keyrings@vger.kernel.org
    Signed-off-by: Vitaly Chikunov
    Reviewed-by: Denis Kenzior
    Signed-off-by: Herbert Xu

    Vitaly Chikunov
     
  • Previous akcipher .verify() just `decrypts' (using RSA encrypt which is
    using public key) signature to uncover message hash, which was then
    compared in upper level public_key_verify_signature() with the expected
    hash value, which itself was never passed into verify().

    This approach was incompatible with EC-DSA family of algorithms,
    because, to verify a signature EC-DSA algorithm also needs a hash value
    as input; then it's used (together with a signature divided into halves
    `r||s') to produce a witness value, which is then compared with `r' to
    determine if the signature is correct. Thus, for EC-DSA, nor
    requirements of .verify() itself, nor its output expectations in
    public_key_verify_signature() wasn't sufficient.

    Make improved .verify() call which gets hash value as input and produce
    complete signature check without any output besides status.

    Now for the top level verification only crypto_akcipher_verify() needs
    to be called and its return value inspected.

    Make sure that `digest' is in kmalloc'd memory (in place of `output`) in
    {public,tpm}_key_verify_signature() as insisted by Herbert Xu, and will
    be changed in the following commit.

    Cc: David Howells
    Cc: keyrings@vger.kernel.org
    Signed-off-by: Vitaly Chikunov
    Reviewed-by: Denis Kenzior
    Signed-off-by: Herbert Xu

    Vitaly Chikunov
     

08 Apr, 2019

1 commit

  • Add a module parameter cryptomgr.panic_on_fail which causes the kernel
    to panic if any crypto self-tests fail.

    Use cases:

    - More easily detect crypto self-test failures by boot testing,
    e.g. on KernelCI.
    - Get a bug report if syzkaller manages to use the template system to
    instantiate an algorithm that fails its self-tests.

    The command-line option "fips=1" already does this, but it also makes
    other changes not wanted for general testing, such as disabling
    "unapproved" algorithms. panic_on_fail just does what it says.

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

    Eric Biggers
     

22 Mar, 2019

3 commits

  • All crypto API algorithms are supposed to support the case where they
    are called in a context where SIMD instructions are unusable, e.g. IRQ
    context on some architectures. However, this isn't tested for by the
    self-tests, causing bugs to go undetected.

    Now that all algorithms have been converted to use crypto_simd_usable(),
    update the self-tests to test the no-SIMD case. First, a bool
    testvec_config::nosimd is added. When set, the crypto operation is
    executed with preemption disabled and with crypto_simd_usable() mocked
    out to return false on the current CPU.

    A bool test_sg_division::nosimd is also added. For hash algorithms it's
    honored by the corresponding ->update(). By setting just a subset of
    these bools, the case where some ->update()s are done in SIMD context
    and some are done in no-SIMD context is also tested.

    These bools are then randomly set by generate_random_testvec_config().

    For now, all no-SIMD testing is limited to the extra crypto self-tests,
    because it might be a bit too invasive for the regular self-tests.
    But this could be changed later.

    This has already found bugs in the arm64 AES-GCM and ChaCha algorithms.
    This would have found some past bugs as well.

    Signed-off-by: Eric Biggers
    Acked-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Eric Biggers
     
  • So that the no-SIMD fallback code can be tested by the crypto
    self-tests, add a macro crypto_simd_usable() which wraps may_use_simd(),
    but also returns false if the crypto self-tests have set a per-CPU bool
    to disable SIMD in crypto code on the current CPU.

    Signed-off-by: Eric Biggers
    Reviewed-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Eric Biggers
     
  • Now that all AEAD algorithms (that I have the hardware to test, at
    least) have been fixed to not modify the user-provided aead_request,
    remove the workaround from testmgr that reset aead_request::tfm after
    each AEAD encryption/decryption.

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

    Eric Biggers
     

22 Feb, 2019

1 commit

  • Allow skcipher test vectors to declare the value the IV buffer should be
    updated to at the end of the encryption or decryption operation.

    (This check actually used to be supported in testmgr, but it was never
    used and therefore got removed except for the AES-Keywrap special case.
    But it will be used by CBC and CTR now, so re-add it.)

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

    Eric Biggers
     

08 Feb, 2019

7 commits

  • Check that algorithms do not change the aead_request structure, as users
    may rely on submitting the request again (e.g. after copying new data
    into the same source buffer) without reinitializing everything.

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

    Eric Biggers
     
  • Check that algorithms do not change the skcipher_request structure, as
    users may rely on submitting the request again (e.g. after copying new
    data into the same source buffer) without reinitializing everything.

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

    Eric Biggers
     
  • Convert alg_test_hash() to use the new test framework, adding a list of
    testvec_configs to test by default. When the extra self-tests are
    enabled, randomly generated testvec_configs are tested as well.

    This improves hash test coverage mainly because now all algorithms have
    a variety of data layouts tested, whereas before each algorithm was
    responsible for declaring its own chunked test cases which were often
    missing or provided poor test coverage. The new code also tests both
    the MAY_SLEEP and !MAY_SLEEP cases and buffers that cross pages.

    This already found bugs in the hash walk code and in the arm32 and arm64
    implementations of crct10dif.

    I removed the hash chunked test vectors that were the same as
    non-chunked ones, but left the ones that were unique.

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

    Eric Biggers
     
  • Convert alg_test_aead() to use the new test framework, using the same
    list of testvec_configs that skcipher testing uses.

    This significantly improves AEAD test coverage mainly because previously
    there was only very limited test coverage of the possible data layouts.
    Now the data layouts to test are listed in one place for all algorithms
    and optionally are also randomly generated. In fact, only one AEAD
    algorithm (AES-GCM) even had a chunked test case before.

    This already found bugs in all the AEGIS and MORUS implementations, the
    x86 AES-GCM implementation, and the arm64 AES-CCM implementation.

    I removed the AEAD chunked test vectors that were the same as
    non-chunked ones, but left the ones that were unique.

    Note: the rewritten test code allocates an aead_request just once per
    algorithm rather than once per encryption/decryption, but some AEAD
    algorithms incorrectly change the tfm pointer in the request. It's
    nontrivial to fix these, so to move forward I'm temporarily working
    around it by resetting the tfm pointer. But they'll need to be fixed.

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

    Eric Biggers
     
  • Convert alg_test_skcipher() to use the new test framework, adding a list
    of testvec_configs to test by default. When the extra self-tests are
    enabled, randomly generated testvec_configs are tested as well.

    This improves skcipher test coverage mainly because now all algorithms
    have a variety of data layouts tested, whereas before each algorithm was
    responsible for declaring its own chunked test cases which were often
    missing or provided poor test coverage. The new code also tests both
    the MAY_SLEEP and !MAY_SLEEP cases, different IV alignments, and buffers
    that cross pages.

    This has already found a bug in the arm64 ctr-aes-neonbs algorithm.
    It would have easily found many past bugs.

    I removed the skcipher chunked test vectors that were the same as
    non-chunked ones, but left the ones that were unique.

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

    Eric Biggers
     
  • Add functions that generate a random testvec_config, in preparation for
    using it for randomized fuzz tests.

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

    Eric Biggers
     
  • To achieve more comprehensive crypto test coverage, I'd like to add fuzz
    tests that use random data layouts and request flags.

    To be most effective these tests should be part of testmgr, so they
    automatically run on every algorithm registered with the crypto API.
    However, they will take much longer to run than the current tests and
    therefore will only really be intended to be run by developers, whereas
    the current tests have a wider audience.

    Therefore, add a new kconfig option CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
    that can be set by developers to enable these extra, expensive tests.

    Similar to the regular tests, also add a module parameter
    cryptomgr.noextratests to support disabling the tests.

    Finally, another module parameter cryptomgr.fuzz_iterations is added to
    control how many iterations the fuzz tests do. Note: for now setting
    this to 0 will be equivalent to cryptomgr.noextratests=1. But I opted
    for separate parameters to provide more flexibility to add other types
    of tests under the "extra tests" category in the future.

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

    Eric Biggers