Skip to content

Commit 54d5100

Browse files
authored
Add CHAM lightweight block cipher (PR weidai11#670)
Add CHAM lightweight block cipher
1 parent 30b2de2 commit 54d5100

14 files changed

+702
-2
lines changed

Filelist.txt

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ ccm.cpp
4949
ccm.h
5050
chacha.cpp
5151
chacha.h
52+
cham.cpp
53+
cham.h
5254
channels.cpp
5355
channels.h
5456
cmac.cpp
@@ -436,6 +438,7 @@ TestVectors/blake2b.txt
436438
TestVectors/blake2s.txt
437439
TestVectors/aria.txt
438440
TestVectors/camellia.txt
441+
TestVectors/cham.txt
439442
TestVectors/ccm.txt
440443
TestVectors/chacha.txt
441444
TestVectors/cmac.txt

TestVectors/all.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Test: TestVectors/sm4.txt
3333
Test: TestVectors/lea.txt
3434
Test: TestVectors/simon.txt
3535
Test: TestVectors/speck.txt
36+
Test: TestVectors/cham.txt
3637
Test: TestVectors/salsa.txt
3738
Test: TestVectors/chacha.txt
3839
#Test: TestVectors/tls_chacha.txt

TestVectors/cham.txt

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
AlgorithmType: SymmetricCipher
2+
Name: CHAM-64/ECB
3+
#
4+
Source: CHAM paper, Appendix A, test vector 1
5+
Comment: CHAM-64/ECB, 128-bit key
6+
Key: 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e
7+
Plaintext: 1100 3322 5544 7766
8+
Ciphertext: 453c 63bc dcfa bf4e
9+
Test: Encrypt
10+
#
11+
Source: CHAM reference implementation
12+
Comment: CHAM-64/ECB, 128-bit key
13+
Key: 0277 0a9e a270 1fed 460c c269 9163 e519
14+
Plaintext: 704a 4e91 eb9b 688d
15+
Ciphertext: ceda d4dc 00e3 800d
16+
Test: Encrypt
17+
#
18+
Source: CHAM reference implementation
19+
Comment: CHAM-64/ECB, 128-bit key
20+
Key: 24cd a3e2 c167 92f3 40b6 0017 cabc 07c4
21+
Plaintext: 115a 31e5 ee65 87f7
22+
Ciphertext: e1af b96f 3079 4233
23+
Test: Encrypt
24+
#
25+
Source: CHAM reference implementation
26+
Comment: CHAM-64/ECB, 128-bit key
27+
Key: 0914 eef6 827c 21b9 c697 05ce b28b 7dd5
28+
Plaintext: e722 2e2b 0f2c ee49
29+
Ciphertext: 280d 763b 931b da81
30+
Test: Encrypt
31+
#
32+
Source: CHAM reference implementation
33+
Comment: CHAM-64/ECB, 128-bit key
34+
Key: 2fa2 fb02 1cd5 9124 ee27 1ec9 7307 6a13
35+
Plaintext: 9fc0 8c64 f9f9 8163
36+
Ciphertext: 0277 8604 1b15 8cb9
37+
Test: Encrypt
38+
#
39+
Source: CHAM reference implementation
40+
Comment: CHAM-64/ECB, 128-bit key
41+
Key: 6035 af8d 6d97 6a47 1bc9 cb88 1a4a f2aa
42+
Plaintext: 657b 5980 aad8 468b
43+
Ciphertext: 5684 2bf7 606d 67f8
44+
Test: Encrypt
45+
#
46+
Source: CHAM reference implementation
47+
Comment: CHAM-64/ECB, 128-bit key
48+
Key: be3a cf23 eda6 9014 023e 098b 37c3 9b9e
49+
Plaintext: ff83 911e 2f35 84a5
50+
Ciphertext: 9263 2bf9 9819 783a
51+
Test: Encrypt
52+
#
53+
Source: CHAM reference implementation
54+
Comment: CHAM-64/ECB, 128-bit key
55+
Key: ffde 8a15 21c5 fb5e b6b1 1ec9 05aa c629
56+
Plaintext: 7802 c7a5 d52f 1868
57+
Ciphertext: f810 fad0 80f0 19bd
58+
Test: Encrypt
59+
#
60+
Source: CHAM reference implementation
61+
Comment: CHAM-64/ECB, 128-bit key
62+
Key: fc25 b83f 5058 9cb6 fe7a 5d6c 1635 5cfd
63+
Plaintext: 1ab2 1791 a5d3 05aa
64+
Ciphertext: e733 fd94 c357 d36c
65+
Test: Encrypt
66+
#
67+
Source: CHAM reference implementation
68+
Comment: CHAM-64/ECB, 128-bit key
69+
Key: fae3 5e23 e357 3e33 4468 c725 80e5 4a6e
70+
Plaintext: 5dc5 c55f 6b8d 31e2
71+
Ciphertext: 5bc2 2475 f93f 6cc8
72+
Test: Encrypt
73+
74+
AlgorithmType: SymmetricCipher
75+
Name: CHAM-128/ECB
76+
#
77+
Source: CHAM paper, Appendix A, test vector 2
78+
Comment: CHAM-128/ECB, 128-bit key
79+
Key: 03020100 07060504 0b0a0908 0f0e0d0c
80+
Plaintext: 33221100 77665544 bbaa9988 ffeeddcc
81+
Ciphertext: c3746034 b55700c5 8d64ec32 489332f7
82+
Test: Encrypt
83+
#
84+
Source: CHAM reference implementation
85+
Comment: CHAM-128/ECB, 128-bit key
86+
Key: a37beb01 15c49898 906f6f1c 73f68cf3
87+
Plaintext: 463e4b34 efe3faa8 d8b74450 967f34d1
88+
Ciphertext: 30269e99 4d70c5de 7b0bc631 a96a1458
89+
Test: Encrypt
90+
#
91+
Source: CHAM reference implementation
92+
Comment: CHAM-128/ECB, 128-bit key
93+
Key: ad97ae34 49a65961 46872c23 08a85a00
94+
Plaintext: 7c241f66 85111245 83d76a6f 8498946b
95+
Ciphertext: 633b6cb9 00b390d8 d1bb84cb d84b9ccf
96+
Test: Encrypt
97+
#
98+
Source: CHAM reference implementation
99+
Comment: CHAM-128/ECB, 128-bit key
100+
Key: 012ddb51 d216a550 3b1632f3 69930aac
101+
Plaintext: 440a7ce0 23b8499f 991482fd e6069cbe
102+
Ciphertext: b2b21944 81c5becf 091d3c08 ee6d1749
103+
Test: Encrypt
104+
#
105+
Source: CHAM reference implementation
106+
Comment: CHAM-128/ECB, 128-bit key
107+
Key: dfd8192b cab7764c 12632c23 95c96b55
108+
Plaintext: a72c2040 1e652249 6ceb83be d90a2816
109+
Ciphertext: 0416aae7 302a5219 cd20a3b8 6d879c22
110+
Test: Encrypt
111+
#
112+
Source: CHAM reference implementation
113+
Comment: CHAM-128/ECB, 128-bit key
114+
Key: c3fe465e dff5a38c 308bcf68 a6d45ba7
115+
Plaintext: 91167a4b b9641eb2 15195841 f3301521
116+
Ciphertext: 36d1dd06 e42c583d 9aea8e58 08ee2f3b
117+
Test: Encrypt
118+
#
119+
Source: CHAM reference implementation
120+
Comment: CHAM-128/ECB, 128-bit key
121+
Key: e7365921 729a2e4b 5e9e2d42 6b53c079
122+
Plaintext: 9fd5fb98 d2de3459 42cf3edb 2104e849
123+
Ciphertext: 60f3dd59 406e579e e45a2191 526c5693
124+
Test: Encrypt
125+
#
126+
Source: CHAM reference implementation
127+
Comment: CHAM-128/ECB, 128-bit key
128+
Key: b880a315 e410aa2d 9d8686e4 ac033a6e
129+
Plaintext: 05251c25 354ded83 67d50c4c 4a73b66f
130+
Ciphertext: e3f879f5 8b41baf8 8b458da7 04343a03
131+
Test: Encrypt
132+
#
133+
Source: CHAM reference implementation
134+
Comment: CHAM-128/ECB, 128-bit key
135+
Key: f0cb7d27 58d7ac44 937b882d 526fb9f8
136+
Plaintext: 088ede84 315ef415 2e2e22b1 8b45e765
137+
Ciphertext: 4ff2532c 66a12b2e 869f476e aab2d53f
138+
Test: Encrypt
139+
#
140+
Source: CHAM reference implementation
141+
Comment: CHAM-128/ECB, 128-bit key
142+
Key: 28b841b2 9a5e552c e02170c8 fee72a87
143+
Plaintext: 0fc61c4c fa1db413 9d007659 39df2ba9
144+
Ciphertext: 6fd504e7 091aca2e 32c88718 3e40b4a4
145+
Test: Encrypt
146+
#
147+
Source: CHAM paper, Appendix A, test vector 3
148+
Comment: CHAM-128/ECB, 256-bit key
149+
Key: 03020100 07060504 0b0a0908 0f0e0d0c f3f2f1f0 f7f6f5f4 fbfaf9f8 fffefdfc
150+
Plaintext: 33221100 77665544 bbaa9988 ffeeddcc
151+
Ciphertext: a899c8a0 c929d55c ab670d38 0c4f7ac8
152+
Test: Encrypt
153+
#
154+
Source: CHAM reference implementation
155+
Comment: CHAM-128/ECB, 256-bit key
156+
Key: 4031c291 53a38799 8e0a6bad 6098a6c4 e4a852f8 7daf676e 873c3524 e1527db8
157+
Plaintext: aac76bc0 ec99e00e 9648a939 1a37c8db
158+
Ciphertext: c993c682 1545b60c 456af36c b97628e7
159+
Test: Encrypt
160+
#
161+
Source: CHAM reference implementation
162+
Comment: CHAM-128/ECB, 256-bit key
163+
Key: 0c7be271 0ee365ff 061b8e43 5dbc63e3 52a08866 634223c9 8f4bcc4f a1223aee
164+
Plaintext: 49eec4dd eb938769 a359a6bf f69353a9
165+
Ciphertext: 6252cf6f 6524f0ed 0b3a272a 33827bb4
166+
Test: Encrypt
167+
#
168+
Source: CHAM reference implementation
169+
Comment: CHAM-128/ECB, 256-bit key
170+
Key: 90c69c18 8fcac90f 7c061078 036f3279 5676641c 40358d9f d74867ca 5debd8fa
171+
Plaintext: c27e5d18 985bd57e 25b7164e 5acb6ceb
172+
Ciphertext: c7c15e12 2287fd3d 45875c14 629a042c
173+
Test: Encrypt
174+
#
175+
Source: CHAM reference implementation
176+
Comment: CHAM-128/ECB, 256-bit key
177+
Key: f7bae93e 170bbccd 42a1d993 a6247a9c ae609194 075045fc 95b22ad9 59e16c9c
178+
Plaintext: 87cc88e7 9f159afe b2e8967b ff1ddd8b
179+
Ciphertext: 0887e541 4b68e67f a46d19ff 948290b6
180+
Test: Encrypt
181+
#
182+
Source: CHAM reference implementation
183+
Comment: CHAM-128/ECB, 256-bit key
184+
Key: 15747f3e 359c8462 151d0e6d f06abade 06f246e1 c817332b 1fa9102a 52263db4
185+
Plaintext: 5c11eab6 3fa257df 7da90d0e 1bf46991
186+
Ciphertext: 3cabb22e 79c7ad8e d502abf8 74e7d3bf
187+
Test: Encrypt
188+
#
189+
Source: CHAM reference implementation
190+
Comment: CHAM-128/ECB, 256-bit key
191+
Key: 4c70d578 34042fbd 8f4b7c40 89ac864e 1dee8bac 4093f375 308aa073 655098f1
192+
Plaintext: 68c7097e ab6c6043 87d2bc67 41dece87
193+
Ciphertext: 362a9742 dd8238a8 d916409a 4a3c11a1
194+
Test: Encrypt
195+
#
196+
Source: CHAM reference implementation
197+
Comment: CHAM-128/ECB, 256-bit key
198+
Key: 073359a0 5e54c5f8 882ef21f 01be08d5 7d5c5b87 533059a5 204e2bcd 5652dfc5
199+
Plaintext: ef94e8fb 7bf2aa7c ac73ef0a 294ad1f8
200+
Ciphertext: 5914594d db44ba25 ac0bfc05 1b92a9fe
201+
Test: Encrypt
202+
#
203+
Source: CHAM reference implementation
204+
Comment: CHAM-128/ECB, 256-bit key
205+
Key: dc359e46 f5516d84 89885aee 191494fe 25350de0 69275496 1531e563 59f9e0ee
206+
Plaintext: d1c5fbd0 7d1e85fc 7922d741 6a5a44dc
207+
Ciphertext: bbe95a67 06b38ff2 898dfda8 41fe29c7
208+
Test: Encrypt
209+
#
210+
Source: CHAM reference implementation
211+
Comment: CHAM-128/ECB, 256-bit key
212+
Key: faf3682d cf6e656c 53bd8c06 de0f7f71 678c5a2d 34624762 d88daf37 21d5ad6c
213+
Plaintext: 55b32441 7a787fbc 41b91ab2 9a5bf734
214+
Ciphertext: 2a7dab0b 6769e989 61578998 7e4be9a7
215+
Test: Encrypt

bench1.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void Benchmark2(double t, double hertz)
592592
BenchMarkByName<SymmetricCipher>("Threefish-1024(1024)/CTR", 128);
593593
BenchMarkByName<SymmetricCipher>("Serpent/CTR");
594594
BenchMarkByName<SymmetricCipher>("CAST-128/CTR");
595-
BenchMarkByName<SymmetricCipher>("CAST-256/CTR");
595+
BenchMarkByName<SymmetricCipher>("CAST-256/CTR", 32);
596596
BenchMarkByName<SymmetricCipher>("RC6/CTR");
597597
BenchMarkByName<SymmetricCipher>("MARS/CTR");
598598
BenchMarkByName<SymmetricCipher>("SHACAL-2/CTR", 16);
@@ -614,6 +614,13 @@ void Benchmark2(double t, double hertz)
614614
BenchMarkByName<SymmetricCipher>("Kalyna-256/CTR", 32, "Kalyna-256(256)/CTR (256-bit key)");
615615
BenchMarkByName<SymmetricCipher>("Kalyna-256/CTR", 64, "Kalyna-256(512)/CTR (512-bit key)");
616616
BenchMarkByName<SymmetricCipher>("Kalyna-512/CTR", 64, "Kalyna-512(512)/CTR (512-bit key)");
617+
}
618+
619+
std::cout << "\n<TBODY style=\"background: yellow;\">";
620+
{
621+
BenchMarkByName<SymmetricCipher>("CHAM-64/CTR", 16, "CHAM-64(128)/CTR (128-bit key)");
622+
BenchMarkByName<SymmetricCipher>("CHAM-128/CTR", 16, "CHAM-128(128)/CTR (128-bit key)");
623+
BenchMarkByName<SymmetricCipher>("CHAM-128/CTR", 32, "CHAM-128(256)/CTR (256-bit key)");
617624

618625
BenchMarkByName<SymmetricCipher>("LEA-128/CTR", 16, "LEA-128(128)/CTR (128-bit key)");
619626
BenchMarkByName<SymmetricCipher>("LEA-128/CTR", 24, "LEA-128(192)/CTR (192-bit key)");
@@ -632,7 +639,7 @@ void Benchmark2(double t, double hertz)
632639
BenchMarkByName<SymmetricCipher>("SPECK-128/CTR", 32, "SPECK-128(256)/CTR (256-bit key)");
633640
}
634641

635-
std::cout << "\n<TBODY style=\"background: yellow;\">";
642+
std::cout << "\n<TBODY style=\"background: white;\">";
636643
{
637644
#if CRYPTOPP_AESNI_AVAILABLE
638645
if (HasCLMUL())

0 commit comments

Comments
 (0)