@@ -35,6 +35,33 @@ void blecrypt_aes_128(
35
35
EVP_CIPHER_CTX_free (ctx );
36
36
}
37
37
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
+
38
65
// Encrypts payload of one packet and appends MIC.
39
66
// Encrypted and unencrypted packet payloads must reside at different (non-overlapping) locations.
40
67
void blecrypt_packet_encrypt (
0 commit comments