upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mirage-crypto: CCM bugfix 32 bit with long adata (#207)

* Add 32 bit ccm test case
* Fix CCM on 32 bit architecture

authored by

Reynir Björnsson and committed by
GitHub
701e983c 3ebc0e3e

+13 -2
+2 -2
src/ccm.ml
··· 51 51 let buf = Cstruct.create 2 in 52 52 Cstruct.BE.set_uint16 buf 0 x ; 53 53 buf 54 - | x when x < (1 lsl 32) -> 54 + | x when Sys.int_size < 32 || x < (1 lsl 32) -> 55 55 let buf = Cstruct.create 4 in 56 56 Cstruct.BE.set_uint32 buf 0 (Int32.of_int x) ; 57 57 Cs.of_bytes [0xff ; 0xfe] <+> buf 58 - | x -> 58 + | x -> 59 59 let buf = Cstruct.create 8 in 60 60 Cstruct.BE.set_uint64 buf 0 (Int64.of_int x) ; 61 61 Cs.of_bytes [0xff ; 0xff] <+> buf
+11
tests/test_cipher.ml
··· 381 381 match authenticate_decrypt ~key ~nonce ~adata cipher with 382 382 | Some x -> assert_cs_equal ~msg:"CCM decrypt of empty message" p x 383 383 | None -> assert_failure "decryption broken" 384 + and long_adata _ = 385 + let key = of_secret (vx "000102030405060708090a0b0c0d0e0f") 386 + and nonce = vx "0001020304050607" 387 + and plaintext = Cstruct.of_string "hello" 388 + (* [adata] is greater than [1 lsl 16 - 1 lsl 8] *) 389 + and adata = Cstruct.create 65280 390 + and expected = vx "6592169e946f98973bc06d080f7c9dbb493a536f8a" 391 + in 392 + let cipher = authenticate_encrypt ~adata ~key ~nonce plaintext in 393 + assert_cs_equal ~msg:"CCM encrypt of >=65280 adata" expected cipher 384 394 in 385 395 [ 386 396 test_case no_vs_empty_ad ; ··· 389 399 test_case short_nonce_enc3 ; 390 400 test_case long_nonce_enc ; 391 401 test_case enc_dec_empty_message ; 402 + test_case long_adata ; 392 403 ] 393 404 394 405 let gcm_regressions =