26 lines
840 B
C
26 lines
840 B
C
|
#pragma once
|
||
|
|
||
|
#include <cstdint>
|
||
|
|
||
|
namespace AES {
|
||
|
|
||
|
constexpr size_t kKeyLen = 16; // Key length in bytes
|
||
|
constexpr size_t kKeyExpansionSize = 176;
|
||
|
constexpr size_t kBlockLen = 16; // Block length in bytes - AES is 128b block only
|
||
|
|
||
|
struct AES_ctx {
|
||
|
uint8_t RoundKey[kKeyExpansionSize];
|
||
|
uint8_t Iv[16];
|
||
|
};
|
||
|
|
||
|
void AES_init_ctx_iv(AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||
|
|
||
|
// buffer size MUST be mutile of AES_BLOCKLEN;
|
||
|
// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
|
||
|
// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
|
||
|
// no IV should ever be reused with the same key
|
||
|
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||
|
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||
|
|
||
|
} // namespace AES
|