commit fab1952

Michael Forney  ·  2025-04-06 20:17:03 +0000 UTC
parent 9ec1700
wpa_supplicant: Use BearSSL AES implementation
3 files changed,  +88, -9
+0, -3
 1@@ -29,9 +29,6 @@ exe('bin/wpa_supplicant', [[
 2 		wpa_common.c
 3 	)
 4 	src/crypto/(
 5-		aes-internal-dec.c
 6-		aes-internal-enc.c
 7-		aes-internal.c
 8 		aes-omac1.c
 9 		aes-unwrap.c
10 		aes-wrap.c
+87, -5
  1@@ -1,19 +1,19 @@
  2-From ea00c8e557fe645a1ef0b6c0ebe2209514f9f94f Mon Sep 17 00:00:00 2001
  3+From e6ef6ceba52f7d80f82dd91e1c6a121e11caefa5 Mon Sep 17 00:00:00 2001
  4 From: Michael Forney <mforney@mforney.org>
  5 Date: Fri, 15 Nov 2019 20:19:37 -0800
  6 Subject: [PATCH] Add support for some BearSSL crypto primitives
  7 
  8 ---
  9- src/crypto/crypto_bearssl.c | 83 +++++++++++++++++++++++++++++++++++++
 10- 1 file changed, 83 insertions(+)
 11+ src/crypto/crypto_bearssl.c | 165 ++++++++++++++++++++++++++++++++++++
 12+ 1 file changed, 165 insertions(+)
 13  create mode 100644 src/crypto/crypto_bearssl.c
 14 
 15 diff --git a/src/crypto/crypto_bearssl.c b/src/crypto/crypto_bearssl.c
 16 new file mode 100644
 17-index 000000000..db2bfbc27
 18+index 000000000..c207f22bc
 19 --- /dev/null
 20 +++ b/src/crypto/crypto_bearssl.c
 21-@@ -0,0 +1,83 @@
 22+@@ -0,0 +1,165 @@
 23 +/*
 24 + * Wrapper functions for BearSSL crypto
 25 + * Copyright (c) 2019, Michael Forney <mforney@mforney.org>
 26@@ -94,6 +94,88 @@ index 000000000..db2bfbc27
 27 +	return hmac_vector(key, key_len, 1, &data, &data_len, mac, &br_md5_vtable);
 28 +}
 29 +
 30++void *aes_encrypt_init(const u8 *key, size_t len)
 31++{
 32++	br_aes_ct64_cbcenc_keys *ctx;
 33++
 34++	if (len != 16 && len != 24 && len != 32)
 35++		return NULL;
 36++	ctx = os_malloc(sizeof *ctx);
 37++	if (ctx == NULL)
 38++		return NULL;
 39++	br_aes_ct64_cbcenc_init(ctx, key, len);
 40++	return ctx;
 41++}
 42++
 43++int aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
 44++{
 45++	unsigned char iv[br_aes_ct64_BLOCK_SIZE];
 46++
 47++	memset(iv, 0, sizeof iv);
 48++	memcpy(crypt, plain, br_aes_ct64_BLOCK_SIZE);
 49++	br_aes_ct64_cbcenc_run(ctx, iv, crypt, br_aes_ct64_BLOCK_SIZE);
 50++	return 0;
 51++}
 52++
 53++void aes_encrypt_deinit(void *ctx)
 54++{
 55++	os_free(ctx);
 56++}
 57++
 58++void *aes_decrypt_init(const u8 *key, size_t len)
 59++{
 60++	br_aes_ct64_cbcdec_keys *ctx;
 61++
 62++	if (len != 16 && len != 24 && len != 32)
 63++		return NULL;
 64++	ctx = os_malloc(sizeof *ctx);
 65++	if (ctx == NULL)
 66++		return NULL;
 67++	br_aes_ct64_cbcdec_init(ctx, key, len);
 68++	return ctx;
 69++}
 70++
 71++int aes_decrypt(void *ctx, const u8 *plain, u8 *crypt)
 72++{
 73++	unsigned char iv[br_aes_ct64_BLOCK_SIZE];
 74++
 75++	memset(iv, 0, sizeof iv);
 76++	memcpy(crypt, plain, br_aes_ct64_BLOCK_SIZE);
 77++	br_aes_ct64_cbcdec_run(ctx, iv, crypt, br_aes_ct64_BLOCK_SIZE);
 78++	return 0;
 79++}
 80++
 81++void aes_decrypt_deinit(void *ctx)
 82++{
 83++	os_free(ctx);
 84++}
 85++
 86++int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
 87++{
 88++	br_aes_ct64_cbcenc_keys ctx;
 89++	u8 ivbuf[br_aes_ct64_BLOCK_SIZE];
 90++
 91++	if (data_len & 0xF)
 92++		return -1;
 93++	memcpy(ivbuf, iv, sizeof ivbuf);
 94++	br_aes_ct64_cbcenc_init(&ctx, key, 16);
 95++	br_aes_ct64_cbcenc_run(&ctx, ivbuf, data, data_len);
 96++	return 0;
 97++}
 98++
 99++int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
100++{
101++	br_aes_ct64_cbcdec_keys ctx;
102++	u8 ivbuf[br_aes_ct64_BLOCK_SIZE];
103++
104++	if (data_len & 0xF)
105++		return -1;
106++	memcpy(ivbuf, iv, sizeof ivbuf);
107++	br_aes_ct64_cbcdec_init(&ctx, key, 16);
108++	br_aes_ct64_cbcdec_run(&ctx, ivbuf, data, data_len);
109++	return 0;
110++}
111++
112 +void crypto_unload(void)
113 +{
114 +}
+1, -1
1@@ -1 +1 @@
2-2.11 r0
3+2.11 r1