Skip to content

Fix and simplify the NIST DRBG implementation

Eric Biggers linux-crypto lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest38 patches 13 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/38crypto: drbg - Fix returning success on failure in CTR_DRBGcrypto/drbg.c+1 -10 replies
2/38crypto: drbg - Fix misaligned writes in CTR_DRBG and HASH_DRBGcrypto/df_sp80090a.c crypto/drbg.c include/crypto/internal/drbg.h+6 -220 replies
3/38crypto: drbg - Fix ineffective sanity checkcrypto/drbg.c+4 -50 replies
4/38crypto: drbg - Fix drbg_max_addtl() on 64-bit kernelsinclude/crypto/drbg.h+7 -110 replies
5/38crypto: drbg - Fix the fips_enabled priority boostcrypto/drbg.c+1 -10 replies
6/38crypto: drbg - Remove always-enabled symbol CRYPTO_DRBG_HMACcrypto/Kconfig crypto/drbg.c+3 -220 replies
7/38crypto: drbg - Remove broken commented-out codecrypto/drbg.c+0 -290 replies
8/38crypto: drbg - Remove unhelpful helper functionscrypto/drbg.c crypto/testmgr.c include/crypto/drbg.h+15 -1100 replies
9/38crypto: drbg - Remove obsolete FIPS 140-2 continuous testcrypto/drbg.c include/crypto/drbg.h+2 -780 replies
10/38crypto: drbg - Fold include/crypto/drbg.h into crypto/drbg.ccrypto/drbg.c crypto/testmgr.c include/crypto/drbg.h +1 more+132 -1850 replies
11/38crypto: drbg - Remove import of crypto_cipher functionscrypto/drbg.c+0 -20 replies
12/38crypto: drbg - Remove support for CTR_DRBGarch/m68k/configs/amiga_defconfig arch/m68k/configs/apollo_defconfig arch/m68k/configs/atari_defconfig +17 more+9 -6386 replies
13/38crypto: drbg - Remove support for HASH_DRBGDocumentation/crypto/api-samples.rst Documentation/crypto/userspace-if.rst arch/m68k/configs/amiga_defconfig +18 more+8 -6951 reply
14/38crypto: drbg - Flatten the DRBG menucrypto/Kconfig+5 -120 replies
15/38crypto: testmgr - Add test for drbg_pr_hmac_sha512crypto/testmgr.c crypto/testmgr.h+203 -12 replies
16/38crypto: testmgr - Update test for drbg_nopr_hmac_sha512crypto/testmgr.c crypto/testmgr.h+215 -470 replies
17/38crypto: drbg - Remove support for HMAC-SHA256 and HMAC-SHA384crypto/drbg.c crypto/testmgr.c crypto/testmgr.h+2 -3270 replies
18/38crypto: drbg - Simplify algorithm registrationcrypto/drbg.c+35 -650 replies
19/38crypto: drbg - De-virtualize drbg_state_opscrypto/drbg.c+6 -440 replies
20/38crypto: drbg - Move fixed values into constantscrypto/drbg.c+61 -1221 reply
21/38crypto: drbg - Embed V and C into struct drbg_statecrypto/drbg.c+4 -260 replies
22/38crypto: drbg - Use HMAC-SHA512 library APIcrypto/Kconfig crypto/drbg.c+41 -1750 replies
23/38crypto: drbg - Remove drbg_corecrypto/drbg.c+13 -860 replies
24/38crypto: drbg - Install separate seed functions for pr and noprcrypto/drbg.c+16 -90 replies
25/38crypto: drbg - Move module aliases to end of filecrypto/drbg.c+2 -30 replies
26/38crypto: drbg - Consolidate "instantiate" logic and remove drbg_state::Ccrypto/drbg.c+15 -230 replies
27/38crypto: drbg - Eliminate use of 'drbg_string' and listscrypto/df_sp80090a.c crypto/drbg.c drivers/crypto/xilinx/xilinx-trng.c +2 more+94 -1510 replies
28/38crypto: drbg - Simplify drbg_generate_long() and fold into callercrypto/drbg.c+17 -310 replies
29/38crypto: drbg - Put rng_alg methods in logical ordercrypto/drbg.c+36 -460 replies
30/38crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed()crypto/drbg.c+43 -640 replies
31/38crypto: drbg - Separate "reseed" case in drbg_kcapi_seed()crypto/drbg.c+16 -220 replies
32/38crypto: drbg - Fold drbg_prepare_hrng() into drbg_kcapi_seed()crypto/drbg.c+12 -220 replies
33/38crypto: drbg - Simplify "uninstantiate" logiccrypto/drbg.c+13 -440 replies
34/38crypto: drbg - Include get_random_bytes() output in additional inputcrypto/drbg.c+25 -40 replies
35/38crypto: drbg - Change DRBG_MAX_REQUESTS to 4096crypto/drbg.c+1 -10 replies
36/38crypto: drbg - Remove redundant reseeding based on random.c statecrypto/drbg.c+9 -982 replies
37/38crypto: drbg - Clean up generation codecrypto/drbg.c+19 -340 replies
38/38crypto: drbg - Clean up loop in drbg_hmac_update()crypto/drbg.c+2 -120 replies

