Source
1
1
/*
2
-
* ChaCha20 (RFC7539) and XChaCha20 stream cipher algorithms
2
+
* ChaCha and XChaCha stream ciphers, including ChaCha20 (RFC7539)
3
3
*
4
4
* Copyright (C) 2015 Martin Willi
5
5
* Copyright (C) 2018 Google LLC
6
6
*
7
7
* This program is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License as published by
9
9
* the Free Software Foundation; either version 2 of the License, or
10
10
* (at your option) any later version.
11
11
*/
12
12
99
99
return 0;
100
100
}
101
101
102
102
int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
103
103
unsigned int keysize)
104
104
{
105
105
return chacha_setkey(tfm, key, keysize, 20);
106
106
}
107
107
EXPORT_SYMBOL_GPL(crypto_chacha20_setkey);
108
108
109
+
int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key,
110
+
unsigned int keysize)
111
+
{
112
+
return chacha_setkey(tfm, key, keysize, 12);
113
+
}
114
+
EXPORT_SYMBOL_GPL(crypto_chacha12_setkey);
115
+
109
116
int crypto_chacha_crypt(struct skcipher_request *req)
110
117
{
111
118
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
112
119
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
113
120
114
121
return chacha_stream_xor(req, ctx, req->iv);
115
122
}
116
123
EXPORT_SYMBOL_GPL(crypto_chacha_crypt);
117
124
118
125
int crypto_xchacha_crypt(struct skcipher_request *req)
161
168
.base.cra_ctxsize = sizeof(struct chacha_ctx),
162
169
.base.cra_module = THIS_MODULE,
163
170
164
171
.min_keysize = CHACHA_KEY_SIZE,
165
172
.max_keysize = CHACHA_KEY_SIZE,
166
173
.ivsize = XCHACHA_IV_SIZE,
167
174
.chunksize = CHACHA_BLOCK_SIZE,
168
175
.setkey = crypto_chacha20_setkey,
169
176
.encrypt = crypto_xchacha_crypt,
170
177
.decrypt = crypto_xchacha_crypt,
178
+
}, {
179
+
.base.cra_name = "xchacha12",
180
+
.base.cra_driver_name = "xchacha12-generic",
181
+
.base.cra_priority = 100,
182
+
.base.cra_blocksize = 1,
183
+
.base.cra_ctxsize = sizeof(struct chacha_ctx),
184
+
.base.cra_module = THIS_MODULE,
185
+
186
+
.min_keysize = CHACHA_KEY_SIZE,
187
+
.max_keysize = CHACHA_KEY_SIZE,
188
+
.ivsize = XCHACHA_IV_SIZE,
189
+
.chunksize = CHACHA_BLOCK_SIZE,
190
+
.setkey = crypto_chacha12_setkey,
191
+
.encrypt = crypto_xchacha_crypt,
192
+
.decrypt = crypto_xchacha_crypt,
171
193
}
172
194
};
173
195
174
196
static int __init chacha_generic_mod_init(void)
175
197
{
176
198
return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
177
199
}
178
200
179
201
static void __exit chacha_generic_mod_fini(void)
180
202
{
184
206
module_init(chacha_generic_mod_init);
185
207
module_exit(chacha_generic_mod_fini);
186
208
187
209
MODULE_LICENSE("GPL");
188
210
MODULE_AUTHOR("Martin Willi <martin@strongswan.org>");
189
211
MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (generic)");
190
212
MODULE_ALIAS_CRYPTO("chacha20");
191
213
MODULE_ALIAS_CRYPTO("chacha20-generic");
192
214
MODULE_ALIAS_CRYPTO("xchacha20");
193
215
MODULE_ALIAS_CRYPTO("xchacha20-generic");
216
+
MODULE_ALIAS_CRYPTO("xchacha12");
217
+
MODULE_ALIAS_CRYPTO("xchacha12-generic");