Commit 4beb1060 authored by Herbert Xu's avatar Herbert Xu

crypto: vmx - Reindent to kernel style

This patch reidents the vmx code-base to the kernel coding style.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0903e435
...@@ -46,9 +46,10 @@ static int p8_aes_init(struct crypto_tfm *tfm) ...@@ -46,9 +46,10 @@ static int p8_aes_init(struct crypto_tfm *tfm)
return -ENOENT; return -ENOENT;
} }
fallback = crypto_alloc_cipher(alg, 0 ,CRYPTO_ALG_NEED_FALLBACK); fallback = crypto_alloc_cipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) { if (IS_ERR(fallback)) {
printk(KERN_ERR "Failed to allocate transformation for '%s': %ld\n", printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n",
alg, PTR_ERR(fallback)); alg, PTR_ERR(fallback));
return PTR_ERR(fallback); return PTR_ERR(fallback);
} }
...@@ -56,7 +57,9 @@ static int p8_aes_init(struct crypto_tfm *tfm) ...@@ -56,7 +57,9 @@ static int p8_aes_init(struct crypto_tfm *tfm)
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));
crypto_cipher_set_flags(fallback, crypto_cipher_set_flags(fallback,
crypto_cipher_get_flags((struct crypto_cipher *) tfm)); crypto_cipher_get_flags((struct
crypto_cipher *)
tfm));
ctx->fallback = fallback; ctx->fallback = fallback;
return 0; return 0;
...@@ -136,4 +139,3 @@ struct crypto_alg p8_aes_alg = { ...@@ -136,4 +139,3 @@ struct crypto_alg p8_aes_alg = {
.cia_decrypt = p8_aes_decrypt, .cia_decrypt = p8_aes_decrypt,
}, },
}; };
...@@ -47,17 +47,20 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm) ...@@ -47,17 +47,20 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
return -ENOENT; return -ENOENT;
} }
fallback = crypto_alloc_blkcipher(alg, 0 ,CRYPTO_ALG_NEED_FALLBACK); fallback =
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) { if (IS_ERR(fallback)) {
printk(KERN_ERR "Failed to allocate transformation for '%s': %ld\n", printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n",
alg, PTR_ERR(fallback)); alg, PTR_ERR(fallback));
return PTR_ERR(fallback); return PTR_ERR(fallback);
} }
printk(KERN_INFO "Using '%s' as fallback implementation.\n", printk(KERN_INFO "Using '%s' as fallback implementation.\n",
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));
crypto_blkcipher_set_flags(fallback, crypto_blkcipher_set_flags(
crypto_blkcipher_get_flags((struct crypto_blkcipher *) tfm)); fallback,
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm));
ctx->fallback = fallback; ctx->fallback = fallback;
return 0; return 0;
...@@ -90,13 +93,13 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key, ...@@ -90,13 +93,13 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key,
} }
static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
struct scatterlist *dst, struct scatterlist *src, struct scatterlist *dst,
unsigned int nbytes) struct scatterlist *src, unsigned int nbytes)
{ {
int ret; int ret;
struct blkcipher_walk walk; struct blkcipher_walk walk;
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx( struct p8_aes_cbc_ctx *ctx =
crypto_blkcipher_tfm(desc->tfm)); crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
struct blkcipher_desc fallback_desc = { struct blkcipher_desc fallback_desc = {
.tfm = ctx->fallback, .tfm = ctx->fallback,
.info = desc->info, .info = desc->info,
...@@ -104,7 +107,8 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, ...@@ -104,7 +107,8 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
}; };
if (in_interrupt()) { if (in_interrupt()) {
ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, nbytes); ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src,
nbytes);
} else { } else {
pagefault_disable(); pagefault_disable();
enable_kernel_altivec(); enable_kernel_altivec();
...@@ -112,8 +116,10 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, ...@@ -112,8 +116,10 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
blkcipher_walk_init(&walk, dst, src, nbytes); blkcipher_walk_init(&walk, dst, src, nbytes);
ret = blkcipher_walk_virt(desc, &walk); ret = blkcipher_walk_virt(desc, &walk);
while ((nbytes = walk.nbytes)) { while ((nbytes = walk.nbytes)) {
aes_p8_cbc_encrypt(walk.src.virt.addr, walk.dst.virt.addr, aes_p8_cbc_encrypt(walk.src.virt.addr,
nbytes & AES_BLOCK_MASK, &ctx->enc_key, walk.iv, 1); walk.dst.virt.addr,
nbytes & AES_BLOCK_MASK,
&ctx->enc_key, walk.iv, 1);
nbytes &= AES_BLOCK_SIZE - 1; nbytes &= AES_BLOCK_SIZE - 1;
ret = blkcipher_walk_done(desc, &walk, nbytes); ret = blkcipher_walk_done(desc, &walk, nbytes);
} }
...@@ -125,13 +131,13 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, ...@@ -125,13 +131,13 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
} }
static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc, static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
struct scatterlist *dst, struct scatterlist *src, struct scatterlist *dst,
unsigned int nbytes) struct scatterlist *src, unsigned int nbytes)
{ {
int ret; int ret;
struct blkcipher_walk walk; struct blkcipher_walk walk;
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx( struct p8_aes_cbc_ctx *ctx =
crypto_blkcipher_tfm(desc->tfm)); crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
struct blkcipher_desc fallback_desc = { struct blkcipher_desc fallback_desc = {
.tfm = ctx->fallback, .tfm = ctx->fallback,
.info = desc->info, .info = desc->info,
...@@ -139,7 +145,8 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc, ...@@ -139,7 +145,8 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
}; };
if (in_interrupt()) { if (in_interrupt()) {
ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src, nbytes); ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src,
nbytes);
} else { } else {
pagefault_disable(); pagefault_disable();
enable_kernel_altivec(); enable_kernel_altivec();
...@@ -147,8 +154,10 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc, ...@@ -147,8 +154,10 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
blkcipher_walk_init(&walk, dst, src, nbytes); blkcipher_walk_init(&walk, dst, src, nbytes);
ret = blkcipher_walk_virt(desc, &walk); ret = blkcipher_walk_virt(desc, &walk);
while ((nbytes = walk.nbytes)) { while ((nbytes = walk.nbytes)) {
aes_p8_cbc_encrypt(walk.src.virt.addr, walk.dst.virt.addr, aes_p8_cbc_encrypt(walk.src.virt.addr,
nbytes & AES_BLOCK_MASK, &ctx->dec_key, walk.iv, 0); walk.dst.virt.addr,
nbytes & AES_BLOCK_MASK,
&ctx->dec_key, walk.iv, 0);
nbytes &= AES_BLOCK_SIZE - 1; nbytes &= AES_BLOCK_SIZE - 1;
ret = blkcipher_walk_done(desc, &walk, nbytes); ret = blkcipher_walk_done(desc, &walk, nbytes);
} }
...@@ -181,4 +190,3 @@ struct crypto_alg p8_aes_cbc_alg = { ...@@ -181,4 +190,3 @@ struct crypto_alg p8_aes_cbc_alg = {
.decrypt = p8_aes_cbc_decrypt, .decrypt = p8_aes_cbc_decrypt,
}, },
}; };
...@@ -45,17 +45,20 @@ static int p8_aes_ctr_init(struct crypto_tfm *tfm) ...@@ -45,17 +45,20 @@ static int p8_aes_ctr_init(struct crypto_tfm *tfm)
return -ENOENT; return -ENOENT;
} }
fallback = crypto_alloc_blkcipher(alg, 0 ,CRYPTO_ALG_NEED_FALLBACK); fallback =
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) { if (IS_ERR(fallback)) {
printk(KERN_ERR "Failed to allocate transformation for '%s': %ld\n", printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n",
alg, PTR_ERR(fallback)); alg, PTR_ERR(fallback));
return PTR_ERR(fallback); return PTR_ERR(fallback);
} }
printk(KERN_INFO "Using '%s' as fallback implementation.\n", printk(KERN_INFO "Using '%s' as fallback implementation.\n",
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));
crypto_blkcipher_set_flags(fallback, crypto_blkcipher_set_flags(
crypto_blkcipher_get_flags((struct crypto_blkcipher *) tfm)); fallback,
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm));
ctx->fallback = fallback; ctx->fallback = fallback;
return 0; return 0;
...@@ -106,13 +109,13 @@ static void p8_aes_ctr_final(struct p8_aes_ctr_ctx *ctx, ...@@ -106,13 +109,13 @@ static void p8_aes_ctr_final(struct p8_aes_ctr_ctx *ctx,
} }
static int p8_aes_ctr_crypt(struct blkcipher_desc *desc, static int p8_aes_ctr_crypt(struct blkcipher_desc *desc,
struct scatterlist *dst, struct scatterlist *src, struct scatterlist *dst,
unsigned int nbytes) struct scatterlist *src, unsigned int nbytes)
{ {
int ret; int ret;
struct blkcipher_walk walk; struct blkcipher_walk walk;
struct p8_aes_ctr_ctx *ctx = crypto_tfm_ctx( struct p8_aes_ctr_ctx *ctx =
crypto_blkcipher_tfm(desc->tfm)); crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
struct blkcipher_desc fallback_desc = { struct blkcipher_desc fallback_desc = {
.tfm = ctx->fallback, .tfm = ctx->fallback,
.info = desc->info, .info = desc->info,
...@@ -120,15 +123,21 @@ static int p8_aes_ctr_crypt(struct blkcipher_desc *desc, ...@@ -120,15 +123,21 @@ static int p8_aes_ctr_crypt(struct blkcipher_desc *desc,
}; };
if (in_interrupt()) { if (in_interrupt()) {
ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, nbytes); ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src,
nbytes);
} else { } else {
blkcipher_walk_init(&walk, dst, src, nbytes); blkcipher_walk_init(&walk, dst, src, nbytes);
ret = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE); ret = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) { while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
pagefault_disable(); pagefault_disable();
enable_kernel_altivec(); enable_kernel_altivec();
aes_p8_ctr32_encrypt_blocks(walk.src.virt.addr, walk.dst.virt.addr, aes_p8_ctr32_encrypt_blocks(walk.src.virt.addr,
(nbytes & AES_BLOCK_MASK)/AES_BLOCK_SIZE, &ctx->enc_key, walk.iv); walk.dst.virt.addr,
(nbytes &
AES_BLOCK_MASK) /
AES_BLOCK_SIZE,
&ctx->enc_key,
walk.iv);
pagefault_enable(); pagefault_enable();
crypto_inc(walk.iv, AES_BLOCK_SIZE); crypto_inc(walk.iv, AES_BLOCK_SIZE);
......
...@@ -13,8 +13,9 @@ int aes_p8_set_encrypt_key(const u8 *userKey, const int bits, ...@@ -13,8 +13,9 @@ int aes_p8_set_encrypt_key(const u8 *userKey, const int bits,
int aes_p8_set_decrypt_key(const u8 *userKey, const int bits, int aes_p8_set_decrypt_key(const u8 *userKey, const int bits,
struct aes_key *key); struct aes_key *key);
void aes_p8_encrypt(const u8 *in, u8 *out, const struct aes_key *key); void aes_p8_encrypt(const u8 *in, u8 *out, const struct aes_key *key);
void aes_p8_decrypt(const u8 *in, u8 *out,const struct aes_key *key); void aes_p8_decrypt(const u8 *in, u8 *out, const struct aes_key *key);
void aes_p8_cbc_encrypt(const u8 *in, u8 *out, size_t len, void aes_p8_cbc_encrypt(const u8 *in, u8 *out, size_t len,
const struct aes_key *key, u8 *iv, const int enc); const struct aes_key *key, u8 *iv, const int enc);
void aes_p8_ctr32_encrypt_blocks(const u8 *in, u8 *out, void aes_p8_ctr32_encrypt_blocks(const u8 *in, u8 *out,
size_t len, const struct aes_key *key, const u8 *iv); size_t len, const struct aes_key *key,
const u8 *iv);
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
void gcm_init_p8(u128 htable[16], const u64 Xi[2]); void gcm_init_p8(u128 htable[16], const u64 Xi[2]);
void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]); void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]);
void gcm_ghash_p8(u64 Xi[2], const u128 htable[16], void gcm_ghash_p8(u64 Xi[2], const u128 htable[16],
const u8 *in,size_t len); const u8 *in, size_t len);
struct p8_ghash_ctx { struct p8_ghash_ctx {
u128 htable[16]; u128 htable[16];
...@@ -65,9 +65,10 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm) ...@@ -65,9 +65,10 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
return -ENOENT; return -ENOENT;
} }
fallback = crypto_alloc_shash(alg, 0 ,CRYPTO_ALG_NEED_FALLBACK); fallback = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) { if (IS_ERR(fallback)) {
printk(KERN_ERR "Failed to allocate transformation for '%s': %ld\n", printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n",
alg, PTR_ERR(fallback)); alg, PTR_ERR(fallback));
return PTR_ERR(fallback); return PTR_ERR(fallback);
} }
...@@ -75,7 +76,8 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm) ...@@ -75,7 +76,8 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
crypto_tfm_alg_driver_name(crypto_shash_tfm(fallback))); crypto_tfm_alg_driver_name(crypto_shash_tfm(fallback)));
crypto_shash_set_flags(fallback, crypto_shash_set_flags(fallback,
crypto_shash_get_flags((struct crypto_shash *) tfm)); crypto_shash_get_flags((struct crypto_shash
*) tfm));
ctx->fallback = fallback; ctx->fallback = fallback;
shash_tfm->descsize = sizeof(struct p8_ghash_desc_ctx) shash_tfm->descsize = sizeof(struct p8_ghash_desc_ctx)
...@@ -130,11 +132,13 @@ static int p8_ghash_update(struct shash_desc *desc, ...@@ -130,11 +132,13 @@ static int p8_ghash_update(struct shash_desc *desc,
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc); struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
if (IN_INTERRUPT) { if (IN_INTERRUPT) {
return crypto_shash_update(&dctx->fallback_desc, src, srclen); return crypto_shash_update(&dctx->fallback_desc, src,
srclen);
} else { } else {
if (dctx->bytes) { if (dctx->bytes) {
if (dctx->bytes + srclen < GHASH_DIGEST_SIZE) { if (dctx->bytes + srclen < GHASH_DIGEST_SIZE) {
memcpy(dctx->buffer + dctx->bytes, src, srclen); memcpy(dctx->buffer + dctx->bytes, src,
srclen);
dctx->bytes += srclen; dctx->bytes += srclen;
return 0; return 0;
} }
...@@ -143,8 +147,8 @@ static int p8_ghash_update(struct shash_desc *desc, ...@@ -143,8 +147,8 @@ static int p8_ghash_update(struct shash_desc *desc,
pagefault_disable(); pagefault_disable();
enable_kernel_altivec(); enable_kernel_altivec();
enable_kernel_fp(); enable_kernel_fp();
gcm_ghash_p8(dctx->shash, ctx->htable, dctx->buffer, gcm_ghash_p8(dctx->shash, ctx->htable,
GHASH_DIGEST_SIZE); dctx->buffer, GHASH_DIGEST_SIZE);
pagefault_enable(); pagefault_enable();
src += GHASH_DIGEST_SIZE - dctx->bytes; src += GHASH_DIGEST_SIZE - dctx->bytes;
srclen -= GHASH_DIGEST_SIZE - dctx->bytes; srclen -= GHASH_DIGEST_SIZE - dctx->bytes;
...@@ -183,8 +187,8 @@ static int p8_ghash_final(struct shash_desc *desc, u8 *out) ...@@ -183,8 +187,8 @@ static int p8_ghash_final(struct shash_desc *desc, u8 *out)
pagefault_disable(); pagefault_disable();
enable_kernel_altivec(); enable_kernel_altivec();
enable_kernel_fp(); enable_kernel_fp();
gcm_ghash_p8(dctx->shash, ctx->htable, dctx->buffer, gcm_ghash_p8(dctx->shash, ctx->htable,
GHASH_DIGEST_SIZE); dctx->buffer, GHASH_DIGEST_SIZE);
pagefault_enable(); pagefault_enable();
dctx->bytes = 0; dctx->bytes = 0;
} }
......
...@@ -82,7 +82,7 @@ module_init(p8_init); ...@@ -82,7 +82,7 @@ module_init(p8_init);
module_exit(p8_exit); module_exit(p8_exit);
MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>"); MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions support on Power 8"); MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions "
"support on Power 8");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0"); MODULE_VERSION("1.0.0");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment