-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix CCM, as discovered when porting TLS to string #242
Conversation
The issue were missing offsets, both if multiple blocks were encrypted/decrypted and when unaligned data (i.e. not a multiple of block_size) was encrypted and decrypted.
Bytes.unsafe_blit buf 0 dst dst_off len ; | ||
unsafe_xor_into src ~src_off dst ~dst_off len ; | ||
Bytes.unsafe_blit_string cbcblock cbc_off buf 0 len ; | ||
Bytes.unsafe_fill buf len (block_size - len) '\x00'; | ||
cbc (Bytes.unsafe_to_string buf) cbc_off iv 0 | ||
cbc (Bytes.unsafe_to_string buf) 0 iv 0 |
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.
Hmm is it safe to switch cbc_off
with 0
?
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.
Ah, it is. buf
is the counter stuff and unrelated to src
/dst
.
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.
No, it's not the counter stuff, I am confusing myself. But this looks good.
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.
buf
is the locally created 16 byte buffer that holds the last block (which is then partially blit into dst). the cbc
is for the tag, and here the full buf
is used -- where previously the cbcblock
(depending on encrypt or decrypt, the src or dst) has been blit into, followed by clearing the remaining bytes with 0.
CI failures are:
|
CHANGES: * mirage-crypto: fix CCM implementation, discovered while porting TLS to mirage-crypto 1.0.0 (@hannesm @dinosaure @reynir mirage/mirage-crypto#242)
CHANGES: * FEATURE mirage-crypto-ec: provide Dh.secret_to_octets (requested in mirage/mirage-crypto#243 by @palainp, implemented by @hannesm mirage/mirage-crypto#244) * mirage-crypto: fix CCM implementation, discovered while porting TLS to mirage-crypto 1.0.0 (@hannesm @dinosaure @reynir mirage/mirage-crypto#242)
CHANGES: * FEATURE mirage-crypto-ec: provide Dh.secret_to_octets (requested in mirage/mirage-crypto#243 by @palainp, implemented by @hannesm mirage/mirage-crypto#244) * mirage-crypto: fix CCM implementation, discovered while porting TLS to mirage-crypto 1.0.0 (@hannesm @dinosaure @reynir mirage/mirage-crypto#242)
The issue were missing offsets, both if multiple blocks were encrypted/decrypted and when unaligned data (i.e. not a multiple of block_size) was encrypted and decrypted.
//cc @reynir @dinosaure