From 329439f361fb9cd446c728aeefda70cd5cb3f852 Mon Sep 17 00:00:00 2001
From: Graham Percival <gperciva@tarsnap.com>
Date: Mon, 8 Apr 2024 11:56:49 -0700
Subject: [PATCH] apisupport: add & use LIBCRYPTO-LOW_LEVEL_AES

---
 Makefile.am                                       |  7 ++++++-
 .../Build/apisupport-LIBCRYPTO-LOW_LEVEL_AES.c    | 15 +++++++++++++++
 libcperciva/crypto/crypto_aes.c                   |  4 ++++
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 libcperciva/apisupport/Build/apisupport-LIBCRYPTO-LOW_LEVEL_AES.c

diff --git a/Makefile.am b/Makefile.am
index a3f265ed..4ecc8db1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,7 +49,6 @@ scrypt_SOURCES=		main.c					\
 			lib/util/passphrase_entry.c		\
 			lib/util/passphrase_entry.h		\
 			lib-platform/util/memlimit.h		\
-			libcperciva/crypto/crypto_aes.c		\
 			libcperciva/crypto/crypto_aes.h		\
 			libcperciva/crypto/crypto_aes_aesni.h	\
 			libcperciva/crypto/crypto_aes_aesni_m128i.h \
@@ -101,6 +100,7 @@ AM_CPPFLAGS=		-I$(srcdir)/lib				\
 scrypt_LDADD=		libcperciva_aesni.la libcperciva_rdrand.la \
 			libcperciva_shani.la libscrypt_sse2.la	\
 			libscrypt_memlimit.la			\
+			libscrypt_crypto_aes.la			\
 			libcperciva_arm_sha256.la		\
 			libcperciva_arm_aes.la			\
 			${LDADD_POSIX}
@@ -159,6 +159,11 @@ libscrypt_memlimit_la_SOURCES=	lib-platform/util/memlimit.c	\
 				lib-platform/util/memlimit.h
 libscrypt_memlimit_la_CFLAGS=`. ./apisupport-config.h; echo $${CFLAGS_NONPOSIX_MEMLIMIT}`
 
+noinst_LTLIBRARIES+=	libscrypt_crypto_aes.la
+libscrypt_crypto_aes_la_SOURCES=	libcperciva/crypto/crypto_aes.c	\
+					libcperciva/crypto/crypto_aes.h
+libscrypt_crypto_aes_la_CFLAGS=`. ./apisupport-config.h; echo $${CFLAGS_LIBCRYPTO_LOW_LEVEL_AES}`
+
 # Install libscrypt-kdf?
 if LIBSCRYPT_KDF
 lib_LTLIBRARIES=		libscrypt-kdf.la
diff --git a/libcperciva/apisupport/Build/apisupport-LIBCRYPTO-LOW_LEVEL_AES.c b/libcperciva/apisupport/Build/apisupport-LIBCRYPTO-LOW_LEVEL_AES.c
new file mode 100644
index 00000000..1864f011
--- /dev/null
+++ b/libcperciva/apisupport/Build/apisupport-LIBCRYPTO-LOW_LEVEL_AES.c
@@ -0,0 +1,15 @@
+#include <stdint.h>
+
+#include <openssl/aes.h>
+
+int
+main(void)
+{
+	AES_KEY kexp_actual;
+	const uint8_t key_unexpanded[16] = { 0 };
+
+	AES_set_encrypt_key(key_unexpanded, 128, &kexp_actual);
+
+	/* Success! */
+	return (0);
+}
diff --git a/libcperciva/crypto/crypto_aes.c b/libcperciva/crypto/crypto_aes.c
index f884605b..d88f9510 100644
--- a/libcperciva/crypto/crypto_aes.c
+++ b/libcperciva/crypto/crypto_aes.c
@@ -1,3 +1,7 @@
+/**
+ * APISUPPORT CFLAGS: LIBCRYPTO_LOW_LEVEL_AES
+ */
+
 #include <assert.h>
 #include <stdint.h>
 #include <stdlib.h>