Mercurial > dropbear
annotate libtomcrypt/src/ciphers/multi2.c @ 1938:77bc00dcc19f default tip main master
Bump version to 2022.82
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 01 Apr 2022 14:43:27 +0800 |
parents | 6dba84798cd5 |
children |
rev | line source |
---|---|
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 /** |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 @file multi2.c |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 Multi-2 implementation (not public domain, hence the default disable) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 #include "tomcrypt.h" |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 #ifdef LTC_MULTI2 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 static void pi1(ulong32 *p) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 p[1] ^= p[0]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 static void pi2(ulong32 *p, ulong32 *k) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 ulong32 t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 t = (p[1] + k[0]) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 t = (ROL(t, 1) + t - 1) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 t = (ROL(t, 4) ^ t) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 p[0] ^= t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 static void pi3(ulong32 *p, ulong32 *k) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 ulong32 t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 t = p[0] + k[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 t = (ROL(t, 8) ^ t) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 t = (t + k[2]) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 t = (ROL(t, 1) - t) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 t = ROL(t, 16) ^ (p[0] | t); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 p[1] ^= t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 static void pi4(ulong32 *p, ulong32 *k) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 ulong32 t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 t = (p[1] + k[3]) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 p[0] ^= t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 static void setup(ulong32 *dk, ulong32 *k, ulong32 *uk) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 int n, t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 ulong32 p[2]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 p[0] = dk[0]; p[1] = dk[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
59 t = 4; |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 n = 0; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 pi1(p); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 pi2(p, k); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 uk[n++] = p[0]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 pi3(p, k); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 uk[n++] = p[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 pi4(p, k); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 uk[n++] = p[0]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 pi1(p); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 uk[n++] = p[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 pi2(p, k+t); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 uk[n++] = p[0]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 pi3(p, k+t); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 uk[n++] = p[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 pi4(p, k+t); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 uk[n++] = p[0]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 pi1(p); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 uk[n++] = p[1]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 static void encrypt(ulong32 *p, int N, ulong32 *uk) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 int n, t; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 for (t = n = 0; ; ) { |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
84 pi1(p); if (++n == N) break; |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 pi2(p, uk+t); if (++n == N) break; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 pi3(p, uk+t); if (++n == N) break; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 pi4(p, uk+t); if (++n == N) break; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 t ^= 4; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 } |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
90 } |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 static void decrypt(ulong32 *p, int N, ulong32 *uk) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 int n, t; |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
95 for (t = 4*(((N-1)>>2)&1), n = N; ; ) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
96 switch (n<=4 ? n : ((n-1)%4)+1) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
97 case 4: pi4(p, uk+t); --n; /* FALLTHROUGH */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
98 case 3: pi3(p, uk+t); --n; /* FALLTHROUGH */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
99 case 2: pi2(p, uk+t); --n; /* FALLTHROUGH */ |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 case 1: pi1(p); --n; break; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 case 0: return; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 t ^= 4; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 } |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
105 } |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 const struct ltc_cipher_descriptor multi2_desc = { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 "multi2", |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 22, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 40, 40, 8, 128, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 &multi2_setup, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 &multi2_ecb_encrypt, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 &multi2_ecb_decrypt, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 &multi2_test, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 &multi2_done, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 &multi2_keysize, |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
117 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 }; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 ulong32 sk[8], dk[2]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 int x; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 LTC_ARGCHK(key != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 LTC_ARGCHK(skey != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 if (keylen != 40) return CRYPT_INVALID_KEYSIZE; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 if (num_rounds == 0) num_rounds = 128; |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
130 |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 skey->multi2.N = num_rounds; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 for (x = 0; x < 8; x++) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 LOAD32H(sk[x], key + x*4); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 LOAD32H(dk[0], key + 32); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 LOAD32H(dk[1], key + 36); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 setup(dk, sk, skey->multi2.uk); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 zeromem(sk, sizeof(sk)); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 zeromem(dk, sizeof(dk)); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 return CRYPT_OK; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 /** |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 Encrypts a block of text with multi2 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 @param pt The input plaintext (8 bytes) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 @param ct The output ciphertext (8 bytes) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 @param skey The key as scheduled |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 @return CRYPT_OK if successful |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 ulong32 p[2]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 LTC_ARGCHK(pt != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 LTC_ARGCHK(ct != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 LTC_ARGCHK(skey != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 LOAD32H(p[0], pt); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 LOAD32H(p[1], pt+4); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 encrypt(p, skey->multi2.N, skey->multi2.uk); |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
160 STORE32H(p[0], ct); |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 STORE32H(p[1], ct+4); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 return CRYPT_OK; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 /** |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 Decrypts a block of text with multi2 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 @param ct The input ciphertext (8 bytes) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 @param pt The output plaintext (8 bytes) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 @param skey The key as scheduled |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 @return CRYPT_OK if successful |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 ulong32 p[2]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 LTC_ARGCHK(pt != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 LTC_ARGCHK(ct != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 LTC_ARGCHK(skey != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 LOAD32H(p[0], ct); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 LOAD32H(p[1], ct+4); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
180 decrypt(p, skey->multi2.N, skey->multi2.uk); |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
181 STORE32H(p[0], pt); |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 STORE32H(p[1], pt+4); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 return CRYPT_OK; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 /** |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
187 Performs a self-test of the multi2 block cipher |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
189 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 int multi2_test(void) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
192 static const struct { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 unsigned char key[40]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 unsigned char pt[8], ct[8]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 int rounds; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 } tests[] = { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
198 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
199 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
201 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
206 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
207 0x00, 0x00, 0x00, 0x00, |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
208 |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
209 0x01, 0x23, 0x45, 0x67, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 0x89, 0xAB, 0xCD, 0xEF |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 0x00, 0x00, 0x00, 0x00, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 0x00, 0x00, 0x00, 0x01, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 0xf8, 0x94, 0x40, 0x84, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
218 0x5e, 0x11, 0xcf, 0x89 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 128, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 0x35, 0x91, 0x9d, 0x96, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 0x07, 0x02, 0xe2, 0xce, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 0x8d, 0x0b, 0x58, 0x3c, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 0xc9, 0xc8, 0x9d, 0x59, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 0xa2, 0xae, 0x96, 0x4e, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 0x87, 0x82, 0x45, 0xed, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 0x3f, 0x2e, 0x62, 0xd6, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 0x36, 0x35, 0xd0, 0x67, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 0xb1, 0x27, 0xb9, 0x06, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 0xe7, 0x56, 0x22, 0x38, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 }, |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
236 { |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 0x1f, 0xb4, 0x60, 0x60, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 0xd0, 0xb3, 0x4f, 0xa5 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
240 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
241 0xca, 0x84, 0xa9, 0x34, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 0x75, 0xc8, 0x60, 0xe5 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 }, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 216, |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 }; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
247 unsigned char buf[8]; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
248 symmetric_key skey; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
249 int err, x; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
250 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
251 for (x = 1; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
252 if ((err = multi2_setup(tests[x].key, 40, tests[x].rounds, &skey)) != CRYPT_OK) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 return err; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 if ((err = multi2_ecb_encrypt(tests[x].pt, buf, &skey)) != CRYPT_OK) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 return err; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
259 if (compare_testvector(buf, 8, tests[x].ct, 8, "Multi2 Encrypt", x)) { |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 return CRYPT_FAIL_TESTVECTOR; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 } |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
262 |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 if ((err = multi2_ecb_decrypt(buf, buf, &skey)) != CRYPT_OK) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 return err; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
265 } |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
266 if (compare_testvector(buf, 8, tests[x].pt, 8, "Multi2 Decrypt", x)) { |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 return CRYPT_FAIL_TESTVECTOR; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
268 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 } |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
270 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
271 for (x = 128; x < 256; ++x) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
272 unsigned char ct[8]; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
273 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
274 if ((err = multi2_setup(tests[0].key, 40, x, &skey)) != CRYPT_OK) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
275 return err; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
276 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
277 if ((err = multi2_ecb_encrypt(tests[0].pt, ct, &skey)) != CRYPT_OK) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
278 return err; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
279 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
280 if ((err = multi2_ecb_decrypt(ct, buf, &skey)) != CRYPT_OK) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
281 return err; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
282 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
283 if (compare_testvector(buf, 8, tests[0].pt, 8, "Multi2 Rounds", x)) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
284 return CRYPT_FAIL_TESTVECTOR; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
285 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
286 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
287 |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 return CRYPT_OK; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
291 /** Terminate the context |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 @param skey The scheduled key |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
293 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
294 void multi2_done(symmetric_key *skey) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
295 { |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
296 LTC_UNUSED_PARAM(skey); |
1435
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
297 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
298 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
299 /** |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
300 Gets suitable key size |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
301 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
302 @return CRYPT_OK if the input key size is acceptable. |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
303 */ |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
304 int multi2_keysize(int *keysize) |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
305 { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
306 LTC_ARGCHK(keysize != NULL); |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
307 if (*keysize >= 40) { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
308 *keysize = 40; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
309 } else { |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
310 return CRYPT_INVALID_KEYSIZE; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
311 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
312 return CRYPT_OK; |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
313 } |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
314 |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
315 #endif |
f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
316 |
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
317 /* ref: $Format:%D$ */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
318 /* git commit: $Format:%H$ */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
1435
diff
changeset
|
319 /* commit time: $Format:%ai$ */ |