.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * AES CTR routines supporting the Power 7+ Nest Accelerators driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2011-2012 International Business Machines Inc. |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; version 2 only. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program; if not, write to the Free Software |
---|
17 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
18 | 6 | * |
---|
19 | 7 | * Author: Kent Yoder <yoder1@us.ibm.com> |
---|
20 | 8 | */ |
---|
.. | .. |
---|
31 | 19 | #include "nx.h" |
---|
32 | 20 | |
---|
33 | 21 | |
---|
34 | | -static int ctr_aes_nx_set_key(struct crypto_tfm *tfm, |
---|
35 | | - const u8 *in_key, |
---|
36 | | - unsigned int key_len) |
---|
| 22 | +static int ctr_aes_nx_set_key(struct crypto_skcipher *tfm, |
---|
| 23 | + const u8 *in_key, |
---|
| 24 | + unsigned int key_len) |
---|
37 | 25 | { |
---|
38 | | - struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
---|
| 26 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
39 | 27 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
---|
40 | 28 | |
---|
41 | 29 | nx_ctx_init(nx_ctx, HCOP_FC_AES); |
---|
.. | .. |
---|
63 | 51 | return 0; |
---|
64 | 52 | } |
---|
65 | 53 | |
---|
66 | | -static int ctr3686_aes_nx_set_key(struct crypto_tfm *tfm, |
---|
67 | | - const u8 *in_key, |
---|
68 | | - unsigned int key_len) |
---|
| 54 | +static int ctr3686_aes_nx_set_key(struct crypto_skcipher *tfm, |
---|
| 55 | + const u8 *in_key, |
---|
| 56 | + unsigned int key_len) |
---|
69 | 57 | { |
---|
70 | | - struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
---|
| 58 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
71 | 59 | |
---|
72 | 60 | if (key_len < CTR_RFC3686_NONCE_SIZE) |
---|
73 | 61 | return -EINVAL; |
---|
.. | .. |
---|
81 | 69 | return ctr_aes_nx_set_key(tfm, in_key, key_len); |
---|
82 | 70 | } |
---|
83 | 71 | |
---|
84 | | -static int ctr_aes_nx_crypt(struct blkcipher_desc *desc, |
---|
85 | | - struct scatterlist *dst, |
---|
86 | | - struct scatterlist *src, |
---|
87 | | - unsigned int nbytes) |
---|
| 72 | +static int ctr_aes_nx_crypt(struct skcipher_request *req, u8 *iv) |
---|
88 | 73 | { |
---|
89 | | - struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 74 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 75 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
90 | 76 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
---|
91 | 77 | unsigned long irq_flags; |
---|
92 | 78 | unsigned int processed = 0, to_process; |
---|
.. | .. |
---|
95 | 81 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
---|
96 | 82 | |
---|
97 | 83 | do { |
---|
98 | | - to_process = nbytes - processed; |
---|
| 84 | + to_process = req->cryptlen - processed; |
---|
99 | 85 | |
---|
100 | | - rc = nx_build_sg_lists(nx_ctx, desc, dst, src, &to_process, |
---|
101 | | - processed, csbcpb->cpb.aes_ctr.iv); |
---|
| 86 | + rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src, |
---|
| 87 | + &to_process, processed, |
---|
| 88 | + csbcpb->cpb.aes_ctr.iv); |
---|
102 | 89 | if (rc) |
---|
103 | 90 | goto out; |
---|
104 | 91 | |
---|
.. | .. |
---|
108 | 95 | } |
---|
109 | 96 | |
---|
110 | 97 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, |
---|
111 | | - desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); |
---|
| 98 | + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); |
---|
112 | 99 | if (rc) |
---|
113 | 100 | goto out; |
---|
114 | 101 | |
---|
115 | | - memcpy(desc->info, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE); |
---|
| 102 | + memcpy(iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE); |
---|
116 | 103 | |
---|
117 | 104 | atomic_inc(&(nx_ctx->stats->aes_ops)); |
---|
118 | 105 | atomic64_add(csbcpb->csb.processed_byte_count, |
---|
119 | 106 | &(nx_ctx->stats->aes_bytes)); |
---|
120 | 107 | |
---|
121 | 108 | processed += to_process; |
---|
122 | | - } while (processed < nbytes); |
---|
| 109 | + } while (processed < req->cryptlen); |
---|
123 | 110 | out: |
---|
124 | 111 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); |
---|
125 | 112 | return rc; |
---|
126 | 113 | } |
---|
127 | 114 | |
---|
128 | | -static int ctr3686_aes_nx_crypt(struct blkcipher_desc *desc, |
---|
129 | | - struct scatterlist *dst, |
---|
130 | | - struct scatterlist *src, |
---|
131 | | - unsigned int nbytes) |
---|
| 115 | +static int ctr3686_aes_nx_crypt(struct skcipher_request *req) |
---|
132 | 116 | { |
---|
133 | | - struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 117 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 118 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
134 | 119 | u8 iv[16]; |
---|
135 | 120 | |
---|
136 | | - memcpy(iv, nx_ctx->priv.ctr.nonce, CTR_RFC3686_IV_SIZE); |
---|
137 | | - memcpy(iv + CTR_RFC3686_NONCE_SIZE, |
---|
138 | | - desc->info, CTR_RFC3686_IV_SIZE); |
---|
| 121 | + memcpy(iv, nx_ctx->priv.ctr.nonce, CTR_RFC3686_NONCE_SIZE); |
---|
| 122 | + memcpy(iv + CTR_RFC3686_NONCE_SIZE, req->iv, CTR_RFC3686_IV_SIZE); |
---|
139 | 123 | iv[12] = iv[13] = iv[14] = 0; |
---|
140 | 124 | iv[15] = 1; |
---|
141 | 125 | |
---|
142 | | - desc->info = iv; |
---|
143 | | - |
---|
144 | | - return ctr_aes_nx_crypt(desc, dst, src, nbytes); |
---|
| 126 | + return ctr_aes_nx_crypt(req, iv); |
---|
145 | 127 | } |
---|
146 | 128 | |
---|
147 | | -struct crypto_alg nx_ctr3686_aes_alg = { |
---|
148 | | - .cra_name = "rfc3686(ctr(aes))", |
---|
149 | | - .cra_driver_name = "rfc3686-ctr-aes-nx", |
---|
150 | | - .cra_priority = 300, |
---|
151 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
152 | | - .cra_blocksize = 1, |
---|
153 | | - .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
---|
154 | | - .cra_type = &crypto_blkcipher_type, |
---|
155 | | - .cra_module = THIS_MODULE, |
---|
156 | | - .cra_init = nx_crypto_ctx_aes_ctr_init, |
---|
157 | | - .cra_exit = nx_crypto_ctx_exit, |
---|
158 | | - .cra_blkcipher = { |
---|
159 | | - .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE, |
---|
160 | | - .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE, |
---|
161 | | - .ivsize = CTR_RFC3686_IV_SIZE, |
---|
162 | | - .geniv = "seqiv", |
---|
163 | | - .setkey = ctr3686_aes_nx_set_key, |
---|
164 | | - .encrypt = ctr3686_aes_nx_crypt, |
---|
165 | | - .decrypt = ctr3686_aes_nx_crypt, |
---|
166 | | - } |
---|
| 129 | +struct skcipher_alg nx_ctr3686_aes_alg = { |
---|
| 130 | + .base.cra_name = "rfc3686(ctr(aes))", |
---|
| 131 | + .base.cra_driver_name = "rfc3686-ctr-aes-nx", |
---|
| 132 | + .base.cra_priority = 300, |
---|
| 133 | + .base.cra_blocksize = 1, |
---|
| 134 | + .base.cra_ctxsize = sizeof(struct nx_crypto_ctx), |
---|
| 135 | + .base.cra_module = THIS_MODULE, |
---|
| 136 | + .init = nx_crypto_ctx_aes_ctr_init, |
---|
| 137 | + .exit = nx_crypto_ctx_skcipher_exit, |
---|
| 138 | + .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE, |
---|
| 139 | + .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE, |
---|
| 140 | + .ivsize = CTR_RFC3686_IV_SIZE, |
---|
| 141 | + .setkey = ctr3686_aes_nx_set_key, |
---|
| 142 | + .encrypt = ctr3686_aes_nx_crypt, |
---|
| 143 | + .decrypt = ctr3686_aes_nx_crypt, |
---|
| 144 | + .chunksize = AES_BLOCK_SIZE, |
---|
167 | 145 | }; |
---|