aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-10-09 23:19:47 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-10-09 23:19:47 -0400
commitc3afafa47898e34eb49828ec4ac92bcdc81c8f0c (patch)
tree055f603e131de9c4d36dafb1856fe69c737152de /crypto
parentf97581cfa6e7db9818520597b8a44f8268d75013 (diff)
parent80da44c29d997e28c4442825f35f4ac339813877 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Merge the crypto tree to pull in vmx ghash fix.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/blkcipher.c3
-rw-r--r--crypto/cryptd.c12
-rw-r--r--crypto/echainiv.c115
-rw-r--r--crypto/ghash-generic.c13
-rw-r--r--crypto/rsa-pkcs1pad.c41
5 files changed, 60 insertions, 124 deletions
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index 369999530108..a832426820e8 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -233,6 +233,8 @@ static int blkcipher_walk_next(struct blkcipher_desc *desc,
233 return blkcipher_walk_done(desc, walk, -EINVAL); 233 return blkcipher_walk_done(desc, walk, -EINVAL);
234 } 234 }
235 235
236 bsize = min(walk->walk_blocksize, n);
237
236 walk->flags &= ~(BLKCIPHER_WALK_SLOW | BLKCIPHER_WALK_COPY | 238 walk->flags &= ~(BLKCIPHER_WALK_SLOW | BLKCIPHER_WALK_COPY |
237 BLKCIPHER_WALK_DIFF); 239 BLKCIPHER_WALK_DIFF);
238 if (!scatterwalk_aligned(&walk->in, walk->alignmask) || 240 if (!scatterwalk_aligned(&walk->in, walk->alignmask) ||
@@ -245,7 +247,6 @@ static int blkcipher_walk_next(struct blkcipher_desc *desc,
245 } 247 }
246 } 248 }
247 249
248 bsize = min(walk->walk_blocksize, n);
249 n = scatterwalk_clamp(&walk->in, n); 250 n = scatterwalk_clamp(&walk->in, n);
250 n = scatterwalk_clamp(&walk->out, n); 251 n = scatterwalk_clamp(&walk->out, n);
251 252
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index cf8037a87b2d..0c654e59f215 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -631,9 +631,14 @@ static int cryptd_hash_export(struct ahash_request *req, void *out)
631 631
632static int cryptd_hash_import(struct ahash_request *req, const void *in) 632static int cryptd_hash_import(struct ahash_request *req, const void *in)
633{ 633{
634 struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req); 634 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
635 struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
636 struct shash_desc *desc = cryptd_shash_desc(req);
637
638 desc->tfm = ctx->child;
639 desc->flags = req->base.flags;
635 640
636 return crypto_shash_import(&rctx->desc, in); 641 return crypto_shash_import(desc, in);
637} 642}
638 643
639static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, 644static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
@@ -733,13 +738,14 @@ static void cryptd_aead_crypt(struct aead_request *req,
733 rctx = aead_request_ctx(req); 738 rctx = aead_request_ctx(req);
734 compl = rctx->complete; 739 compl = rctx->complete;
735 740
741 tfm = crypto_aead_reqtfm(req);
742
736 if (unlikely(err == -EINPROGRESS)) 743 if (unlikely(err == -EINPROGRESS))
737 goto out; 744 goto out;
738 aead_request_set_tfm(req, child); 745 aead_request_set_tfm(req, child);
739 err = crypt( req ); 746 err = crypt( req );
740 747
741out: 748out:
742 tfm = crypto_aead_reqtfm(req);
743 ctx = crypto_aead_ctx(tfm); 749 ctx = crypto_aead_ctx(tfm);
744 refcnt = atomic_read(&ctx->refcnt); 750 refcnt = atomic_read(&ctx->refcnt);
745 751
diff --git a/crypto/echainiv.c b/crypto/echainiv.c
index 1b01fe98e91f..e3d889b122e0 100644
--- a/crypto/echainiv.c
+++ b/crypto/echainiv.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * echainiv: Encrypted Chain IV Generator 2 * echainiv: Encrypted Chain IV Generator
3 * 3 *
4 * This generator generates an IV based on a sequence number by xoring it 4 * This generator generates an IV based on a sequence number by multiplying
5 * with a salt and then encrypting it with the same key as used to encrypt 5 * it with a salt and then encrypting it with the same key as used to encrypt
6 * the plain text. This algorithm requires that the block size be equal 6 * the plain text. This algorithm requires that the block size be equal
7 * to the IV size. It is mainly useful for CBC. 7 * to the IV size. It is mainly useful for CBC.
8 * 8 *
@@ -24,81 +24,17 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/mm.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/percpu.h> 28#include <linux/slab.h>
30#include <linux/spinlock.h>
31#include <linux/string.h> 29#include <linux/string.h>
32 30
33#define MAX_IV_SIZE 16
34
35static DEFINE_PER_CPU(u32 [MAX_IV_SIZE / sizeof(u32)], echainiv_iv);
36
37/* We don't care if we get preempted and read/write IVs from the next CPU. */
38static void echainiv_read_iv(u8 *dst, unsigned size)
39{
40 u32 *a = (u32 *)dst;
41 u32 __percpu *b = echainiv_iv;
42
43 for (; size >= 4; size -= 4) {
44 *a++ = this_cpu_read(*b);
45 b++;
46 }
47}
48
49static void echainiv_write_iv(const u8 *src, unsigned size)
50{
51 const u32 *a = (const u32 *)src;
52 u32 __percpu *b = echainiv_iv;
53
54 for (; size >= 4; size -= 4) {
55 this_cpu_write(*b, *a);
56 a++;
57 b++;
58 }
59}
60
61static void echainiv_encrypt_complete2(struct aead_request *req, int err)
62{
63 struct aead_request *subreq = aead_request_ctx(req);
64 struct crypto_aead *geniv;
65 unsigned int ivsize;
66
67 if (err == -EINPROGRESS)
68 return;
69
70 if (err)
71 goto out;
72
73 geniv = crypto_aead_reqtfm(req);
74 ivsize = crypto_aead_ivsize(geniv);
75
76 echainiv_write_iv(subreq->iv, ivsize);
77
78 if (req->iv != subreq->iv)
79 memcpy(req->iv, subreq->iv, ivsize);
80
81out:
82 if (req->iv != subreq->iv)
83 kzfree(subreq->iv);
84}
85
86static void echainiv_encrypt_complete(struct crypto_async_request *base,
87 int err)
88{
89 struct aead_request *req = base->data;
90
91 echainiv_encrypt_complete2(req, err);
92 aead_request_complete(req, err);
93}
94
95static int echainiv_encrypt(struct aead_request *req) 31static int echainiv_encrypt(struct aead_request *req)
96{ 32{
97 struct crypto_aead *geniv = crypto_aead_reqtfm(req); 33 struct crypto_aead *geniv = crypto_aead_reqtfm(req);
98 struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv); 34 struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
99 struct aead_request *subreq = aead_request_ctx(req); 35 struct aead_request *subreq = aead_request_ctx(req);
100 crypto_completion_t compl; 36 __be64 nseqno;
101 void *data; 37 u64 seqno;
102 u8 *info; 38 u8 *info;
103 unsigned int ivsize = crypto_aead_ivsize(geniv); 39 unsigned int ivsize = crypto_aead_ivsize(geniv);
104 int err; 40 int err;
@@ -108,8 +44,6 @@ static int echainiv_encrypt(struct aead_request *req)
108 44
109 aead_request_set_tfm(subreq, ctx->child); 45 aead_request_set_tfm(subreq, ctx->child);
110 46
111 compl = echainiv_encrypt_complete;
112 data = req;
113 info = req->iv; 47 info = req->iv;
114 48
115 if (req->src != req->dst) { 49 if (req->src != req->dst) {
@@ -127,29 +61,30 @@ static int echainiv_encrypt(struct aead_request *req)
127 return err; 61 return err;
128 } 62 }
129 63
130 if (unlikely(!IS_ALIGNED((unsigned long)info, 64 aead_request_set_callback(subreq, req->base.flags,
131 crypto_aead_alignmask(geniv) + 1))) { 65 req->base.complete, req->base.data);
132 info = kmalloc(ivsize, req->base.flags &
133 CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
134 GFP_ATOMIC);
135 if (!info)
136 return -ENOMEM;
137
138 memcpy(info, req->iv, ivsize);
139 }
140
141 aead_request_set_callback(subreq, req->base.flags, compl, data);
142 aead_request_set_crypt(subreq, req->dst, req->dst, 66 aead_request_set_crypt(subreq, req->dst, req->dst,
143 req->cryptlen, info); 67 req->cryptlen, info);
144 aead_request_set_ad(subreq, req->assoclen); 68 aead_request_set_ad(subreq, req->assoclen);
145 69
146 crypto_xor(info, ctx->salt, ivsize); 70 memcpy(&nseqno, info + ivsize - 8, 8);