Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SP800-38E limitation #7558

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -12785,13 +12785,16 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,

aes = &xaes->aes;

/* FIPS TODO: SP800-38E - Restrict data unit to 2^20 blocks per key. A block is
* AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to
* protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes or
* 134,217,728-bits) Add helpful printout and message along with BAD_FUNC_ARG
* return whenever sz / AES_BLOCK_SIZE > 1,048,576 or equal to that and sz is
* not a sequence of complete blocks.
*/
#if FIPS_VERSION3_GE(6,0,0)
/* SP800-38E - Restrict data unit to 2^20 blocks per key. A block is
* AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to
* protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes)
*/
if (sz > FIPS_XTS_LIMIT) {
WOLFSSL_MSG("Request exceeds allowed bytes per SP800-38E");
return BAD_FUNC_ARG;
}
#endif

if (aes->keylen == 0) {
WOLFSSL_MSG("wc_AesXtsEncrypt called with unset encryption key.");
Expand Down
6 changes: 6 additions & 0 deletions wolfssl/wolfcrypt/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ typedef struct Gcm {
#if FIPS_VERSION3_GE(6,0,0)
extern const unsigned int wolfCrypt_FIPS_aes_ro_sanity[2];
WOLFSSL_LOCAL int wolfCrypt_FIPS_AES_sanity(void);

/* SP800-38E - Restrict data unit to 2^20 blocks per key. A block is
* AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to
* protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes)
*/
#define FIPS_XTS_LIMIT 16777216
#endif

WOLFSSL_LOCAL void GenerateM0(Gcm* gcm);
Expand Down