Blame view
crypto/cbc.c
2.23 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
db131ef90 [CRYPTO] cipher: ... |
2 3 4 |
/* * CBC: Cipher Block Chaining mode * |
cc868d82a crypto: cbc - Exp... |
5 |
* Copyright (c) 2006-2016 Herbert Xu <herbert@gondor.apana.org.au> |
db131ef90 [CRYPTO] cipher: ... |
6 |
*/ |
e6c2e65c7 crypto: cbc - Pro... |
7 |
#include <crypto/algapi.h> |
cc868d82a crypto: cbc - Exp... |
8 |
#include <crypto/cbc.h> |
79c65d179 crypto: cbc - Con... |
9 |
#include <crypto/internal/skcipher.h> |
db131ef90 [CRYPTO] cipher: ... |
10 11 12 |
#include <linux/err.h> #include <linux/init.h> #include <linux/kernel.h> |
50b6544e1 [CRYPTO] cbc: Req... |
13 |
#include <linux/log2.h> |
db131ef90 [CRYPTO] cipher: ... |
14 |
#include <linux/module.h> |
db131ef90 [CRYPTO] cipher: ... |
15 |
|
79c65d179 crypto: cbc - Con... |
16 17 18 |
static inline void crypto_cbc_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) { |
a5a84a9db crypto: cbc - con... |
19 |
crypto_cipher_encrypt_one(skcipher_cipher_simple(tfm), dst, src); |
79c65d179 crypto: cbc - Con... |
20 21 22 |
} static int crypto_cbc_encrypt(struct skcipher_request *req) |
db131ef90 [CRYPTO] cipher: ... |
23 |
{ |
79c65d179 crypto: cbc - Con... |
24 25 |
return crypto_cbc_encrypt_walk(req, crypto_cbc_encrypt_one); } |
79c65d179 crypto: cbc - Con... |
26 27 28 |
static inline void crypto_cbc_decrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) { |
a5a84a9db crypto: cbc - con... |
29 |
crypto_cipher_decrypt_one(skcipher_cipher_simple(tfm), dst, src); |
79c65d179 crypto: cbc - Con... |
30 31 32 33 34 35 |
} static int crypto_cbc_decrypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct skcipher_walk walk; |
db131ef90 [CRYPTO] cipher: ... |
36 |
int err; |
79c65d179 crypto: cbc - Con... |
37 |
err = skcipher_walk_virt(&walk, req, false); |
db131ef90 [CRYPTO] cipher: ... |
38 |
|
79c65d179 crypto: cbc - Con... |
39 40 41 42 |
while (walk.nbytes) { err = crypto_cbc_decrypt_blocks(&walk, tfm, crypto_cbc_decrypt_one); err = skcipher_walk_done(&walk, err); |
db131ef90 [CRYPTO] cipher: ... |
43 44 45 46 |
} return err; } |
79c65d179 crypto: cbc - Con... |
47 48 49 |
static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb) { struct skcipher_instance *inst; |
db131ef90 [CRYPTO] cipher: ... |
50 |
struct crypto_alg *alg; |
ebc610e5b [CRYPTO] template... |
51 |
int err; |
b3c16bfc6 crypto: skcipher ... |
52 |
inst = skcipher_alloc_instance_simple(tmpl, tb); |
a5a84a9db crypto: cbc - con... |
53 54 |
if (IS_ERR(inst)) return PTR_ERR(inst); |
50b6544e1 [CRYPTO] cbc: Req... |
55 |
|
b3c16bfc6 crypto: skcipher ... |
56 |
alg = skcipher_ialg_simple(inst); |
79c65d179 crypto: cbc - Con... |
57 58 |
err = -EINVAL; if (!is_power_of_2(alg->cra_blocksize)) |
a5a84a9db crypto: cbc - con... |
59 |
goto out_free_inst; |
db131ef90 [CRYPTO] cipher: ... |
60 |
|
79c65d179 crypto: cbc - Con... |
61 62 |
inst->alg.encrypt = crypto_cbc_encrypt; inst->alg.decrypt = crypto_cbc_decrypt; |
db131ef90 [CRYPTO] cipher: ... |
63 |
|
79c65d179 crypto: cbc - Con... |
64 |
err = skcipher_register_instance(tmpl, inst); |
b3c16bfc6 crypto: skcipher ... |
65 |
if (err) { |
a5a84a9db crypto: cbc - con... |
66 |
out_free_inst: |
b3c16bfc6 crypto: skcipher ... |
67 68 |
inst->free(inst); } |
a5a84a9db crypto: cbc - con... |
69 |
return err; |
db131ef90 [CRYPTO] cipher: ... |
70 71 72 73 |
} static struct crypto_template crypto_cbc_tmpl = { .name = "cbc", |
79c65d179 crypto: cbc - Con... |
74 |
.create = crypto_cbc_create, |
db131ef90 [CRYPTO] cipher: ... |
75 76 77 78 79 80 81 82 83 84 85 86 |
.module = THIS_MODULE, }; static int __init crypto_cbc_module_init(void) { return crypto_register_template(&crypto_cbc_tmpl); } static void __exit crypto_cbc_module_exit(void) { crypto_unregister_template(&crypto_cbc_tmpl); } |
c4741b230 crypto: run initc... |
87 |
subsys_initcall(crypto_cbc_module_init); |
db131ef90 [CRYPTO] cipher: ... |
88 89 90 |
module_exit(crypto_cbc_module_exit); MODULE_LICENSE("GPL"); |
a5a84a9db crypto: cbc - con... |
91 |
MODULE_DESCRIPTION("CBC block cipher mode of operation"); |
4943ba16b crypto: include c... |
92 |
MODULE_ALIAS_CRYPTO("cbc"); |