Skip to content

Commit da24601

Browse files
committed
Add new AES-ECB API (and bump version to 1.5)
With configurable key size Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 2363095 commit da24601

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/blecrypt.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ void blecrypt_aes_128(
3535
EVP_CIPHER_CTX_free(ctx);
3636
}
3737

38+
// Performs simple AES-128/192/256 encryption of 128-bit data.
39+
void blecrypt_aes_ecb(
40+
// Inputs
41+
const uint8_t *key_be, // Key (KEY_LEN bytes, BIG-ENDIAN)
42+
size_t key_size, // Key size in bits (only 128, 192 and 256 are supported)
43+
const uint8_t *plaintext_data_be, // Plaintext data (128bits, BIG-ENDIAN)
44+
// Outputs (the pointers themselves are inputs and must point to large enough areas)
45+
uint8_t *encrypted_data_be) // Encrypted data (128bits, BIG-ENDIAN)
46+
{
47+
// Create OpenSSL cypher context
48+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
49+
// Set cipher type to AES-128, mode to ECB ("Electronic Codebook": simple independent encryption of blocks),
50+
// and provide encryption key
51+
if (key_size == 128) {
52+
EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key_be, NULL);
53+
} else if (key_size == 192) {
54+
EVP_EncryptInit(ctx, EVP_aes_192_ecb(), key_be, NULL);
55+
} else if (key_size == 256) {
56+
EVP_EncryptInit(ctx, EVP_aes_256_ecb(), key_be, NULL);
57+
}
58+
// Encrypt plaintext data and put result in encrypted_data_be and length in outlen
59+
int outlen;
60+
EVP_EncryptUpdate(ctx, encrypted_data_be, &outlen, plaintext_data_be, SKD_LEN);
61+
// Free cipher context
62+
EVP_CIPHER_CTX_free(ctx);
63+
}
64+
3865
// Encrypts payload of one packet and appends MIC.
3966
// Encrypted and unencrypted packet payloads must reside at different (non-overlapping) locations.
4067
void blecrypt_packet_encrypt(

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4
1+
1.5

0 commit comments

Comments
 (0)