Skip to content

Library APIs for AES encryption modes

Eric Biggers linux-crypto lkml 2 versions – Applied

Status from this message: Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest13 patches 4 repliesApplied
  2. v133 patches 23 repliesSuperseded

Changes in v2 from the cover letter

- Reduced the series to just the patches targeting 7.3.
- Made lots of documentation and comment improvements.
- Made CRYPTO_AES select the library kconfig options correctly.
- Adjusted the parameter order of some functions for better consistency:
aes_ccm_init(), aes_{ccm,gcm}_encrypt(), aes_{ccm,gcm}_decrypt().
- Made the CCM implementation support ad_len up to 2^64 - 1, as per the spec, instead of artifically capping it at 2^32.
- Made the CCM implementation check for incorrect call order, making it consistent with the GCM implementation.
- Optimized how aes_ccm_init() validates data_len.
- Made the GCM implementation check for the maximum ad_len.
- Made aes_{gcm,ccm}_decrypt_final() return an error code if either of the lengths was incorrect, instead of just warning.
- Shared more code between encryption and decryption for GCM and CCM in crypto/aes.c.
- Removed unnecessary casts in inc_be128_ctr().
- Avoided memset() with dst == NULL.
- Lots of other small cleanups.

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/13crypto: xts - Split out __xts_verify_key() helperinclude/crypto/xts.h+14 -40 replies
2/13lib/crypto: aes: Add ECB supportDocumentation/crypto/libcrypto-unauth-encryption.rst Documentation/crypto/libcrypto.rst include/crypto/aes-ecb.h +3 more+141 -00 replies
3/13lib/crypto: aes: Add CBC and CBC-CTS supportDocumentation/crypto/libcrypto-unauth-encryption.rst include/crypto/aes-cbc.h lib/crypto/Kconfig +2 more+278 -00 replies
4/13lib/crypto: aes: Add CTR and XCTR supportDocumentation/crypto/libcrypto-unauth-encryption.rst include/crypto/aes-ctr.h lib/crypto/Kconfig +2 more+175 -01 reply
5/13lib/crypto: aes: Add XTS supportDocumentation/crypto/libcrypto-unauth-encryption.rst include/crypto/aes-xts.h lib/crypto/Kconfig +2 more+339 -00 replies
6/13lib/crypto: aes: Add GCM supportDocumentation/crypto/libcrypto-auth-encryption.rst Documentation/crypto/libcrypto.rst include/crypto/aes-gcm.h +4 more+565 -22 replies
7/13lib/crypto: aes: Add CCM supportDocumentation/crypto/libcrypto-auth-encryption.rst include/crypto/aes-ccm.h lib/crypto/Kconfig +2 more+595 -00 replies
8/13crypto: aes - Add ECB support using librarycrypto/Kconfig crypto/aes.c+168 -10 replies
9/13crypto: aes - Add CBC and CBC-CTS support using librarycrypto/Kconfig crypto/aes.c+170 -00 replies
10/13crypto: aes - Add CTR and XCTR support using librarycrypto/Kconfig crypto/aes.c+69 -00 replies
11/13crypto: aes - Add XTS support using librarycrypto/Kconfig crypto/aes.c+118 -00 replies
12/13crypto: aes - Add GCM support using librarycrypto/Kconfig crypto/aes.c+247 -00 replies
13/13crypto: aes - Add CCM support using librarycrypto/Kconfig crypto/aes.c+131 -10 replies

Reviews trailers per patch

4 of 13 patches have a Reviewed-by or Acked-by.

PatchThomas Huth
1/13R-b
2/13R-b
3/13R-b
4/13R-b
5/13
6/13
7/13
8/13
9/13
10/13
11/13
12/13
13/13

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

Read the v2 thread

Cover letter [PATCH v2 00/13] Library APIs for AES encryption modes

This series can also be retrieved from:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git aes-modes-v2

This series adds library APIs for almost all AES encryption modes that are used in the kernel, both authenticated and unauthenticated: AES-ECB, AES-CBC, AES-CBC-CTS, AES-CTR, AES-XCTR, AES-XTS, AES-GCM, and AES-CCM.

