Skip to content

Commit 6543daf

Browse files
added support for aes256_enc_single and aes256_dec_single
1 parent b171d51 commit 6543daf

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

AESLib.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ void aes128_enc_single(const uint8_t* key, void* data){
4747
aes128_enc(data, &ctx);
4848
}
4949

50+
// encrypt single 128bit block. data is assumed to be 16 uint8_t's
51+
// key and iv are assumed to be both 128bit thus 16 uint8_t's
52+
void aes256_enc_single(const uint16_t* key, void* data){
53+
aes256_ctx_t ctx;
54+
aes256_init(key, &ctx);
55+
aes256_enc(data, &ctx);
56+
}
57+
58+
5059
// prepare an encrypted to use for encrypting multiple blocks lateron.
5160
// key and iv are assumed to be both 128bit thus 16 uint8_t's
5261
aes_context aes128_cbc_enc_start(const uint8_t* key, const void* iv){
@@ -106,6 +115,15 @@ void aes128_dec_single(const uint8_t* key, void* data){
106115
aes128_dec(data, &ctx);
107116
}
108117

118+
// decrypt single 128bit block. data is assumed to be 16 uint8_t's
119+
// key and iv are assumed to be both 128bit thus 16 uint8_t's
120+
void aes256_dec_single(const uint16_t* key, void* data){
121+
aes256_ctx_t ctx;
122+
aes256_init(key, &ctx);
123+
aes256_dec(data, &ctx);
124+
}
125+
126+
109127
// prepare an decrypted to use for decrypting multiple blocks lateron.
110128
// key and iv are assumed to be both 128bit thus 16 uint8_t's
111129
aes_context aes128_cbc_dec_start(const uint8_t* key, const void* iv){

AESLib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void aes128_cbc_enc(const uint8_t* key, const uint8_t* iv, void* data, const uin
2929
// key and iv are assumed to be both 128bit thus 16 uint8_t's
3030
void aes128_enc_single(const uint8_t* key, void* data);
3131

32+
void aes256_enc_single(const uint16_t* key, void* data);
33+
3234
typedef void* aes_context;
3335

3436
// prepare an encrypted to use for encrypting multiple blocks lateron.
@@ -50,6 +52,8 @@ void aes128_cbc_dec(const uint8_t* key, const uint8_t* iv, void* data, const uin
5052
// key and iv are assumed to be both 128bit thus 16 uint8_t's
5153
void aes128_dec_single(const uint8_t* key, void* data);
5254

55+
void aes256_dec_single(const uint16_t* key, void* data);
56+
5357
// prepare an decrypter to use for decrypting multiple blocks lateron.
5458
// key and iv are assumed to be both 128bit thus 16 uint8_t's
5559
aes_context aes128_cbc_dec_start(const uint8_t* key, const void* iv);

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@ aes128_dec_single(key, data);
5252
Serial.print("decrypted:");
5353
Serial.println(data);
5454
```
55+
56+
Usage example for AES256:
57+
58+
```c
59+
Serial.begin(57600);
60+
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
61+
char data[] = "0123456789012345"; //16 chars == 16 bytes
62+
aes256_enc_single(key, data);
63+
Serial.print("encrypted:");
64+
Serial.println(data);
65+
aes256_dec_single(key, data);
66+
Serial.print("decrypted:");
67+
Serial.println(data);
68+
```

0 commit comments

Comments
 (0)