Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Tiny AES C
Commits
5268e93e
Unverified
Commit
5268e93e
authored
Dec 06, 2017
by
kokke
Committed by
GitHub
Dec 06, 2017
Browse files
Update aes.h
parent
4346d1f0
Changes
1
Show whitespace changes
Inline
Side-by-side
aes.h
View file @
5268e93e
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include <stdint.h>
#include <stdint.h>
// #define the macros below to 1/0 to enable/disable the mode of operation.
// #define the macros below to 1/0 to enable/disable the mode of operation.
//
//
// CBC enables AES encryption in CBC-mode of operation.
// CBC enables AES encryption in CBC-mode of operation.
...
@@ -57,8 +56,8 @@ void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
...
@@ -57,8 +56,8 @@ void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
#if defined(ECB) && (ECB == 1)
#if defined(ECB) && (ECB == 1)
// buffer size is exactly AES_BLOCKLEN bytes;
// buffer size is exactly AES_BLOCKLEN bytes;
// you need only AES_init_ctx as I
v
is not used in ECB
// you need only AES_init_ctx as I
V
is not used in ECB
// NB: ECB s considered insecure
// NB: ECB
i
s considered insecure
for most uses
void
AES_ECB_encrypt
(
struct
AES_ctx
*
ctx
,
const
uint8_t
*
buf
);
void
AES_ECB_encrypt
(
struct
AES_ctx
*
ctx
,
const
uint8_t
*
buf
);
void
AES_ECB_decrypt
(
struct
AES_ctx
*
ctx
,
const
uint8_t
*
buf
);
void
AES_ECB_decrypt
(
struct
AES_ctx
*
ctx
,
const
uint8_t
*
buf
);
...
@@ -67,9 +66,9 @@ void AES_ECB_decrypt(struct AES_ctx* ctx, const uint8_t* buf);
...
@@ -67,9 +66,9 @@ void AES_ECB_decrypt(struct AES_ctx* ctx, const uint8_t* buf);
#if defined(CBC) && (CBC == 1)
#if defined(CBC) && (CBC == 1)
// buffer size MUST be mutile of AES_BLOCKLEN;
// buffer size MUST be mutile of AES_BLOCKLEN;
//
We s
uggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
if you need on
e
//
S
uggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
for padding schem
e
// you need to set
iv
in ctx via AES_init_ctx_iv or AES_ctx_set_iv
//
NOTES:
you need to set
IV
in ctx via AES_init_ctx_iv
()
or AES_ctx_set_iv
()
//
NB:
no IV should ever be reused with the same key
//
no IV should ever be reused with the same key
void
AES_CBC_encrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
void
AES_CBC_encrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
void
AES_CBC_decrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
void
AES_CBC_decrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
...
@@ -79,11 +78,11 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
...
@@ -79,11 +78,11 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
#if defined(CTR) && (CTR == 1)
#if defined(CTR) && (CTR == 1)
// Same function for encrypting as for decrypting.
// Same function for encrypting as for decrypting.
//
iv
is incremented for every block, and use
s
d after
encryption as
xor
compliment for output
//
IV
is incremented for every block, and used after encryption as
XOR-
compliment for output
// buffer size MUST be mutile of AES_BLOCKLEN;
// buffer size MUST be mu
l
ti
p
le of AES_BLOCKLEN;
//
We s
uggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
if you need on
e
//
S
uggest
ing
https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
for padding schem
e
// you need to set
iv
in ctx
via
AES_init_ctx_iv or AES_ctx_set_iv
//
NOTES:
you need to set
IV
in ctx
with
AES_init_ctx_iv
()
or AES_ctx_set_iv
()
//
NB:
no IV should ever be reused with the same key
//
no IV should ever be reused with the same key
void
AES_CTR_xcrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
void
AES_CTR_xcrypt_buffer
(
struct
AES_ctx
*
ctx
,
uint8_t
*
buf
,
uint32_t
length
);
#endif // #if defined(CTR) && (CTR == 1)
#endif // #if defined(CTR) && (CTR == 1)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment