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

fix CCM, as discovered when porting TLS to string #242

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

hannesm
Copy link
Member

@hannesm hannesm commented Aug 20, 2024

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

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
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

@hannesm
Copy link
Member Author

hannesm commented Aug 20, 2024

CI failures are:

  • arm issue ARM64 cycle count #216 (GitHub macOS runners, OCaml-CI macos & linux runners)
  • fetch failures on OCaml-CI
  • FreeBSD failure on OCaml-CI due to core issue (timerfd)

@hannesm hannesm merged commit 74fd16b into mirage:main Aug 20, 2024
9 of 13 checks passed
@hannesm hannesm deleted the fix-ccm branch August 20, 2024 09:29
hannesm added a commit to hannesm/opam-repository that referenced this pull request Aug 20, 2024
CHANGES:

* mirage-crypto: fix CCM implementation, discovered while porting TLS to
  mirage-crypto 1.0.0 (@hannesm @dinosaure @reynir mirage/mirage-crypto#242)
hannesm added a commit to hannesm/opam-repository that referenced this pull request Aug 20, 2024
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)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants