aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/xcbc.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/xcbc.c')
-rw-r--r--crypto/xcbc.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/crypto/xcbc.c b/crypto/xcbc.c
index 9347eb6bcf69..53e8ccbf0f5f 100644
--- a/crypto/xcbc.c
+++ b/crypto/xcbc.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/crypto.h> 22#include <linux/crypto.h>
23#include <linux/err.h> 23#include <linux/err.h>
24#include <linux/hardirq.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/mm.h> 26#include <linux/mm.h>
26#include <linux/rtnetlink.h> 27#include <linux/rtnetlink.h>
@@ -47,7 +48,7 @@ static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
47 * +------------------------ 48 * +------------------------
48 */ 49 */
49struct crypto_xcbc_ctx { 50struct crypto_xcbc_ctx {
50 struct crypto_tfm *child; 51 struct crypto_cipher *child;
51 u8 *odds; 52 u8 *odds;
52 u8 *prev; 53 u8 *prev;
53 u8 *key; 54 u8 *key;
@@ -75,8 +76,7 @@ static int _crypto_xcbc_digest_setkey(struct crypto_hash *parent,
75 if ((err = crypto_cipher_setkey(ctx->child, ctx->key, ctx->keylen))) 76 if ((err = crypto_cipher_setkey(ctx->child, ctx->key, ctx->keylen)))
76 return err; 77 return err;
77 78
78 ctx->child->__crt_alg->cra_cipher.cia_encrypt(ctx->child, key1, 79 crypto_cipher_encrypt_one(ctx->child, key1, ctx->consts);
79 ctx->consts);
80 80
81 return crypto_cipher_setkey(ctx->child, key1, bs); 81 return crypto_cipher_setkey(ctx->child, key1, bs);
82} 82}
@@ -86,7 +86,7 @@ static int crypto_xcbc_digest_setkey(struct crypto_hash *parent,
86{ 86{
87 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent); 87 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
88 88
89 if (keylen != crypto_tfm_alg_blocksize(ctx->child)) 89 if (keylen != crypto_cipher_blocksize(ctx->child))
90 return -EINVAL; 90 return -EINVAL;
91 91
92 ctx->keylen = keylen; 92 ctx->keylen = keylen;
@@ -108,13 +108,13 @@ static int crypto_xcbc_digest_init(struct hash_desc *pdesc)
108 return 0; 108 return 0;
109} 109}
110 110
111static int crypto_xcbc_digest_update(struct hash_desc *pdesc, 111static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
112 struct scatterlist *sg, 112 struct scatterlist *sg,
113 unsigned int nbytes) 113 unsigned int nbytes)
114{ 114{
115 struct crypto_hash *parent = pdesc->tfm; 115 struct crypto_hash *parent = pdesc->tfm;
116 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent); 116 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
117 struct crypto_tfm *tfm = ctx->child; 117 struct crypto_cipher *tfm = ctx->child;
118 int bs = crypto_hash_blocksize(parent); 118 int bs = crypto_hash_blocksize(parent);
119 unsigned int i = 0; 119 unsigned int i = 0;
120 120
@@ -142,7 +142,7 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
142 offset += len; 142 offset += len;
143 143
144 crypto_kunmap(p, 0); 144 crypto_kunmap(p, 0);
145 crypto_yield(tfm->crt_flags); 145 crypto_yield(pdesc->flags);
146 continue; 146 continue;
147 } 147 }
148 148
@@ -152,7 +152,7 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
152 p += bs - ctx->len; 152 p += bs - ctx->len;
153 153
154 ctx->xor(ctx->prev, ctx->odds, bs); 154 ctx->xor(ctx->prev, ctx->odds, bs);
155 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, ctx->prev, ctx->prev); 155 crypto_cipher_encrypt_one(tfm, ctx->prev, ctx->prev);
156 156
157 /* clearing the length */ 157 /* clearing the length */
158 ctx->len = 0; 158 ctx->len = 0;
@@ -160,7 +160,8 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
160 /* encrypting the rest of data */ 160 /* encrypting the rest of data */
161 while (len > bs) { 161 while (len > bs) {
162 ctx->xor(ctx->prev, p, bs); 162 ctx->xor(ctx->prev, p, bs);
163 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, ctx->prev, ctx->prev); 163 crypto_cipher_encrypt_one(tfm, ctx->prev,
164 ctx->prev);
164 p += bs; 165 p += bs;
165 len -= bs; 166 len -= bs;
166 } 167 }
@@ -171,7 +172,7 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
171 ctx->len = len; 172 ctx->len = len;
172 } 173 }
173 crypto_kunmap(p, 0); 174 crypto_kunmap(p, 0);
174 crypto_yield(tfm->crt_flags); 175 crypto_yield(pdesc->flags);
175 slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset); 176 slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
176 offset = 0; 177 offset = 0;
177 pg++; 178 pg++;
@@ -183,11 +184,20 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
183 return 0; 184 return 0;
184} 185}
185 186
187static int crypto_xcbc_digest_update(struct hash_desc *pdesc,
188 struct scatterlist *sg,
189 unsigned int nbytes)
190{
191 if (WARN_ON_ONCE(in_irq()))
192 return -EDEADLK;
193 return crypto_xcbc_digest_update2(pdesc, sg, nbytes);
194}
195
186static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out) 196static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
187{ 197{
188 struct crypto_hash *parent = pdesc->tfm; 198 struct crypto_hash *parent = pdesc->tfm;
189 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent); 199 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
190 struct crypto_tfm *tfm = ctx->child; 200 struct crypto_cipher *tfm = ctx->child;
191 int bs = crypto_hash_blocksize(parent); 201 int bs = crypto_hash_blocksize(parent);
192 int err = 0; 202 int err = 0;
193 203
@@ -197,13 +207,14 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
197 if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0) 207 if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
198 return err; 208 return err;
199 209
200 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, key2, (const u8*)(ctx->consts+bs)); 210 crypto_cipher_encrypt_one(tfm, key2,
211 (u8 *)(ctx->consts + bs));
201 212
202 ctx->xor(ctx->prev, ctx->odds, bs); 213 ctx->xor(ctx->prev, ctx->odds, bs);
203 ctx->xor(ctx->prev, key2, bs); 214 ctx->xor(ctx->prev, key2, bs);
204 _crypto_xcbc_digest_setkey(parent, ctx); 215 _crypto_xcbc_digest_setkey(parent, ctx);
205 216
206 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, out, ctx->prev); 217 crypto_cipher_encrypt_one(tfm, out, ctx->prev);
207 } else { 218 } else {
208 u8 key3[bs]; 219 u8 key3[bs];
209 unsigned int rlen; 220 unsigned int rlen;
@@ -218,14 +229,15 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
218 if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0) 229 if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
219 return err; 230 return err;
220 231
221 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, key3, (const u8*)(ctx->consts+bs*2)); 232 crypto_cipher_encrypt_one(tfm, key3,
233 (u8 *)(ctx->consts + bs * 2));
222 234
223 ctx->xor(ctx->prev, ctx->odds, bs); 235 ctx->xor(ctx->prev, ctx->odds, bs);
224 ctx->xor(ctx->prev, key3, bs); 236 ctx->xor(ctx->prev, key3, bs);
225 237
226 _crypto_xcbc_digest_setkey(parent, ctx); 238 _crypto_xcbc_digest_setkey(parent, ctx);
227 239
228 tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, out, ctx->prev); 240 crypto_cipher_encrypt_one(tfm, out, ctx->prev);
229 } 241 }
230 242
231 return 0; 243 return 0;
@@ -234,21 +246,25 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
234static int crypto_xcbc_digest(struct hash_desc *pdesc, 246static int crypto_xcbc_digest(struct hash_desc *pdesc,
235 struct scatterlist *sg, unsigned int nbytes, u8 *out) 247 struct scatterlist *sg, unsigned int nbytes, u8 *out)
236{ 248{
249 if (WARN_ON_ONCE(in_irq()))
250 return -EDEADLK;
251
237 crypto_xcbc_digest_init(pdesc); 252 crypto_xcbc_digest_init(pdesc);
238 crypto_xcbc_digest_update(pdesc, sg, nbytes); 253 crypto_xcbc_digest_update2(pdesc, sg, nbytes);
239 return crypto_xcbc_digest_final(pdesc, out); 254 return crypto_xcbc_digest_final(pdesc, out);
240} 255}
241 256
242static int xcbc_init_tfm(struct crypto_tfm *tfm) 257static int xcbc_init_tfm(struct crypto_tfm *tfm)
243{ 258{
259 struct crypto_cipher *cipher;
244 struct crypto_instance *inst = (void *)tfm->__crt_alg; 260 struct crypto_instance *inst = (void *)tfm->__crt_alg;
245 struct crypto_spawn *spawn = crypto_instance_ctx(inst); 261 struct crypto_spawn *spawn = crypto_instance_ctx(inst);
246 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(__crypto_hash_cast(tfm)); 262 struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(__crypto_hash_cast(tfm));
247 int bs = crypto_hash_blocksize(__crypto_hash_cast(tfm)); 263 int bs = crypto_hash_blocksize(__crypto_hash_cast(tfm));
248 264
249 tfm = crypto_spawn_tfm(spawn); 265 cipher = crypto_spawn_cipher(spawn);
250 if (IS_ERR(tfm)) 266 if (IS_ERR(cipher))
251 return PTR_ERR(tfm); 267 return PTR_ERR(cipher);
252 268
253 switch(bs) { 269 switch(bs) {
254 case 16: 270 case 16:
@@ -258,7 +274,7 @@ static int xcbc_init_tfm(struct crypto_tfm *tfm)
258 return -EINVAL; 274 return -EINVAL;
259 } 275 }
260 276
261 ctx->child = crypto_cipher_cast(tfm); 277 ctx->child = cipher;
262 ctx->odds = (u8*)(ctx+1); 278 ctx->odds = (u8*)(ctx+1);
263 ctx->prev = ctx->odds + bs; 279 ctx->prev = ctx->odds + bs;
264 ctx->key = ctx->prev + bs; 280 ctx->key = ctx->prev + bs;