Reviews trailers per patch

2 of 38 patches have a Reviewed-by or Acked-by.

PatchGeert Uytterhoeven
1/38
2/38
3/38
4/38
5/38
6/38
7/38
8/38
9/38
10/38
11/38
12/38A-b
13/38A-b
14/38
15/38
16/38
17/38
18/38
19/38
20/38
21/38
22/38
23/38
24/38
25/38
26/38
27/38
28/38
29/38
30/38
31/38
32/38
33/38
34/38
35/38
36/38
37/38
38/38

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/38] Fix and simplify the NIST DRBG implementation

This series is intended to be taken through the cryptodev tree. It can also be retrieved from:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git drbg-v1

This series fixes and greatly simplifies crypto/drbg.c, i.e. the kernel's implementation of NIST SP800-90A. This code isn't normally used, but it's sometimes used by people doing FIPS 140-3 certifications.

Note: this series is *not* meant to encourage using this code over random.c. In fact, my recent commit 65b3c2f627851639 made "normal" systems stop using this code. It's just that the reality is that this is in the kernel tree, it's been there for many years, and people are using it to get FIPS 140-3 certifications. As long as that's the case, it might as well be fixed up and simplified. Another reason to simplify this as much as possible is that for historical reasons it's accessible to unprivileged users via AF_ALG (even though it shouldn't be). So I do think this is a clear step forwards, regardless of level of enthusiasm for FIPS, especially considering the massively negative diffstat.

Patches 1-5 begin with some bug fixes. Fixes for CTR_DRBG and HASH_DRBG are included, despite that code being removed later in the series, so that they can be backported (though that is likely unused code anyway).

Patches 6-11 do some initial cleanups.

Patches 12-17 clean up the museum of DRBG variants to just support the HMAC-SHA512 DRBG only, dropping support for the others. This is already the default variant, it makes sense that it's the default, and it's probably the only one actually being used on current kernels. In any case, supporting more than one is pretty pointless. See the patches for more details about why it makes sense to keep using this one.

Patches 18-33 contain many more cleanups, including switching from the crypto_shash API to the crypto library.

Patch 34 is a significant one: it starts adding 32 bytes from get_random_bytes() to every additional input string. This is to work around the forward secrecy bug described in Woodage & Shumow (2018)
(https://eprint.iacr.org/2018/349.pdf), and to ensure that random.c reseeds are actually reflected in drbg.c. Of course, for FIPS 140-3 this is irrelevant, but this is the right thing to do in practice, and it should make drbg.c quite a bit more robust in practice. (This isn't particularly novel, either; BoringSSL does essentially this same thing.)

Patches 35-38 are some further cleanups, including some tweaks to when the formal reseeding happens.

Note: while the primary goal of this series is to fix and simplify this code, this series is also intended to preserve the FIPS 140-3 "certifiable" property of crypto/drbg.c. I.e. after this series, it should still be possible to get a FIPS 140-3 certification that covers it. In fact it should become quite a bit easier, since there will be only one DRBG variant to worry about and the code will be much more straightforward. If there's anything I missed, let me know.

Eric Biggers (38):
crypto: drbg - Fix returning success on failure in CTR_DRBG
crypto: drbg - Fix misaligned writes in CTR_DRBG and HASH_DRBG
crypto: drbg - Fix ineffective sanity check
crypto: drbg - Fix drbg_max_addtl() on 64-bit kernels
crypto: drbg - Fix the fips_enabled priority boost
crypto: drbg - Remove always-enabled symbol CRYPTO_DRBG_HMAC
crypto: drbg - Remove broken commented-out code
crypto: drbg - Remove unhelpful helper functions
crypto: drbg - Remove obsolete FIPS 140-2 continuous test
crypto: drbg - Fold include/crypto/drbg.h into crypto/drbg.c
crypto: drbg - Remove import of crypto_cipher functions
crypto: drbg - Remove support for CTR_DRBG
crypto: drbg - Remove support for HASH_DRBG
crypto: drbg - Flatten the DRBG menu
crypto: testmgr - Add test for drbg_pr_hmac_sha512
crypto: testmgr - Update test for drbg_nopr_hmac_sha512
crypto: drbg - Remove support for HMAC-SHA256 and HMAC-SHA384
crypto: drbg - Simplify algorithm registration
crypto: drbg - De-virtualize drbg_state_ops
crypto: drbg - Move fixed values into constants
crypto: drbg - Embed V and C into struct drbg_state
crypto: drbg - Use HMAC-SHA512 library API
crypto: drbg - Remove drbg_core
crypto: drbg - Install separate seed functions for pr and nopr
crypto: drbg - Move module aliases to end of file
crypto: drbg - Consolidate "instantiate" logic and remove
drbg_state::C
crypto: drbg - Eliminate use of 'drbg_string' and lists
crypto: drbg - Simplify drbg_generate_long() and fold into caller
crypto: drbg - Put rng_alg methods in logical order
crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed()
crypto: drbg - Separate "reseed" case in drbg_kcapi_seed()
crypto: drbg - Fold drbg_prepare_hrng() into drbg_kcapi_seed()
crypto: drbg - Simplify "uninstantiate" logic
crypto: drbg - Include get_random_bytes() output in additional input
crypto: drbg - Change DRBG_MAX_REQUESTS to 4096
crypto: drbg - Remove redundant reseeding based on random.c state
crypto: drbg - Clean up generation code
crypto: drbg - Clean up loop in drbg_hmac_update()

 Documentation/crypto/api-samples.rst          |    2 +-
 Documentation/crypto/userspace-if.rst         |    2 +-
 arch/m68k/configs/amiga_defconfig             |    2 -
 arch/m68k/configs/apollo_defconfig            |    2 -
 arch/m68k/configs/atari_defconfig             |    2 -
 arch/m68k/configs/bvme6000_defconfig          |    2 -
 arch/m68k/configs/hp300_defconfig             |    2 -
 arch/m68k/configs/mac_defconfig               |    2 -
 arch/m68k/configs/multi_defconfig             |    2 -
 arch/m68k/configs/mvme147_defconfig           |    2 -
 arch/m68k/configs/mvme16x_defconfig           |    2 -
 arch/m68k/configs/q40_defconfig               |    2 -
 arch/m68k/configs/sun3_defconfig              |    2 -
 arch/m68k/configs/sun3x_defconfig             |    2 -
 arch/mips/configs/decstation_64_defconfig     |    2 -
 arch/mips/configs/decstation_defconfig        |    2 -
 arch/mips/configs/decstation_r4k_defconfig    |    2 -
 crypto/Kconfig                                |   40 +-
 crypto/df_sp80090a.c                          |    8 +-
 crypto/drbg.c                                 | 1800 +++--------------
 crypto/testmgr.c                              |  143 +-
 crypto/testmgr.h                              | 1262 ++++--------
 drivers/crypto/xilinx/xilinx-trng.c           |    1 -
 include/crypto/df_sp80090a.h                  |   25 +
 include/crypto/drbg.h                         |  263 ---
 include/crypto/internal/drbg.h                |   54 -
 .../crypto/chacha20-s390/test-cipher.c        |    1 -
 27 files changed, 728 insertions(+), 2903 deletions(-)
 delete mode 100644 include/crypto/drbg.h
 delete mode 100644 include/crypto/internal/drbg.h

base-commit: c1f49dea2b8f335813d3b348fd39117fb8efb428

Signature · 1 line
2.53.0