Re: [PATCH 09/11] crypto: sun4i-ss: move from ablkcipher to skcipher API

2017-05-29 Thread Antoine Tenart
Hi Corentin,

On Mon, May 29, 2017 at 04:47:57PM +0200, Corentin Labbe wrote:
> On Wed, May 24, 2017 at 09:06:50PM +0200, Antoine Tenart wrote:
> > +   .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
> > +CRYPTO_ALG_KERN_DRIVER_ONLY,
> 
> You add CRYPTO_ALG_KERN_DRIVER_ONLY on all flags which is unrelated to
> the patch description.

Right, I forgot to make an extra patch for this. I'll fix this (and the
other ones).

Thanks,
Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


signature.asc
Description: PGP signature


Re: [PATCH 09/11] crypto: sun4i-ss: move from ablkcipher to skcipher API

2017-05-29 Thread Corentin Labbe
On Wed, May 24, 2017 at 09:06:50PM +0200, Antoine Tenart wrote:
> Update the sun4i-ss driver to use the skcipher API instead of the old
> ablkcipher one. It's a bit more tricky than s/ablkcipher/skcipher/, but
> still nothing special and the driver's logic stays the same.
> 
> Signed-off-by: Antoine Tenart 
> ---
>  drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 189 -
>  drivers/crypto/sunxi-ss/sun4i-ss-core.c   | 227 
> +++---
>  drivers/crypto/sunxi-ss/sun4i-ss.h|  34 ++---
>  3 files changed, 226 insertions(+), 224 deletions(-)
> 
> diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c 
> b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> index 23e549204365..5cf64746731a 100644
> --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> -{   .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
> +{   .type = CRYPTO_ALG_TYPE_SKCIPHER,
>   .alg.crypto = {
> - .cra_name = "cbc(aes)",
> - .cra_driver_name = "cbc-aes-sun4i-ss",
> - .cra_priority = 300,
> - .cra_blocksize = AES_BLOCK_SIZE,
> - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER,
> - .cra_ctxsize = sizeof(struct sun4i_tfm_ctx),
> - .cra_module = THIS_MODULE,
> - .cra_alignmask = 3,
> - .cra_type = _ablkcipher_type,
> - .cra_init = sun4i_ss_cipher_init,
> - .cra_ablkcipher = {
> - .min_keysize= AES_MIN_KEY_SIZE,
> - .max_keysize= AES_MAX_KEY_SIZE,
> - .ivsize = AES_BLOCK_SIZE,
> - .setkey = sun4i_ss_aes_setkey,
> - .encrypt= sun4i_ss_cbc_aes_encrypt,
> - .decrypt= sun4i_ss_cbc_aes_decrypt,
> + .setkey = sun4i_ss_aes_setkey,
> + .encrypt= sun4i_ss_cbc_aes_encrypt,
> + .decrypt= sun4i_ss_cbc_aes_decrypt,
> + .min_keysize= AES_MIN_KEY_SIZE,
> + .max_keysize= AES_MAX_KEY_SIZE,
> + .ivsize = AES_BLOCK_SIZE,
> + .base = {
> + .cra_name = "cbc(aes)",
> + .cra_driver_name = "cbc-aes-sun4i-ss",
> + .cra_priority = 300,
> + .cra_blocksize = AES_BLOCK_SIZE,
> + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
> +  CRYPTO_ALG_KERN_DRIVER_ONLY,

Hello

You add CRYPTO_ALG_KERN_DRIVER_ONLY on all flags which is unrelated to the 
patch description.

Regards


[PATCH 09/11] crypto: sun4i-ss: move from ablkcipher to skcipher API

2017-05-24 Thread Antoine Tenart
Update the sun4i-ss driver to use the skcipher API instead of the old
ablkcipher one. It's a bit more tricky than s/ablkcipher/skcipher/, but
still nothing special and the driver's logic stays the same.

Signed-off-by: Antoine Tenart 
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 189 -
 drivers/crypto/sunxi-ss/sun4i-ss-core.c   | 227 +++---
 drivers/crypto/sunxi-ss/sun4i-ss.h|  34 ++---
 3 files changed, 226 insertions(+), 224 deletions(-)

diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c 
b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
index 23e549204365..5cf64746731a 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
@@ -16,13 +16,13 @@
  */
 #include "sun4i-ss.h"
 
-static int sun4i_ss_opti_poll(struct ablkcipher_request *areq)
+static int sun4i_ss_opti_poll(struct skcipher_request *areq)
 {
-   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
-   struct sun4i_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
+   struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
+   struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
struct sun4i_ss_ctx *ss = op->ss;
-   unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
-   struct sun4i_cipher_req_ctx *ctx = ablkcipher_request_ctx(areq);
+   unsigned int ivsize = crypto_skcipher_ivsize(tfm);
+   struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
u32 mode = ctx->mode;
/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
u32 rx_cnt = SS_RX_DEFAULT;
@@ -31,17 +31,17 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request 
*areq)
u32 v;
int err = 0;
unsigned int i;
-   unsigned int ileft = areq->nbytes;
-   unsigned int oleft = areq->nbytes;
+   unsigned int ileft = areq->cryptlen;
+   unsigned int oleft = areq->cryptlen;
unsigned int todo;
struct sg_mapping_iter mi, mo;
unsigned int oi, oo; /* offset for in and out */
unsigned long flags;
 
-   if (!areq->nbytes)
+   if (!areq->cryptlen)
return 0;
 
-   if (!areq->info) {
+   if (!areq->iv) {
dev_err_ratelimited(ss->dev, "ERROR: Empty IV\n");
return -EINVAL;
}
@@ -56,9 +56,9 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq)
for (i = 0; i < op->keylen; i += 4)
writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
 
-   if (areq->info) {
+   if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
-   v = *(u32 *)(areq->info + i * 4);
+   v = *(u32 *)(areq->iv + i * 4);
writel(v, ss->base + SS_IV0 + i * 4);
}
}
@@ -76,8 +76,8 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq)
goto release_ss;
}
 
-   ileft = areq->nbytes / 4;
-   oleft = areq->nbytes / 4;
+   ileft = areq->cryptlen / 4;
+   oleft = areq->cryptlen / 4;
oi = 0;
oo = 0;
do {
@@ -108,10 +108,10 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request 
*areq)
}
} while (oleft);
 
-   if (areq->info) {
+   if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
v = readl(ss->base + SS_IV0 + i * 4);
-   *(u32 *)(areq->info + i * 4) = v;
+   *(u32 *)(areq->iv + i * 4) = v;
}
}
 
@@ -124,16 +124,16 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request 
*areq)
 }
 
 /* Generic function that support SG with size not multiple of 4 */
-static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
+static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
 {
-   struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
-   struct sun4i_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
+   struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
+   struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
struct sun4i_ss_ctx *ss = op->ss;
int no_chunk = 1;
struct scatterlist *in_sg = areq->src;
struct scatterlist *out_sg = areq->dst;
-   unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
-   struct sun4i_cipher_req_ctx *ctx = ablkcipher_request_ctx(areq);
+   unsigned int ivsize = crypto_skcipher_ivsize(tfm);
+   struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
u32 mode = ctx->mode;
/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
u32 rx_cnt = SS_RX_DEFAULT;
@@ -142,8 +142,8 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request 
*areq)
u32 spaces;
int err = 0;
unsigned int i;
-   unsigned int ileft = areq->nbytes;
-   unsigned int