24
24
*/
25
25
26
26
#include <asm/unaligned.h>
27
+ #include <crypto/speck.h>
27
28
#include <linux/bitops.h>
28
29
#include <linux/crypto.h>
29
30
#include <linux/init.h>
30
31
#include <linux/module.h>
31
32
32
33
/* Speck128 */
33
34
34
- #define SPECK128_BLOCK_SIZE 16
35
-
36
- #define SPECK128_128_KEY_SIZE 16
37
- #define SPECK128_128_NROUNDS 32
38
-
39
- #define SPECK128_192_KEY_SIZE 24
40
- #define SPECK128_192_NROUNDS 33
41
-
42
- #define SPECK128_256_KEY_SIZE 32
43
- #define SPECK128_256_NROUNDS 34
44
-
45
- struct speck128_tfm_ctx {
46
- u64 round_keys [SPECK128_256_NROUNDS ];
47
- int nrounds ;
48
- };
49
-
50
35
static __always_inline void speck128_round (u64 * x , u64 * y , u64 k )
51
36
{
52
37
* x = ror64 (* x , 8 );
@@ -65,9 +50,9 @@ static __always_inline void speck128_unround(u64 *x, u64 *y, u64 k)
65
50
* x = rol64 (* x , 8 );
66
51
}
67
52
68
- static void speck128_encrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
53
+ void crypto_speck128_encrypt (const struct speck128_tfm_ctx * ctx ,
54
+ u8 * out , const u8 * in )
69
55
{
70
- const struct speck128_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
71
56
u64 y = get_unaligned_le64 (in );
72
57
u64 x = get_unaligned_le64 (in + 8 );
73
58
int i ;
@@ -78,10 +63,16 @@ static void speck128_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
78
63
put_unaligned_le64 (y , out );
79
64
put_unaligned_le64 (x , out + 8 );
80
65
}
66
+ EXPORT_SYMBOL_GPL (crypto_speck128_encrypt );
81
67
82
- static void speck128_decrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
68
+ static void speck128_encrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
69
+ {
70
+ crypto_speck128_encrypt (crypto_tfm_ctx (tfm ), out , in );
71
+ }
72
+
73
+ void crypto_speck128_decrypt (const struct speck128_tfm_ctx * ctx ,
74
+ u8 * out , const u8 * in )
83
75
{
84
- const struct speck128_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
85
76
u64 y = get_unaligned_le64 (in );
86
77
u64 x = get_unaligned_le64 (in + 8 );
87
78
int i ;
@@ -92,11 +83,16 @@ static void speck128_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
92
83
put_unaligned_le64 (y , out );
93
84
put_unaligned_le64 (x , out + 8 );
94
85
}
86
+ EXPORT_SYMBOL_GPL (crypto_speck128_decrypt );
95
87
96
- static int speck128_setkey (struct crypto_tfm * tfm , const u8 * key ,
88
+ static void speck128_decrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
89
+ {
90
+ crypto_speck128_decrypt (crypto_tfm_ctx (tfm ), out , in );
91
+ }
92
+
93
+ int crypto_speck128_setkey (struct speck128_tfm_ctx * ctx , const u8 * key ,
97
94
unsigned int keylen )
98
95
{
99
- struct speck128_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
100
96
u64 l [3 ];
101
97
u64 k ;
102
98
int i ;
@@ -138,21 +134,15 @@ static int speck128_setkey(struct crypto_tfm *tfm, const u8 *key,
138
134
139
135
return 0 ;
140
136
}
137
+ EXPORT_SYMBOL_GPL (crypto_speck128_setkey );
141
138
142
- /* Speck64 */
143
-
144
- #define SPECK64_BLOCK_SIZE 8
145
-
146
- #define SPECK64_96_KEY_SIZE 12
147
- #define SPECK64_96_NROUNDS 26
148
-
149
- #define SPECK64_128_KEY_SIZE 16
150
- #define SPECK64_128_NROUNDS 27
139
+ static int speck128_setkey (struct crypto_tfm * tfm , const u8 * key ,
140
+ unsigned int keylen )
141
+ {
142
+ return crypto_speck128_setkey (crypto_tfm_ctx (tfm ), key , keylen );
143
+ }
151
144
152
- struct speck64_tfm_ctx {
153
- u32 round_keys [SPECK64_128_NROUNDS ];
154
- int nrounds ;
155
- };
145
+ /* Speck64 */
156
146
157
147
static __always_inline void speck64_round (u32 * x , u32 * y , u32 k )
158
148
{
@@ -172,9 +162,9 @@ static __always_inline void speck64_unround(u32 *x, u32 *y, u32 k)
172
162
* x = rol32 (* x , 8 );
173
163
}
174
164
175
- static void speck64_encrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
165
+ void crypto_speck64_encrypt (const struct speck64_tfm_ctx * ctx ,
166
+ u8 * out , const u8 * in )
176
167
{
177
- const struct speck64_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
178
168
u32 y = get_unaligned_le32 (in );
179
169
u32 x = get_unaligned_le32 (in + 4 );
180
170
int i ;
@@ -185,10 +175,16 @@ static void speck64_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
185
175
put_unaligned_le32 (y , out );
186
176
put_unaligned_le32 (x , out + 4 );
187
177
}
178
+ EXPORT_SYMBOL_GPL (crypto_speck64_encrypt );
188
179
189
- static void speck64_decrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
180
+ static void speck64_encrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
181
+ {
182
+ crypto_speck64_encrypt (crypto_tfm_ctx (tfm ), out , in );
183
+ }
184
+
185
+ void crypto_speck64_decrypt (const struct speck64_tfm_ctx * ctx ,
186
+ u8 * out , const u8 * in )
190
187
{
191
- const struct speck64_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
192
188
u32 y = get_unaligned_le32 (in );
193
189
u32 x = get_unaligned_le32 (in + 4 );
194
190
int i ;
@@ -199,11 +195,16 @@ static void speck64_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
199
195
put_unaligned_le32 (y , out );
200
196
put_unaligned_le32 (x , out + 4 );
201
197
}
198
+ EXPORT_SYMBOL_GPL (crypto_speck64_decrypt );
202
199
203
- static int speck64_setkey (struct crypto_tfm * tfm , const u8 * key ,
200
+ static void speck64_decrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
201
+ {
202
+ crypto_speck64_decrypt (crypto_tfm_ctx (tfm ), out , in );
203
+ }
204
+
205
+ int crypto_speck64_setkey (struct speck64_tfm_ctx * ctx , const u8 * key ,
204
206
unsigned int keylen )
205
207
{
206
- struct speck64_tfm_ctx * ctx = crypto_tfm_ctx (tfm );
207
208
u32 l [3 ];
208
209
u32 k ;
209
210
int i ;
@@ -236,6 +237,13 @@ static int speck64_setkey(struct crypto_tfm *tfm, const u8 *key,
236
237
237
238
return 0 ;
238
239
}
240
+ EXPORT_SYMBOL_GPL (crypto_speck64_setkey );
241
+
242
+ static int speck64_setkey (struct crypto_tfm * tfm , const u8 * key ,
243
+ unsigned int keylen )
244
+ {
245
+ return crypto_speck64_setkey (crypto_tfm_ctx (tfm ), key , keylen );
246
+ }
239
247
240
248
/* Algorithm definitions */
241
249
0 commit comments