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
4b91b70c
Unverified
Commit
4b91b70c
authored
Dec 01, 2017
by
kokke
Committed by
GitHub
Dec 01, 2017
Browse files
adding CTR-mode
parent
835777b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
aes.c
View file @
4b91b70c
/*
/*
This is an implementation of the AES algorithm, specifically ECB and CBC mode.
This is an implementation of the AES algorithm, specifically ECB
, CTR
and CBC mode.
Block size can be chosen in aes.h - available choices are AES128, AES192, AES256.
Block size can be chosen in aes.h - available choices are AES128, AES192, AES256.
The implementation is verified against the test vectors in:
The implementation is verified against the test vectors in:
...
@@ -595,3 +595,42 @@ void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
...
@@ -595,3 +595,42 @@ void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
}
}
#endif // #if defined(CBC) && (CBC == 1)
#endif // #if defined(CBC) && (CBC == 1)
#if defined(CTR) && (CTR == 1)
void
AES_CTR_xcrypt_buffer
(
uint8_t
*
output
,
uint8_t
*
input
,
uint32_t
length
,
const
uint8_t
*
key
,
const
uint8_t
*
iv
)
{
uint8_t
buffer
[
BLOCKLEN
],
counter
[
BLOCKLEN
];
memcpy
(
counter
,
iv
,
BLOCKLEN
);
Key
=
key
;
KeyExpansion
();
int
i
,
j
;
for
(
i
=
0
;
i
<
length
;
++
i
)
{
if
((
i
&
0x0F
)
==
0
)
{
memcpy
(
buffer
,
counter
,
BLOCKLEN
);
state
=
(
state_t
*
)
buffer
;
Cipher
();
for
(
j
=
(
BLOCKLEN
-
1
);
j
>=
0
;
--
j
)
{
counter
[
j
]
+=
1
;
if
(
counter
[
j
]
!=
0
)
{
break
;
}
}
}
output
[
i
]
=
(
input
[
i
])
^
(
buffer
[
i
&
0x0F
]);
}
}
#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