Commit 317cbacf authored by Antoine Ténart's avatar Antoine Ténart Committed by Herbert Xu

crypto: sun4i-ss - move from ablkcipher to skcipher API

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: default avatarAntoine Tenart <antoine.tenart@free-electrons.com>
Tested-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Acked-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent d78867a9
This diff is collapsed.
...@@ -83,134 +83,128 @@ static struct sun4i_ss_alg_template ss_algs[] = { ...@@ -83,134 +83,128 @@ static struct sun4i_ss_alg_template ss_algs[] = {
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "cbc(aes)", .setkey = sun4i_ss_aes_setkey,
.cra_driver_name = "cbc-aes-sun4i-ss", .encrypt = sun4i_ss_cbc_aes_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_cbc_aes_decrypt,
.cra_blocksize = AES_BLOCK_SIZE, .min_keysize = AES_MIN_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = AES_MAX_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_tfm_ctx), .ivsize = AES_BLOCK_SIZE,
.cra_module = THIS_MODULE, .base = {
.cra_alignmask = 3, .cra_name = "cbc(aes)",
.cra_type = &crypto_ablkcipher_type, .cra_driver_name = "cbc-aes-sun4i-ss",
.cra_init = sun4i_ss_cipher_init, .cra_priority = 300,
.cra_ablkcipher = { .cra_blocksize = AES_BLOCK_SIZE,
.min_keysize = AES_MIN_KEY_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.max_keysize = AES_MAX_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_tfm_ctx),
.ivsize = AES_BLOCK_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_aes_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_cbc_aes_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_cbc_aes_decrypt,
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "ecb(aes)", .setkey = sun4i_ss_aes_setkey,
.cra_driver_name = "ecb-aes-sun4i-ss", .encrypt = sun4i_ss_ecb_aes_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_ecb_aes_decrypt,
.cra_blocksize = AES_BLOCK_SIZE, .min_keysize = AES_MIN_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = AES_MAX_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_tfm_ctx), .ivsize = AES_BLOCK_SIZE,
.cra_module = THIS_MODULE, .base = {
.cra_alignmask = 3, .cra_name = "ecb(aes)",
.cra_type = &crypto_ablkcipher_type, .cra_driver_name = "ecb-aes-sun4i-ss",
.cra_init = sun4i_ss_cipher_init, .cra_priority = 300,
.cra_ablkcipher = { .cra_blocksize = AES_BLOCK_SIZE,
.min_keysize = AES_MIN_KEY_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.max_keysize = AES_MAX_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_tfm_ctx),
.ivsize = AES_BLOCK_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_aes_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_ecb_aes_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_ecb_aes_decrypt,
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "cbc(des)", .setkey = sun4i_ss_des_setkey,
.cra_driver_name = "cbc-des-sun4i-ss", .encrypt = sun4i_ss_cbc_des_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_cbc_des_decrypt,
.cra_blocksize = DES_BLOCK_SIZE, .min_keysize = DES_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = DES_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_req_ctx), .ivsize = DES_BLOCK_SIZE,
.cra_module = THIS_MODULE, .base = {
.cra_alignmask = 3, .cra_name = "cbc(des)",
.cra_type = &crypto_ablkcipher_type, .cra_driver_name = "cbc-des-sun4i-ss",
.cra_init = sun4i_ss_cipher_init, .cra_priority = 300,
.cra_u.ablkcipher = { .cra_blocksize = DES_BLOCK_SIZE,
.min_keysize = DES_KEY_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.max_keysize = DES_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_req_ctx),
.ivsize = DES_BLOCK_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_des_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_cbc_des_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_cbc_des_decrypt,
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "ecb(des)", .setkey = sun4i_ss_des_setkey,
.cra_driver_name = "ecb-des-sun4i-ss", .encrypt = sun4i_ss_ecb_des_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_ecb_des_decrypt,
.cra_blocksize = DES_BLOCK_SIZE, .min_keysize = DES_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = DES_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_req_ctx), .base = {
.cra_module = THIS_MODULE, .cra_name = "ecb(des)",
.cra_alignmask = 3, .cra_driver_name = "ecb-des-sun4i-ss",
.cra_type = &crypto_ablkcipher_type, .cra_priority = 300,
.cra_init = sun4i_ss_cipher_init, .cra_blocksize = DES_BLOCK_SIZE,
.cra_u.ablkcipher = { .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.min_keysize = DES_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_req_ctx),
.max_keysize = DES_KEY_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_des_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_ecb_des_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_ecb_des_decrypt,
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "cbc(des3_ede)", .setkey = sun4i_ss_des3_setkey,
.cra_driver_name = "cbc-des3-sun4i-ss", .encrypt = sun4i_ss_cbc_des3_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_cbc_des3_decrypt,
.cra_blocksize = DES3_EDE_BLOCK_SIZE, .min_keysize = DES3_EDE_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = DES3_EDE_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_req_ctx), .ivsize = DES3_EDE_BLOCK_SIZE,
.cra_module = THIS_MODULE, .base = {
.cra_alignmask = 3, .cra_name = "cbc(des3_ede)",
.cra_type = &crypto_ablkcipher_type, .cra_driver_name = "cbc-des3-sun4i-ss",
.cra_init = sun4i_ss_cipher_init, .cra_priority = 300,
.cra_u.ablkcipher = { .cra_blocksize = DES3_EDE_BLOCK_SIZE,
.min_keysize = DES3_EDE_KEY_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.max_keysize = DES3_EDE_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_req_ctx),
.ivsize = DES3_EDE_BLOCK_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_des3_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_cbc_des3_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_cbc_des3_decrypt,
} }
} }
}, },
{ .type = CRYPTO_ALG_TYPE_ABLKCIPHER, { .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = { .alg.crypto = {
.cra_name = "ecb(des3_ede)", .setkey = sun4i_ss_des3_setkey,
.cra_driver_name = "ecb-des3-sun4i-ss", .encrypt = sun4i_ss_ecb_des3_encrypt,
.cra_priority = 300, .decrypt = sun4i_ss_ecb_des3_decrypt,
.cra_blocksize = DES3_EDE_BLOCK_SIZE, .min_keysize = DES3_EDE_KEY_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER, .max_keysize = DES3_EDE_KEY_SIZE,
.cra_ctxsize = sizeof(struct sun4i_req_ctx), .ivsize = DES3_EDE_BLOCK_SIZE,
.cra_module = THIS_MODULE, .base = {
.cra_alignmask = 3, .cra_name = "ecb(des3_ede)",
.cra_type = &crypto_ablkcipher_type, .cra_driver_name = "ecb-des3-sun4i-ss",
.cra_init = sun4i_ss_cipher_init, .cra_priority = 300,
.cra_u.ablkcipher = { .cra_blocksize = DES3_EDE_BLOCK_SIZE,
.min_keysize = DES3_EDE_KEY_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER,
.max_keysize = DES3_EDE_KEY_SIZE, .cra_ctxsize = sizeof(struct sun4i_req_ctx),
.ivsize = DES3_EDE_BLOCK_SIZE, .cra_module = THIS_MODULE,
.setkey = sun4i_ss_des3_setkey, .cra_alignmask = 3,
.encrypt = sun4i_ss_ecb_des3_encrypt, .cra_init = sun4i_ss_cipher_init,
.decrypt = sun4i_ss_ecb_des3_decrypt,
} }
} }
}, },
...@@ -340,11 +334,11 @@ static int sun4i_ss_probe(struct platform_device *pdev) ...@@ -340,11 +334,11 @@ static int sun4i_ss_probe(struct platform_device *pdev)
for (i = 0; i < ARRAY_SIZE(ss_algs); i++) { for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
ss_algs[i].ss = ss; ss_algs[i].ss = ss;
switch (ss_algs[i].type) { switch (ss_algs[i].type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER: case CRYPTO_ALG_TYPE_SKCIPHER:
err = crypto_register_alg(&ss_algs[i].alg.crypto); err = crypto_register_skcipher(&ss_algs[i].alg.crypto);
if (err) { if (err) {
dev_err(ss->dev, "Fail to register %s\n", dev_err(ss->dev, "Fail to register %s\n",
ss_algs[i].alg.crypto.cra_name); ss_algs[i].alg.crypto.base.cra_name);
goto error_alg; goto error_alg;
} }
break; break;
...@@ -364,8 +358,8 @@ static int sun4i_ss_probe(struct platform_device *pdev) ...@@ -364,8 +358,8 @@ static int sun4i_ss_probe(struct platform_device *pdev)
i--; i--;
for (; i >= 0; i--) { for (; i >= 0; i--) {
switch (ss_algs[i].type) { switch (ss_algs[i].type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER: case CRYPTO_ALG_TYPE_SKCIPHER:
crypto_unregister_alg(&ss_algs[i].alg.crypto); crypto_unregister_skcipher(&ss_algs[i].alg.crypto);
break; break;
case CRYPTO_ALG_TYPE_AHASH: case CRYPTO_ALG_TYPE_AHASH:
crypto_unregister_ahash(&ss_algs[i].alg.hash); crypto_unregister_ahash(&ss_algs[i].alg.hash);
...@@ -388,8 +382,8 @@ static int sun4i_ss_remove(struct platform_device *pdev) ...@@ -388,8 +382,8 @@ static int sun4i_ss_remove(struct platform_device *pdev)
for (i = 0; i < ARRAY_SIZE(ss_algs); i++) { for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
switch (ss_algs[i].type) { switch (ss_algs[i].type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER: case CRYPTO_ALG_TYPE_SKCIPHER:
crypto_unregister_alg(&ss_algs[i].alg.crypto); crypto_unregister_skcipher(&ss_algs[i].alg.crypto);
break; break;
case CRYPTO_ALG_TYPE_AHASH: case CRYPTO_ALG_TYPE_AHASH:
crypto_unregister_ahash(&ss_algs[i].alg.hash); crypto_unregister_ahash(&ss_algs[i].alg.hash);
......
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <crypto/md5.h> #include <crypto/md5.h>
#include <crypto/skcipher.h>
#include <crypto/sha.h> #include <crypto/sha.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#include <crypto/internal/hash.h> #include <crypto/internal/hash.h>
#include <crypto/internal/skcipher.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/des.h> #include <crypto/des.h>
#include <crypto/internal/rng.h> #include <crypto/internal/rng.h>
...@@ -140,7 +142,7 @@ struct sun4i_ss_alg_template { ...@@ -140,7 +142,7 @@ struct sun4i_ss_alg_template {
u32 type; u32 type;
u32 mode; u32 mode;
union { union {
struct crypto_alg crypto; struct skcipher_alg crypto;
struct ahash_alg hash; struct ahash_alg hash;
} alg; } alg;
struct sun4i_ss_ctx *ss; struct sun4i_ss_ctx *ss;
...@@ -177,25 +179,25 @@ int sun4i_hash_import_md5(struct ahash_request *areq, const void *in); ...@@ -177,25 +179,25 @@ int sun4i_hash_import_md5(struct ahash_request *areq, const void *in);
int sun4i_hash_export_sha1(struct ahash_request *areq, void *out); int sun4i_hash_export_sha1(struct ahash_request *areq, void *out);
int sun4i_hash_import_sha1(struct ahash_request *areq, const void *in); int sun4i_hash_import_sha1(struct ahash_request *areq, const void *in);
int sun4i_ss_cbc_aes_encrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_aes_encrypt(struct skcipher_request *areq);
int sun4i_ss_cbc_aes_decrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_aes_decrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_aes_encrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_aes_encrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_aes_decrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_aes_decrypt(struct skcipher_request *areq);
int sun4i_ss_cbc_des_encrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_des_encrypt(struct skcipher_request *areq);
int sun4i_ss_cbc_des_decrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_des_decrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_des_encrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_des_encrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_des_decrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_des_decrypt(struct skcipher_request *areq);
int sun4i_ss_cbc_des3_encrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_des3_encrypt(struct skcipher_request *areq);
int sun4i_ss_cbc_des3_decrypt(struct ablkcipher_request *areq); int sun4i_ss_cbc_des3_decrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_des3_encrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_des3_encrypt(struct skcipher_request *areq);
int sun4i_ss_ecb_des3_decrypt(struct ablkcipher_request *areq); int sun4i_ss_ecb_des3_decrypt(struct skcipher_request *areq);
int sun4i_ss_cipher_init(struct crypto_tfm *tfm); int sun4i_ss_cipher_init(struct crypto_tfm *tfm);
int sun4i_ss_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, int sun4i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen); unsigned int keylen);
int sun4i_ss_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, int sun4i_ss_des_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen); unsigned int keylen);
int sun4i_ss_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key, int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen); unsigned int keylen);
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