OpenSSL: Implement aes_wrap() and aes_unwrap()

This replaces the implementation in aes-wrap.c and aes-unwrap.c with
OpenSSL AES_wrap_key() and AES_unwrap_key() functions when building
hostapd or wpa_supplicant with OpenSSL.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2015-01-27 13:57:59 +02:00 committed by Jouni Malinen
parent fee31f76cd
commit f19c907822
5 changed files with 43 additions and 0 deletions

View file

@ -675,7 +675,9 @@ ifdef CONFIG_INTERNAL_AES
AESOBJS += src/crypto/aes-internal.c src/crypto/aes-internal-enc.c AESOBJS += src/crypto/aes-internal.c src/crypto/aes-internal-enc.c
endif endif
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += src/crypto/aes-wrap.c AESOBJS += src/crypto/aes-wrap.c
endif
ifdef NEED_AES_EAX ifdef NEED_AES_EAX
AESOBJS += src/crypto/aes-eax.c AESOBJS += src/crypto/aes-eax.c
NEED_AES_CTR=y NEED_AES_CTR=y
@ -690,9 +692,11 @@ ifdef NEED_AES_OMAC1
AESOBJS += src/crypto/aes-omac1.c AESOBJS += src/crypto/aes-omac1.c
endif endif
ifdef NEED_AES_UNWRAP ifdef NEED_AES_UNWRAP
ifneq ($(CONFIG_TLS), openssl)
NEED_AES_DEC=y NEED_AES_DEC=y
AESOBJS += src/crypto/aes-unwrap.c AESOBJS += src/crypto/aes-unwrap.c
endif endif
endif
ifdef NEED_AES_CBC ifdef NEED_AES_CBC
NEED_AES_DEC=y NEED_AES_DEC=y
AESOBJS += src/crypto/aes-cbc.c AESOBJS += src/crypto/aes-cbc.c

View file

@ -669,7 +669,9 @@ ifdef CONFIG_INTERNAL_AES
AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-enc.o AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-enc.o
endif endif
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += ../src/crypto/aes-wrap.o AESOBJS += ../src/crypto/aes-wrap.o
endif
ifdef NEED_AES_EAX ifdef NEED_AES_EAX
AESOBJS += ../src/crypto/aes-eax.o AESOBJS += ../src/crypto/aes-eax.o
NEED_AES_CTR=y NEED_AES_CTR=y
@ -684,9 +686,11 @@ ifdef NEED_AES_OMAC1
AESOBJS += ../src/crypto/aes-omac1.o AESOBJS += ../src/crypto/aes-omac1.o
endif endif
ifdef NEED_AES_UNWRAP ifdef NEED_AES_UNWRAP
ifneq ($(CONFIG_TLS), openssl)
NEED_AES_DEC=y NEED_AES_DEC=y
AESOBJS += ../src/crypto/aes-unwrap.o AESOBJS += ../src/crypto/aes-unwrap.o
endif endif
endif
ifdef NEED_AES_CBC ifdef NEED_AES_CBC
NEED_AES_DEC=y NEED_AES_DEC=y
AESOBJS += ../src/crypto/aes-cbc.o AESOBJS += ../src/crypto/aes-cbc.o

View file

@ -297,6 +297,33 @@ void aes_decrypt_deinit(void *ctx)
} }
int aes_wrap(const u8 *kek, size_t kek_len, int n, const u8 *plain, u8 *cipher)
{
AES_KEY actx;
int res;
if (AES_set_encrypt_key(kek, kek_len << 3, &actx))
return -1;
res = AES_wrap_key(&actx, NULL, cipher, plain, n * 8);
OPENSSL_cleanse(&actx, sizeof(actx));
return res <= 0 ? -1 : 0;
}
int aes_unwrap(const u8 *kek, size_t kek_len, int n, const u8 *cipher,
u8 *plain)
{
AES_KEY actx;
int res;
if (AES_set_decrypt_key(kek, kek_len << 3, &actx))
return -1;
res = AES_unwrap_key(&actx, NULL, plain, cipher, (n + 1) * 8);
OPENSSL_cleanse(&actx, sizeof(actx));
return res <= 0 ? -1 : 0;
}
int crypto_mod_exp(const u8 *base, size_t base_len, int crypto_mod_exp(const u8 *base, size_t base_len,
const u8 *power, size_t power_len, const u8 *power, size_t power_len,
const u8 *modulus, size_t modulus_len, const u8 *modulus, size_t modulus_len,

View file

@ -1127,7 +1127,9 @@ ifdef CONFIG_INTERNAL_AES
AESOBJS += src/crypto/aes-internal.c src/crypto/aes-internal-dec.c AESOBJS += src/crypto/aes-internal.c src/crypto/aes-internal-dec.c
endif endif
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += src/crypto/aes-unwrap.c AESOBJS += src/crypto/aes-unwrap.c
endif
ifdef NEED_AES_EAX ifdef NEED_AES_EAX
AESOBJS += src/crypto/aes-eax.c AESOBJS += src/crypto/aes-eax.c
NEED_AES_CTR=y NEED_AES_CTR=y
@ -1148,8 +1150,10 @@ endif
endif endif
ifdef NEED_AES_WRAP ifdef NEED_AES_WRAP
NEED_AES_ENC=y NEED_AES_ENC=y
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += src/crypto/aes-wrap.c AESOBJS += src/crypto/aes-wrap.c
endif endif
endif
ifdef NEED_AES_CBC ifdef NEED_AES_CBC
NEED_AES_ENC=y NEED_AES_ENC=y
AESOBJS += src/crypto/aes-cbc.c AESOBJS += src/crypto/aes-cbc.c

View file

@ -1142,7 +1142,9 @@ ifdef CONFIG_INTERNAL_AES
AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-dec.o AESOBJS += ../src/crypto/aes-internal.o ../src/crypto/aes-internal-dec.o
endif endif
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += ../src/crypto/aes-unwrap.o AESOBJS += ../src/crypto/aes-unwrap.o
endif
ifdef NEED_AES_EAX ifdef NEED_AES_EAX
AESOBJS += ../src/crypto/aes-eax.o AESOBJS += ../src/crypto/aes-eax.o
NEED_AES_CTR=y NEED_AES_CTR=y
@ -1166,8 +1168,10 @@ AESOBJS += ../src/crypto/aes-siv.o
endif endif
ifdef NEED_AES_WRAP ifdef NEED_AES_WRAP
NEED_AES_ENC=y NEED_AES_ENC=y
ifneq ($(CONFIG_TLS), openssl)
AESOBJS += ../src/crypto/aes-wrap.o AESOBJS += ../src/crypto/aes-wrap.o
endif endif
endif
ifdef NEED_AES_CBC ifdef NEED_AES_CBC
NEED_AES_ENC=y NEED_AES_ENC=y
AESOBJS += ../src/crypto/aes-cbc.o AESOBJS += ../src/crypto/aes-cbc.o