Patches 2-7 add the library APIs, and patches 8-13 wire them up to the traditional crypto API (with just priority 110 for now). I'm planning to take these through libcrypto-next for 7.3.

Proof-of-concept patches that convert users of the traditional crypto API to use the new library APIs can be found in patches 14-33 of the v1 series
(https://lore.kernel.org/linux-crypto/[email protected]/).
Those additional patches are intended for 7.4 or later.

Apologies for the large patch series, but it ended up being easiest to handle all the AES modes at once rather than try to do them one by one. This ensures a consistent design for them, which is really important. Additionally, the arch-optimized AES code tends to intermingle different modes, and many depend on each other anyway.

But as a result, to keep this series manageable it doesn't include the usual KUnit tests or the integration of the architecture-optimized code. Those will be sent separately in follow-up series.

Changed in v2:
- Reduced the series to just the patches targeting 7.3.
- Made lots of documentation and comment improvements.
- Made CRYPTO_AES select the library kconfig options correctly.
- Adjusted the parameter order of some functions for better consistency:
aes_ccm_init(), aes_{ccm,gcm}_encrypt(), aes_{ccm,gcm}_decrypt().
- Made the CCM implementation support ad_len up to 2^64 - 1, as per the spec, instead of artifically capping it at 2^32.
- Made the CCM implementation check for incorrect call order, making it consistent with the GCM implementation.
- Optimized how aes_ccm_init() validates data_len.
- Made the GCM implementation check for the maximum ad_len.
- Made aes_{gcm,ccm}_decrypt_final() return an error code if either of the lengths was incorrect, instead of just warning.
- Shared more code between encryption and decryption for GCM and CCM in crypto/aes.c.
- Removed unnecessary casts in inc_be128_ctr().
- Avoided memset() with dst == NULL.
- Lots of other small cleanups.

Eric Biggers (13):
crypto: xts - Split out __xts_verify_key() helper lib/crypto: aes: Add ECB support
lib/crypto: aes: Add CBC and CBC-CTS support lib/crypto: aes: Add CTR and XCTR support lib/crypto: aes: Add XTS support
lib/crypto: aes: Add GCM support
lib/crypto: aes: Add CCM support
crypto: aes - Add ECB support using library
crypto: aes - Add CBC and CBC-CTS support using library
crypto: aes - Add CTR and XCTR support using library
crypto: aes - Add XTS support using library
crypto: aes - Add GCM support using library
crypto: aes - Add CCM support using library

 .../crypto/libcrypto-auth-encryption.rst      |   20 +
 .../crypto/libcrypto-unauth-encryption.rst    |   49 +
 Documentation/crypto/libcrypto.rst            |    2 +
 crypto/Kconfig                                |   11 +
 crypto/aes.c                                  |  892 ++++++++++++-
 include/crypto/aes-cbc.h                      |   77 ++
 include/crypto/aes-ccm.h                      |  266 ++++
 include/crypto/aes-ctr.h                      |   65 +
 include/crypto/aes-ecb.h                      |   49 +
 include/crypto/aes-gcm.h                      |  260 ++++
 include/crypto/aes-xts.h                      |   94 ++
 include/crypto/gcm.h                          |    4 +-
 include/crypto/xts.h                          |   18 +-
 lib/crypto/Kconfig                            |   40 +
 lib/crypto/aes.c                              | 1163 +++++++++++++++++
 lib/crypto/tests/Kconfig                      |    6 +
 16 files changed, 3009 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/crypto/libcrypto-auth-encryption.rst
 create mode 100644 Documentation/crypto/libcrypto-unauth-encryption.rst
 create mode 100644 include/crypto/aes-cbc.h
 create mode 100644 include/crypto/aes-ccm.h
 create mode 100644 include/crypto/aes-ctr.h
 create mode 100644 include/crypto/aes-ecb.h
 create mode 100644 include/crypto/aes-gcm.h
 create mode 100644 include/crypto/aes-xts.h

base-commit: e073f1238ecaea366f53e98724c40b31856da56a

Signature · 1 line
2.55.0