Skip to content

Commit 770001f

Browse files
committed
3des test vectors (manually generated by test_random_runner)
1 parent b1a794a commit 770001f

File tree

2 files changed

+91
-7
lines changed

2 files changed

+91
-7
lines changed

tests/test_cipher.ml

+91
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,94 @@ open Mirage_crypto
44

55
open Test_common
66

7+
let des_ecb_cases =
8+
let open Cipher_block in
9+
10+
let case ~data ~key ~out = vx data, DES.ECB.of_secret (vx key), vx out
11+
12+
and check (data, key, out) _ =
13+
let enc = DES.ECB.encrypt ~key data in
14+
let dec = DES.ECB.decrypt ~key enc in
15+
assert_oct_equal ~msg:"ciphertext" out enc ;
16+
assert_oct_equal ~msg:"plaintext" data dec in
17+
18+
cases_of check [
19+
case
20+
~data:"3f87 9123 0058 8d88 e784 d52a 5d0f 2038
21+
f523 6889 bbce ce1f a7bf 7aa8 6fcc 8245
22+
0576 2144 8f11 94d7 07bc 1bba 9b92 5e45
23+
3190 c42b 758f 3d91 f68e ebbb ce62 b8e7"
24+
~key: "3f47 f79c c120 7188 4700 217e fd88 bbe4 6f51 27fb 7340 81e5"
25+
~out: "b43b 3ae3 d765 b299 06ea 7c35 ceeb 9e52
26+
946c 06e7 0d50 193e 5a22 1ff0 afe9 abe0
27+
3b82 ce7d c42a 465d 0f19 45f0 5382 7006
28+
b4cd 21f0 5b0f 6843 de2a 67b6 9fb4 6a8f"
29+
]
30+
31+
let des_cbc_cases =
32+
let open Cipher_block in
33+
34+
let case ~data ~key ~iv ~out = vx data, DES.CBC.of_secret (vx key), vx iv, vx out
35+
36+
and check (data, key, iv, out) _ =
37+
let enc = DES.CBC.encrypt ~key ~iv data in
38+
let dec = DES.CBC.decrypt ~key ~iv enc in
39+
assert_oct_equal ~msg:"ciphertext" out enc ;
40+
assert_oct_equal ~msg:"plaintext" data dec in
41+
42+
cases_of check [
43+
case
44+
~data:
45+
"8f8c 1e0a c8fb 1614 3cec ed1c 28ac fd6f
46+
ae6d 3686 5365 511d 6707 68d9 7928 0479
47+
cacd 6808 1540 d5fc 2971 2a8a c2b1 17c2
48+
f0e6 a329 e190 44ff 54e7 5eec 8296 6a58"
49+
~iv:"b219 ef93 4c37 aadf"
50+
~key:"7ecd 2240 a2ac a10a e713 f467 7ea5 d327 e04c cfe0 5cb4 bb09"
51+
~out:
52+
"3110 3904 faa1 4ef4 e404 d3d0 f2ee ae58
53+
5fe9 e6b7 9552 b4f4 3608 03ca 395a f6e9
54+
2330 69d6 2c6f a52a d083 faab 3306 b794
55+
89f6 6671 e3dd 3368 0b13 f8d9 7136 9674"
56+
]
57+
58+
let des_ctr_cases =
59+
let case ~data ~key ~ctr ~out = test_case @@ fun _ ->
60+
let open Cipher_block.DES.CTR in
61+
let key = vx key |> of_secret
62+
and ctr = vx ctr |> ctr_of_octets
63+
and out = vx out
64+
and data = vx data in
65+
let enc = encrypt ~key ~ctr data in
66+
let dec = decrypt ~key ~ctr enc in
67+
assert_oct_equal ~msg:"cipher" out enc;
68+
assert_oct_equal ~msg:"plain" data dec
69+
in
70+
[ case
71+
~data:
72+
"e9ee ce61 7b75 4c70 79f3 3e5b 036a 7d5b
73+
4bee f693 0eb3 fa50 9fe3 61d8 713a a487
74+
a692 21b0 8627 5e6f d021 4030 7c58 507a
75+
5fea ca64 d17d a493 7337 8c17 ae05 f3c4
76+
c6dc 15cc 49c4 3ab0 dab3 9c9b e964 a3c8
77+
5865 7bb8 6e4d 8507 3866 b805 02c2 4970
78+
dbbd 3554 20b1 76b2 ee6c 98b3 f7ce 9035
79+
1e5f 880e"
80+
~key:"76b9 d4ff d52f 5024 6d24 a3e1 4ebd e605 b82c d81f 0c07 2da1"
81+
~ctr:"6318 a132 cafd aac0"
82+
~out:
83+
"b8d8 aeec d583 009c f042 ec4d 7ddf c5e5
84+
386f 89e6 d975 02bc 7583 e113 4899 dabc
85+
bd93 871b 774b e5ce 4e12 6778 f208 0c53
86+
52cb a3ac 7567 cdb9 ae81 fc46 25d4 7f9d
87+
6f3f fbec 4512 8845 3739 1014 2b39 d293
88+
845a 8505 91a6 f644 5168 bf00 ca4d 4603
89+
6e5f 418f c43f fabd 272e 1009 c69b 2a6b
90+
7d2c edb2"
91+
92+
]
93+
94+
795
(* NIST SP 800-38A test vectors for block cipher modes of operation *)
896

997
let nist_sp_800_38a = vx
@@ -762,6 +850,9 @@ let empty_cases _ =
762850
assert_oct_equal ~msg:"ARC4 decrypt" plain (Cipher_stream.ARC4.(decrypt ~key cipher).message)
763851

764852
let suite = [
853+
"3DES-ECB" >::: des_ecb_cases ;
854+
"3DES-CBC" >::: des_cbc_cases ;
855+
"3DES-CTR" >::: des_ctr_cases ;
765856
"AES-ECB" >::: [ "SP 300-38A" >::: aes_ecb_cases ] ;
766857
"AES-CBC" >::: [ "SP 300-38A" >::: aes_cbc_cases ] ;
767858
"AES-CTR" >::: [ "SP 300-38A" >::: aes_ctr_cases; ] ;

tests/test_symmetric_runner.ml

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
open OUnit2
22

3-
(* Gather quantum uncertainty. *)
4-
(* let () = *)
5-
(* let t = Unix.gettimeofday () in *)
6-
(* let cs = Cstruct.create 8 in *)
7-
(* Cstruct.BE.set_uint64 cs 0 Int64.(of_float (t *. 1000.)) ; *)
8-
(* Mirage_crypto_rng.reseed cs *)
9-
103
let () =
114
Format.printf "accel: %a\n%!"
125
(fun ppf -> List.iter @@ fun x ->

0 commit comments

Comments
 (0)