On 2026-07-14 13:45, Ilya Leoshkevich wrote:
On 7/10/26 17:28, Harald Freudenberger wrote:
Add a new file crypto/aes-helpers.c with simple functions
to support some AES modes:
- AES cbc: AES_cbc_encrypt() AES_cbc_decrypt()
- AES ctr: AES_ctr_encrypt()
- AES xts: AES_xts_encrypt() AES_xts_decrypt()
and some AES related helpers:
- AES_xor()
- AES_xts_prep_next_tweak()
Add header file include/crypto/aes-helpers.h for these functions

Signed-off-by: Harald Freudenberger <[email protected]>
Reviewed-by: Finn Callies <[email protected]>
---
  crypto/aes-helpers.c         | 106 ++++++++++++++++++++++++++++++++
  crypto/meson.build           |   1 +
include/crypto/aes-helpers.h | 116 +++++++++++++++++++++++++++++++++++
  3 files changed, 223 insertions(+)
  create mode 100644 crypto/aes-helpers.c
  create mode 100644 include/crypto/aes-helpers.h

diff --git a/crypto/aes-helpers.c b/crypto/aes-helpers.c
new file mode 100644
index 0000000000..ff4aa0a385
--- /dev/null
+++ b/crypto/aes-helpers.c

[...]

+void AES_ctr_encrypt(const unsigned char *in, unsigned char *out,
+                     const unsigned char *ctr, const AES_KEY *key)
+{
+    unsigned char buf[AES_BLOCK_SIZE];
+
+    /* encrypt ctr => buf */
+    AES_encrypt(ctr, buf, key);
+    /* exor input data with encrypted ctr => out */
+    AES_xor(in, buf, out);
+}
+
+/*
+ * Tweak calculation for AES XTS.
+ * Multiply tweak by α (x) in GF(2^128) per IEEE 1619-2007. The tweak
+ * is a 128-bit little-endian integer (tweak[0]=LSB, tweak[15]=MSB).
+ * This implementation has been verified on litte and big endian.
+ */

Nit: do we need to have this comment twice?
It's already present in the header.

Well the text is different. aes-helpers.h:

  /**
   * AES_xts_prep_next_tweak:
   *
   * Tweak calculation for AES XTS.
   * Prepares the next tweak value for AES-XTS mode by multiplying
* the current tweak by α (x) in GF(2^128) according to IEEE 1619-2007.
   *
   * @tweak: pointer to tweak value to be updated (16 bytes buffer
   *         containing a 128 bit little endian integer)
   */
  void AES_xts_prep_next_tweak(unsigned char *tweak);

aes-helpers.c:

  /*
   * Tweak calculation for AES XTS.
   * Multiply tweak by α (x) in GF(2^128) per IEEE 1619-2007. The tweak
   * is a 128-bit little-endian integer (tweak[0]=LSB, tweak[15]=MSB).
   * This implementation has been verified on little and big endian.
   */
  void AES_xts_prep_next_tweak(unsigned char *tweak)

And the idea was to describe in the header more the usage whereas
in the c code describe the implementation.


Also typo: litte -> little (but I'm not sure if we even need to state
that in the code).

fixed the typo -> see v13


[...]

Reviewed-by: Ilya Leoshkevich <[email protected]>

Thanks for your review

Reply via email to