-
Notifications
You must be signed in to change notification settings - Fork 830
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
20240516-wc_AesXtsEnDecryptFinal #7549
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12907,8 +12907,9 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, byte* i, word32 iSz) | |
|
||
/* Block-streaming AES-XTS | ||
* | ||
* Note that sz must be greater than AES_BLOCK_SIZE in each call, and must be a | ||
* multiple of AES_BLOCK_SIZE in all but the final call. | ||
* Note that sz must be >= AES_BLOCK_SIZE in each call, and must be a multiple | ||
* of AES_BLOCK_SIZE in each call to wc_AesXtsEncryptUpdate(). | ||
* wc_AesXtsEncryptFinal() can handle any length >= AES_BLOCK_SIZE. | ||
* | ||
* xaes AES keys to use for block encrypt/decrypt | ||
* out output buffer to hold cipher text | ||
|
@@ -12920,7 +12921,7 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, byte* i, word32 iSz) | |
* | ||
* returns 0 on success | ||
*/ | ||
int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
static int AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
int ret; | ||
|
@@ -12975,6 +12976,29 @@ int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | |
return ret; | ||
} | ||
|
||
int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
if (sz & ((word32)AES_BLOCK_SIZE - 1U)) | ||
return BAD_FUNC_ARG; | ||
return AesXtsEncryptUpdate(xaes, out, in, sz, i); | ||
} | ||
|
||
int wc_AesXtsEncryptFinal(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
int ret; | ||
if (sz > 0) | ||
ret = AesXtsEncryptUpdate(xaes, out, in, sz, i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this input "sz" not have to be multiple of block size? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's right. for the last call, the input can have any length >= |
||
else | ||
ret = 0; | ||
ForceZero(i, AES_BLOCK_SIZE); | ||
#ifdef WOLFSSL_CHECK_MEM_ZERO | ||
wc_MemZero_Check(i, AES_BLOCK_SIZE); | ||
#endif | ||
return ret; | ||
} | ||
|
||
#endif /* WOLFSSL_AESXTS_STREAM */ | ||
|
||
|
||
|
@@ -13284,8 +13308,9 @@ int wc_AesXtsDecryptInit(XtsAes* xaes, byte* i, word32 iSz) | |
|
||
/* Block-streaming AES-XTS | ||
* | ||
* Note that sz must be greater than AES_BLOCK_SIZE in each call, and must be a | ||
* multiple of AES_BLOCK_SIZE in all but the final call. | ||
* Note that sz must be >= AES_BLOCK_SIZE in each call, and must be a multiple | ||
* of AES_BLOCK_SIZE in each call to wc_AesXtsDecryptUpdate(). | ||
* wc_AesXtsDecryptFinal() can handle any length >= AES_BLOCK_SIZE. | ||
* | ||
* xaes AES keys to use for block encrypt/decrypt | ||
* out output buffer to hold plain text | ||
|
@@ -13295,7 +13320,7 @@ int wc_AesXtsDecryptInit(XtsAes* xaes, byte* i, word32 iSz) | |
* | ||
* returns 0 on success | ||
*/ | ||
int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
static int AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
int ret; | ||
|
@@ -13353,6 +13378,29 @@ int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | |
return ret; | ||
} | ||
|
||
int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
if (sz & ((word32)AES_BLOCK_SIZE - 1U)) | ||
return BAD_FUNC_ARG; | ||
return AesXtsDecryptUpdate(xaes, out, in, sz, i); | ||
} | ||
|
||
int wc_AesXtsDecryptFinal(XtsAes* xaes, byte* out, const byte* in, word32 sz, | ||
byte *i) | ||
{ | ||
int ret; | ||
if (sz > 0) | ||
ret = AesXtsDecryptUpdate(xaes, out, in, sz, i); | ||
else | ||
ret = 0; | ||
ForceZero(i, AES_BLOCK_SIZE); | ||
#ifdef WOLFSSL_CHECK_MEM_ZERO | ||
wc_MemZero_Check(i, AES_BLOCK_SIZE); | ||
#endif | ||
return ret; | ||
} | ||
|
||
#endif /* WOLFSSL_AESXTS_STREAM */ | ||
|
||
#endif /* !WOLFSSL_ARMASM || WOLFSSL_ARMASM_NO_HW_CRYPTO */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What value does "final" add? Is it the zero'ing of "i"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a couple things:
(1) lets us add error-checking for all calls to
Update()
to make sure they're correctly block-aligned (trying to get ahead of ZenDesk tickets on that).(2) the zeroing lets us check for API abuse, in that it guarantees a wrong result if the user calls Update after a Final, and of course it also prevents anything valuable from leaking out through the IV.