[CRYPTO] xcbc: Use new cipher interface
This patch changes xcbc to use the new cipher encryt_one interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
27d2a33007
commit
6b701dde8e
1 changed files with 16 additions and 14 deletions
|
@ -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 *odds;
|
||||||
u8 *prev;
|
u8 *prev;
|
||||||
u8 *key;
|
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)))
|
if ((err = crypto_cipher_setkey(ctx->child, ctx->key, ctx->keylen)))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
ctx->child->__crt_alg->cra_cipher.cia_encrypt(ctx->child, key1,
|
crypto_cipher_encrypt_one(ctx->child, key1, ctx->consts);
|
||||||
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;
|
return -EINVAL;
|
||||||
|
|
||||||
ctx->keylen = keylen;
|
ctx->keylen = keylen;
|
||||||
|
@ -115,7 +114,7 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
|
||||||
{
|
{
|
||||||
struct crypto_hash *parent = pdesc->tfm;
|
struct crypto_hash *parent = pdesc->tfm;
|
||||||
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
|
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;
|
unsigned int i = 0;
|
||||||
|
|
||||||
|
@ -143,7 +142,7 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
crypto_kunmap(p, 0);
|
crypto_kunmap(p, 0);
|
||||||
crypto_yield(tfm->crt_flags);
|
crypto_yield(pdesc->flags);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +152,7 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
|
||||||
p += bs - ctx->len;
|
p += bs - ctx->len;
|
||||||
|
|
||||||
ctx->xor(ctx->prev, ctx->odds, bs);
|
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 */
|
/* clearing the length */
|
||||||
ctx->len = 0;
|
ctx->len = 0;
|
||||||
|
@ -161,7 +160,8 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
|
||||||
/* encrypting the rest of data */
|
/* encrypting the rest of data */
|
||||||
while (len > bs) {
|
while (len > bs) {
|
||||||
ctx->xor(ctx->prev, p, 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;
|
p += bs;
|
||||||
len -= bs;
|
len -= bs;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
|
||||||
ctx->len = len;
|
ctx->len = len;
|
||||||
}
|
}
|
||||||
crypto_kunmap(p, 0);
|
crypto_kunmap(p, 0);
|
||||||
crypto_yield(tfm->crt_flags);
|
crypto_yield(pdesc->flags);
|
||||||
slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
|
slen -= min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
pg++;
|
pg++;
|
||||||
|
@ -197,7 +197,7 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
|
||||||
{
|
{
|
||||||
struct crypto_hash *parent = pdesc->tfm;
|
struct crypto_hash *parent = pdesc->tfm;
|
||||||
struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent);
|
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);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -207,13 +207,14 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
|
||||||
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
|
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
|
||||||
return err;
|
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, ctx->odds, bs);
|
||||||
ctx->xor(ctx->prev, key2, bs);
|
ctx->xor(ctx->prev, key2, bs);
|
||||||
_crypto_xcbc_digest_setkey(parent, ctx);
|
_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 {
|
} else {
|
||||||
u8 key3[bs];
|
u8 key3[bs];
|
||||||
unsigned int rlen;
|
unsigned int rlen;
|
||||||
|
@ -228,14 +229,15 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out)
|
||||||
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
|
if ((err = crypto_cipher_setkey(tfm, ctx->key, ctx->keylen)) != 0)
|
||||||
return err;
|
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, ctx->odds, bs);
|
||||||
ctx->xor(ctx->prev, key3, bs);
|
ctx->xor(ctx->prev, key3, bs);
|
||||||
|
|
||||||
_crypto_xcbc_digest_setkey(parent, ctx);
|
_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;
|
||||||
|
|
Loading…
Reference in a new issue