git://ftp.safe.ca
/
safe
/
jmp
/
linux-2.6
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
nfsd: fix leak on error in nfsv3 readdir
[safe/jmp/linux-2.6]
/
crypto
/
xcbc.c
diff --git
a/crypto/xcbc.c
b/crypto/xcbc.c
index
d7b4be0
..
b63b633
100644
(file)
--- a/
crypto/xcbc.c
+++ b/
crypto/xcbc.c
@@
-19,6
+19,7
@@
* Kazunori Miyazawa <miyazawa@linux-ipv6.org>
*/
* Kazunori Miyazawa <miyazawa@linux-ipv6.org>
*/
+#include <crypto/scatterwalk.h>
#include <linux/crypto.h>
#include <linux/err.h>
#include <linux/hardirq.h>
#include <linux/crypto.h>
#include <linux/err.h>
#include <linux/hardirq.h>
@@
-27,7
+28,6
@@
#include <linux/rtnetlink.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>
#include <linux/rtnetlink.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>
-#include "internal.h"
static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
0x02020202, 0x02020202, 0x02020202, 0x02020202,
static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
0x02020202, 0x02020202, 0x02020202, 0x02020202,
@@
-48,7
+48,7
@@
static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
* +------------------------
*/
struct crypto_xcbc_ctx {
* +------------------------
*/
struct crypto_xcbc_ctx {
- struct crypto_
tfm
*child;
+ struct crypto_
cipher
*child;
u8 *odds;
u8 *prev;
u8 *key;
u8 *odds;
u8 *prev;
u8 *key;
@@
-76,8
+76,7
@@
static int _crypto_xcbc_digest_setkey(struct crypto_hash *parent,
if ((err = crypto_cipher_setkey(ctx->child, ctx->key, ctx->keylen)))
return err;
if ((err = crypto_cipher_setkey(ctx->child, ctx->key, ctx->keylen)))
return err;
- ctx->child->__crt_alg->cra_cipher.cia_encrypt(ctx->child, key1,
- ctx->consts);
+ crypto_cipher_encrypt_one(ctx->child, key1, ctx->consts);
return crypto_cipher_setkey(ctx->child, key1, bs);
}
return crypto_cipher_setkey(ctx->child, key1, bs);
}
@@
-87,7
+86,7
@@
static int crypto_xcbc_digest_setkey(struct crypto_hash *parent,
{
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
{
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
- if (keylen != crypto_
tfm_alg
_blocksize(ctx->child))
+ if (keylen != crypto_
cipher
_blocksize(ctx->child))
return -EINVAL;
ctx->keylen = keylen;
return -EINVAL;
ctx->keylen = keylen;
@@
-115,15
+114,18
@@
static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
{
struct crypto_hash *parent = pdesc->tfm;
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
{
struct crypto_hash *parent = pdesc->tfm;
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
- struct crypto_
tfm
*tfm = ctx->child;
+ struct crypto_
cipher
*tfm = ctx->child;
int bs = crypto_hash_blocksize(parent);
int bs = crypto_hash_blocksize(parent);
- unsigned int i = 0;
- do {
+ for (;;) {
+ struct page *pg = sg_page(sg);
+ unsigned int offset = sg->offset;
+ unsigned int slen = sg->length;
- struct page *pg = sg[i].page;
- unsigned int offset = sg[i].offset;
- unsigned int slen = sg[i].length;
+ if (unlikely(slen > nbytes))
+ slen = nbytes;
+
+ nbytes -= slen;
while (slen > 0) {
unsigned int len = min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
while (slen > 0) {
unsigned int len = min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
@@
-143,7
+145,7
@@
static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
offset += len;
crypto_kunmap(p, 0);
offset += len;
crypto_kunmap(p, 0);
- crypto_yield(
tfm->crt_
flags);
+ crypto_yield(
pdesc->
flags);
continue;
}
continue;
}
@@
-153,7
+155,7
@@
static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
p += bs - ctx->len;
ctx->xor(ctx->prev, ctx->odds, bs);
p += bs - ctx->len;
ctx->xor(ctx->prev, ctx->odds, bs);
-
tfm->__crt_alg->cra_cipher.cia_encrypt
(tfm, ctx->prev, ctx->prev);
+
crypto_cipher_encrypt_one
(tfm, ctx->prev, ctx->prev);
/* clearing the length */
ctx->len = 0;
/* clearing the length */
ctx->len = 0;
@@
-161,7
+163,8
@@
static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
/* encrypting the rest of data */
while (len > bs) {
ctx->xor(ctx->prev, p, bs);
/* encrypting the rest of data */
while (len > bs) {
ctx->xor(ctx->prev, p, bs);
- tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, ctx->prev, ctx->prev);
+ crypto_cipher_encrypt_one(tfm, ctx->prev,
+ ctx->prev);
p += bs;
len -= bs;
}
p += bs;
len -= bs;
}
@@
-172,14
+175,16
@@
static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
ctx->len = len;
}
crypto_kunmap(p, 0);
ctx->len = len;
}
crypto_kunmap(p, 0);
- crypto_yield(
tfm->crt_
flags);
+ crypto_yield(
pdesc->
flags);
slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
offset = 0;
pg++;
}
slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
offset = 0;
pg++;
}
- nbytes-=sg[i].length;
- i++;
- } while (nbytes>0);
+
+ if (!nbytes)
+ break;
+ sg = scatterwalk_sg_next(sg);
+ }
return 0;
}
return 0;
}
@@
-197,7
+202,7
@@
static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
{
struct crypto_hash *parent = pdesc->tfm;
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
{
struct crypto_hash *parent = pdesc->tfm;
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
- struct crypto_
tfm
*tfm = ctx->child;
+ struct crypto_
cipher
*tfm = ctx->child;
int bs = crypto_hash_blocksize(parent);
int err = 0;
int bs = crypto_hash_blocksize(parent);
int err = 0;
@@
-207,13
+212,14
@@
static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
return err;
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
return err;
- tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, key2, (const u8*)(ctx->consts+bs));
+ crypto_cipher_encrypt_one(tfm, key2,
+ (u8 *)(ctx->consts + bs));
ctx->xor(ctx->prev, ctx->odds, bs);
ctx->xor(ctx->prev, key2, bs);
_crypto_xcbc_digest_setkey(parent, ctx);
ctx->xor(ctx->prev, ctx->odds, bs);
ctx->xor(ctx->prev, key2, bs);
_crypto_xcbc_digest_setkey(parent, ctx);
-
tfm->__crt_alg->cra_cipher.cia_encrypt
(tfm, out, ctx->prev);
+
crypto_cipher_encrypt_one
(tfm, out, ctx->prev);
} else {
u8 key3[bs];
unsigned int rlen;
} else {
u8 key3[bs];
unsigned int rlen;
@@
-228,14
+234,15
@@
static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
return err;
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
return err;
- tfm->__crt_alg->cra_cipher.cia_encrypt(tfm, key3, (const u8*)(ctx->consts+bs*2));
+ crypto_cipher_encrypt_one(tfm, key3,
+ (u8 *)(ctx->consts + bs * 2));
ctx->xor(ctx->prev, ctx->odds, bs);
ctx->xor(ctx->prev, key3, bs);
_crypto_xcbc_digest_setkey(parent, ctx);
ctx->xor(ctx->prev, ctx->odds, bs);
ctx->xor(ctx->prev, key3, bs);
_crypto_xcbc_digest_setkey(parent, ctx);
-
tfm->__crt_alg->cra_cipher.cia_encrypt
(tfm, out, ctx->prev);
+
crypto_cipher_encrypt_one
(tfm, out, ctx->prev);
}
return 0;
}
return 0;
@@
-286,20
+293,27
@@
static void xcbc_exit_tfm(struct crypto_tfm *tfm)
crypto_free_cipher(ctx->child);
}
crypto_free_cipher(ctx->child);
}
-static struct crypto_instance *xcbc_alloc(
void *param, unsigned int len
)
+static struct crypto_instance *xcbc_alloc(
struct rtattr **tb
)
{
struct crypto_instance *inst;
struct crypto_alg *alg;
{
struct crypto_instance *inst;
struct crypto_alg *alg;
- alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER,
- CRYPTO_ALG_TYPE_HASH_MASK | CRYPTO_ALG_ASYNC);
+ int err;
+
+ err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH);
+ if (err)
+ return ERR_PTR(err);
+
+ alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
+ CRYPTO_ALG_TYPE_MASK);
if (IS_ERR(alg))
if (IS_ERR(alg))
- return ERR_
PTR(PTR_ERR(alg)
);
+ return ERR_
CAST(alg
);
switch(alg->cra_blocksize) {
case 16:
break;
default:
switch(alg->cra_blocksize) {
case 16:
break;
default:
- return ERR_PTR(PTR_ERR(alg));
+ inst = ERR_PTR(-EINVAL);
+ goto out_put_alg;
}
inst = crypto_alloc_instance("xcbc", alg);
}
inst = crypto_alloc_instance("xcbc", alg);
@@
-312,10
+326,7
@@
static struct crypto_instance *xcbc_alloc(void *param, unsigned int len)
inst->alg.cra_alignmask = alg->cra_alignmask;
inst->alg.cra_type = &crypto_hash_type;
inst->alg.cra_alignmask = alg->cra_alignmask;
inst->alg.cra_type = &crypto_hash_type;
- inst->alg.cra_hash.digestsize =
- (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
- CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize :
- alg->cra_blocksize;
+ inst->alg.cra_hash.digestsize = alg->cra_blocksize;
inst->alg.cra_ctxsize = sizeof(struct crypto_xcbc_ctx) +
ALIGN(inst->alg.cra_blocksize * 3, sizeof(void *));
inst->alg.cra_init = xcbc_init_tfm;
inst->alg.cra_ctxsize = sizeof(struct crypto_xcbc_ctx) +
ALIGN(inst->alg.cra_blocksize * 3, sizeof(void *));
inst->alg.cra_init = xcbc_init_tfm;