#include <linux/delay.h>
#include <asm/byteorder.h>
#include <crypto/algapi.h>
+#include <crypto/internal/skcipher.h>
#include "ifxmips_deu.h"
int aes_set_key (struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len)
{
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
- unsigned long *flags = (unsigned long *) &tfm->crt_flags;
//printk("set_key in %s\n", __FILE__);
//aes_chip_init();
if (key_len != 16 && key_len != 24 && key_len != 32) {
- *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
}
}
+/*! \fn int aes_set_key_skcipher (struct crypto_skcipher *tfm, const uint8_t *in_key, unsigned int key_len)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief sets the AES keys for skcipher
+ * \param tfm linux crypto skcipher
+ * \param in_key input key
+ * \param key_len key lengths of 16, 24 and 32 bytes supported
+ * \return -EINVAL - bad key length, 0 - SUCCESS
+*/
+int aes_set_key_skcipher (struct crypto_skcipher *tfm, const u8 *in_key, unsigned int key_len)
+{
+ return aes_set_key(crypto_skcipher_tfm(tfm), in_key, key_len);
+}
+
+
/*! \fn void ifx_deu_aes (void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, size_t nbytes, int encdec, int mode)
* \ingroup IFX_AES_FUNCTIONS
* \brief main interface to AES hardware
int ctr_rfc3686_aes_set_key (struct crypto_tfm *tfm, const uint8_t *in_key, unsigned int key_len)
{
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
- unsigned long *flags = (unsigned long *)&tfm->crt_flags;
//printk("ctr_rfc3686_aes_set_key in %s\n", __FILE__);
key_len -= CTR_RFC3686_NONCE_SIZE; // remove 4 bytes of nonce
if (key_len != 16 && key_len != 24 && key_len != 32) {
- *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
}
return 0;
}
+/*!
+ * \fn int ctr_rfc3686_aes_set_key_skcipher (struct crypto_skcipher *tfm, const uint8_t *in_key, unsigned int key_len)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief sets RFC3686 key for skcipher
+ * \param tfm linux crypto skcipher
+ * \param in_key input key
+ * \param key_len key lengths of 20, 28 and 36 bytes supported; last 4 bytes is nonce
+ * \return 0 - SUCCESS
+ * -EINVAL - bad key length
+*/
+int ctr_rfc3686_aes_set_key_skcipher (struct crypto_skcipher *tfm, const uint8_t *in_key, unsigned int key_len)
+{
+ return ctr_rfc3686_aes_set_key(crypto_skcipher_tfm(tfm), in_key, key_len);
+}
+
+
/*! \fn void ifx_deu_aes (void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, u32 nbytes, int encdec, int mode)
* \ingroup IFX_AES_FUNCTIONS
* \brief main interface with deu hardware in DMA mode
/*! \fn void aes_encrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
* \ingroup IFX_AES_FUNCTIONS
- * \brief encrypt AES_BLOCK_SIZE of data
- * \param tfm linux crypto algo transform
- * \param out output bytestream
- * \param in input bytestream
-*/
+ * \brief encrypt AES_BLOCK_SIZE of data
+ * \param tfm linux crypto algo transform
+ * \param out output bytestream
+ * \param in input bytestream
+*/
void aes_encrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
{
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
/*! \fn void aes_decrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
* \ingroup IFX_AES_FUNCTIONS
- * \brief decrypt AES_BLOCK_SIZE of data
- * \param tfm linux crypto algo transform
- * \param out output bytestream
- * \param in input bytestream
-*/
+ * \brief decrypt AES_BLOCK_SIZE of data
+ * \param tfm linux crypto algo transform
+ * \param out output bytestream
+ * \param in input bytestream
+*/
void aes_decrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
{
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
CRYPTO_DIR_DECRYPT, 0);
}
-/*
- * \brief AES function mappings
+/*
+ * \brief AES function mappings
*/
struct crypto_alg ifxdeu_aes_alg = {
.cra_name = "aes",
}
};
-/*! \fn int ecb_aes_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ecb_aes_encrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief ECB AES encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief ECB AES encrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ecb_aes_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ecb_aes_encrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int enc_bytes;
-
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ unsigned int enc_bytes, nbytes;
+
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = enc_bytes = walk.nbytes)) {
enc_bytes -= (nbytes % AES_BLOCK_SIZE);
ifx_deu_aes_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, enc_bytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes &= AES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*! \fn int ecb_aes_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ecb_aes_decrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief ECB AES decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief ECB AES decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ecb_aes_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ecb_aes_decrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int dec_bytes;
+ unsigned int dec_bytes, nbytes;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = dec_bytes = walk.nbytes)) {
dec_bytes -= (nbytes % AES_BLOCK_SIZE);
ifx_deu_aes_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, dec_bytes, CRYPTO_DIR_DECRYPT, 0);
nbytes &= AES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*
+/*
* \brief AES function mappings
*/
-struct crypto_alg ifxdeu_ecb_aes_alg = {
- .cra_name = "ecb(aes)",
- .cra_driver_name = "ifxdeu-ecb(aes)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = AES_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct aes_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_aes_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE,
- .setkey = aes_set_key,
- .encrypt = ecb_aes_encrypt,
- .decrypt = ecb_aes_decrypt,
- }
- }
+struct skcipher_alg ifxdeu_ecb_aes_alg = {
+ .base.cra_name = "ecb(aes)",
+ .base.cra_driver_name = "ifxdeu-ecb(aes)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = AES_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct aes_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ecb_aes_alg.base.cra_list),
+ .min_keysize = AES_MIN_KEY_SIZE,
+ .max_keysize = AES_MAX_KEY_SIZE,
+ .setkey = aes_set_key_skcipher,
+ .encrypt = ecb_aes_encrypt,
+ .decrypt = ecb_aes_decrypt,
};
-/*! \fn int cbc_aes_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ecb_aes_encrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief CBC AES encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief CBC AES encrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int cbc_aes_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int cbc_aes_encrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int enc_bytes;
+ unsigned int enc_bytes, nbytes;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = enc_bytes = walk.nbytes)) {
u8 *iv = walk.iv;
ifx_deu_aes_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
iv, enc_bytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes &= AES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*! \fn int cbc_aes_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int cbc_aes_decrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief CBC AES decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief CBC AES decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int cbc_aes_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int cbc_aes_decrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int dec_bytes;
+ unsigned int dec_bytes, nbytes;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = dec_bytes = walk.nbytes)) {
u8 *iv = walk.iv;
ifx_deu_aes_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
iv, dec_bytes, CRYPTO_DIR_DECRYPT, 0);
nbytes &= AES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
/*
* \brief AES function mappings
*/
-struct crypto_alg ifxdeu_cbc_aes_alg = {
- .cra_name = "cbc(aes)",
- .cra_driver_name = "ifxdeu-cbc(aes)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = AES_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct aes_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_cbc_aes_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE,
- .ivsize = AES_BLOCK_SIZE,
- .setkey = aes_set_key,
- .encrypt = cbc_aes_encrypt,
- .decrypt = cbc_aes_decrypt,
- }
- }
+struct skcipher_alg ifxdeu_cbc_aes_alg = {
+ .base.cra_name = "cbc(aes)",
+ .base.cra_driver_name = "ifxdeu-cbc(aes)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = AES_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct aes_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_cbc_aes_alg.base.cra_list),
+ .min_keysize = AES_MIN_KEY_SIZE,
+ .max_keysize = AES_MAX_KEY_SIZE,
+ .ivsize = AES_BLOCK_SIZE,
+ .setkey = aes_set_key_skcipher,
+ .encrypt = cbc_aes_encrypt,
+ .decrypt = cbc_aes_decrypt,
};
-/*! \fn int ctr_basic_aes_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ctr_basic_aes_encrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief Counter mode AES encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief Counter mode AES encrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ctr_basic_aes_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ctr_basic_aes_encrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
int err;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes)) {
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
walk.iv, nbytes, CRYPTO_DIR_ENCRYPT, 0);
- err = blkcipher_walk_done(desc, &walk, 0);
+ err = skcipher_walk_done(&walk, 0);
}
return err;
}
-/*! \fn int ctr_basic_aes_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ctr_basic_aes_encrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief Counter mode AES decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief Counter mode AES decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ctr_basic_aes_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ctr_basic_aes_decrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
int err;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes)) {
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
walk.iv, nbytes, CRYPTO_DIR_DECRYPT, 0);
- err = blkcipher_walk_done(desc, &walk, 0);
+ err = skcipher_walk_done(&walk, 0);
}
return err;
}
-/*
+/*
* \brief AES function mappings
*/
-struct crypto_alg ifxdeu_ctr_basic_aes_alg = {
- .cra_name = "ctr(aes)",
- .cra_driver_name = "ifxdeu-ctr(aes)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = 1,
- .cra_ctxsize = sizeof(struct aes_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ctr_basic_aes_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE,
- .ivsize = AES_BLOCK_SIZE,
- .setkey = aes_set_key,
- .encrypt = ctr_basic_aes_encrypt,
- .decrypt = ctr_basic_aes_decrypt,
- }
- }
+struct skcipher_alg ifxdeu_ctr_basic_aes_alg = {
+ .base.cra_name = "ctr(aes)",
+ .base.cra_driver_name = "ifxdeu-ctr(aes)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = 1,
+ .base.cra_ctxsize = sizeof(struct aes_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ctr_basic_aes_alg.base.cra_list),
+ .min_keysize = AES_MIN_KEY_SIZE,
+ .max_keysize = AES_MAX_KEY_SIZE,
+ .ivsize = AES_BLOCK_SIZE,
+ .setkey = aes_set_key_skcipher,
+ .encrypt = ctr_basic_aes_encrypt,
+ .decrypt = ctr_basic_aes_decrypt,
};
-/*! \fn int ctr_rfc3686_aes_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ctr_rfc3686_aes_encrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief Counter mode AES (rfc3686) encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief Counter mode AES (rfc3686) encrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ctr_rfc3686_aes_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ctr_rfc3686_aes_encrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
- int err, bsize = nbytes;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
+ int err, bsize;
u8 rfc3686_iv[16];
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
-
+ err = skcipher_walk_virt(&walk, req, false);
+ nbytes = walk.nbytes;
+ bsize = nbytes;
+
/* set up counter block */
memcpy(rfc3686_iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE);
memcpy(rfc3686_iv + CTR_RFC3686_NONCE_SIZE, walk.iv, CTR_RFC3686_IV_SIZE);
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
rfc3686_iv, nbytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes -= walk.nbytes;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
return err;
}
nbytes -= walk.nbytes;
bsize -= walk.nbytes;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
/* to handle remaining bytes < AES_BLOCK_SIZE */
if (walk.nbytes) {
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
rfc3686_iv, walk.nbytes, CRYPTO_DIR_ENCRYPT, 0);
- err = blkcipher_walk_done(desc, &walk, 0);
+ err = skcipher_walk_done(&walk, 0);
}
-
+
return err;
}
-/*! \fn int ctr_rfc3686_aes_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn int ctr_rfc3686_aes_decrypt(struct skcipher_req *req)
* \ingroup IFX_AES_FUNCTIONS
- * \brief Counter mode AES (rfc3686) decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+ * \brief Counter mode AES (rfc3686) decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ctr_rfc3686_aes_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ctr_rfc3686_aes_decrypt(struct skcipher_request *req)
{
- struct aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
- int err, bsize = nbytes;
+ struct aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
+ int err, bsize;
u8 rfc3686_iv[16];
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
+ nbytes = walk.nbytes;
+ bsize = nbytes;
/* set up counter block */
memcpy(rfc3686_iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE);
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
rfc3686_iv, nbytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes -= walk.nbytes;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
return err;
}
nbytes -= walk.nbytes;
bsize -= walk.nbytes;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
/* to handle remaining bytes < AES_BLOCK_SIZE */
if (walk.nbytes) {
ifx_deu_aes_ctr(ctx, walk.dst.virt.addr, walk.src.virt.addr,
rfc3686_iv, walk.nbytes, CRYPTO_DIR_ENCRYPT, 0);
- err = blkcipher_walk_done(desc, &walk, 0);
+ err = skcipher_walk_done(&walk, 0);
}
return err;
}
-/*
+/*
* \brief AES function mappings
*/
-struct crypto_alg ifxdeu_ctr_rfc3686_aes_alg = {
- .cra_name = "rfc3686(ctr(aes))",
- .cra_driver_name = "ifxdeu-ctr-rfc3686(aes)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = 1,
- .cra_ctxsize = sizeof(struct aes_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ctr_rfc3686_aes_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = CTR_RFC3686_MAX_KEY_SIZE,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .setkey = ctr_rfc3686_aes_set_key,
- .encrypt = ctr_rfc3686_aes_encrypt,
- .decrypt = ctr_rfc3686_aes_decrypt,
- }
- }
+struct skcipher_alg ifxdeu_ctr_rfc3686_aes_alg = {
+ .base.cra_name = "rfc3686(ctr(aes))",
+ .base.cra_driver_name = "ifxdeu-ctr-rfc3686(aes)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = 1,
+ .base.cra_ctxsize = sizeof(struct aes_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ctr_rfc3686_aes_alg.base.cra_list),
+ .min_keysize = AES_MIN_KEY_SIZE,
+ .max_keysize = CTR_RFC3686_MAX_KEY_SIZE,
+ .ivsize = CTR_RFC3686_IV_SIZE,
+ .setkey = ctr_rfc3686_aes_set_key_skcipher,
+ .encrypt = ctr_rfc3686_aes_encrypt,
+ .decrypt = ctr_rfc3686_aes_decrypt,
};
/*! \fn int ifxdeu_init_aes (void)
* \ingroup IFX_AES_FUNCTIONS
- * \brief function to initialize AES driver
- * \return ret
-*/
+ * \brief function to initialize AES driver
+ * \return ret
+*/
int ifxdeu_init_aes (void)
{
int ret = -ENOSYS;
if ((ret = crypto_register_alg(&ifxdeu_aes_alg)))
goto aes_err;
- if ((ret = crypto_register_alg(&ifxdeu_ecb_aes_alg)))
+ if ((ret = crypto_register_skcipher(&ifxdeu_ecb_aes_alg)))
goto ecb_aes_err;
- if ((ret = crypto_register_alg(&ifxdeu_cbc_aes_alg)))
+ if ((ret = crypto_register_skcipher(&ifxdeu_cbc_aes_alg)))
goto cbc_aes_err;
- if ((ret = crypto_register_alg(&ifxdeu_ctr_basic_aes_alg)))
+ if ((ret = crypto_register_skcipher(&ifxdeu_ctr_basic_aes_alg)))
goto ctr_basic_aes_err;
- if ((ret = crypto_register_alg(&ifxdeu_ctr_rfc3686_aes_alg)))
+ if ((ret = crypto_register_skcipher(&ifxdeu_ctr_rfc3686_aes_alg)))
goto ctr_rfc3686_aes_err;
CRTCL_SECT_INIT;
return ret;
ctr_rfc3686_aes_err:
- crypto_unregister_alg(&ifxdeu_ctr_rfc3686_aes_alg);
+ crypto_unregister_skcipher(&ifxdeu_ctr_rfc3686_aes_alg);
printk (KERN_ERR "IFX ctr_rfc3686_aes initialization failed!\n");
return ret;
ctr_basic_aes_err:
- crypto_unregister_alg(&ifxdeu_ctr_basic_aes_alg);
+ crypto_unregister_skcipher(&ifxdeu_ctr_basic_aes_alg);
printk (KERN_ERR "IFX ctr_basic_aes initialization failed!\n");
return ret;
cbc_aes_err:
- crypto_unregister_alg(&ifxdeu_cbc_aes_alg);
+ crypto_unregister_skcipher(&ifxdeu_cbc_aes_alg);
printk (KERN_ERR "IFX cbc_aes initialization failed!\n");
return ret;
ecb_aes_err:
- crypto_unregister_alg(&ifxdeu_ecb_aes_alg);
+ crypto_unregister_skcipher(&ifxdeu_ecb_aes_alg);
printk (KERN_ERR "IFX aes initialization failed!\n");
return ret;
aes_err:
/*! \fn void ifxdeu_fini_aes (void)
* \ingroup IFX_AES_FUNCTIONS
- * \brief unregister aes driver
-*/
+ * \brief unregister aes driver
+*/
void ifxdeu_fini_aes (void)
{
crypto_unregister_alg (&ifxdeu_aes_alg);
- crypto_unregister_alg (&ifxdeu_ecb_aes_alg);
- crypto_unregister_alg (&ifxdeu_cbc_aes_alg);
- crypto_unregister_alg (&ifxdeu_ctr_basic_aes_alg);
- crypto_unregister_alg (&ifxdeu_ctr_rfc3686_aes_alg);
+ crypto_unregister_skcipher (&ifxdeu_ecb_aes_alg);
+ crypto_unregister_skcipher (&ifxdeu_cbc_aes_alg);
+ crypto_unregister_skcipher (&ifxdeu_ctr_basic_aes_alg);
+ crypto_unregister_skcipher (&ifxdeu_ctr_rfc3686_aes_alg);
}
-
-
#include <linux/errno.h>
#include <linux/crypto.h>
#include <crypto/algapi.h>
+#include <crypto/internal/skcipher.h>
#include <linux/interrupt.h>
#include <asm/byteorder.h>
#include <linux/delay.h>
return 0;
}
+/*! \fn static int arc4_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *in_key, unsigned int key_len)
+ \ingroup IFX_ARC4_FUNCTIONS
+ \brief sets ARC4 key
+ \param tfm linux crypto skcipher
+ \param in_key input key
+ \param key_len key lengths less than or equal to 16 bytes supported
+*/
+static int arc4_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *inkey,
+ unsigned int key_len)
+{
+ return arc4_set_key(crypto_skcipher_ctx(tfm), inkey, key_len);
+}
+
/*! \fn static void _deu_arc4_ecb(void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
\ingroup IFX_ARC4_FUNCTIONS
\brief sets ARC4 hardware to ECB mode
}
};
-/*! \fn static int ecb_arc4_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn static int ecb_arc4_encrypt(struct skcipher_request *req)
\ingroup IFX_ARC4_FUNCTIONS
- \brief ECB ARC4 encrypt using linux crypto blkcipher
- \param desc blkcipher descriptor
- \param dst output scatterlist
- \param src input scatterlist
- \param nbytes data size in bytes
-*/
-static int ecb_arc4_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+ \brief ECB ARC4 encrypt using linux crypto skcipher
+ \param req skcipher_request
+*/
+static int ecb_arc4_encrypt(struct skcipher_request *req)
{
- struct arc4_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct arc4_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
int err;
DPRINTF(1, "\n");
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes)) {
_deu_arc4_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, nbytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes &= ARC4_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*! \fn static int ecb_arc4_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
+/*! \fn static int ecb_arc4_decrypt(struct skcipher_request *req)
\ingroup IFX_ARC4_FUNCTIONS
- \brief ECB ARC4 decrypt using linux crypto blkcipher
- \param desc blkcipher descriptor
- \param dst output scatterlist
- \param src input scatterlist
- \param nbytes data size in bytes
-*/
-static int ecb_arc4_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+ \brief ECB ARC4 decrypt using linux crypto skcipher
+ \param desc skcipher_request
+*/
+static int ecb_arc4_decrypt(struct skcipher_request *req)
{
- struct arc4_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct arc4_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
+ unsigned int nbytes;
int err;
DPRINTF(1, "\n");
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes)) {
_deu_arc4_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, nbytes, CRYPTO_DIR_DECRYPT, 0);
nbytes &= ARC4_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
/*
* \brief ARC4 function mappings
*/
-static struct crypto_alg ifxdeu_ecb_arc4_alg = {
- .cra_name = "ecb(arc4)",
- .cra_driver_name = "ifxdeu-ecb(arc4)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = ARC4_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct arc4_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_arc4_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = ARC4_MIN_KEY_SIZE,
- .max_keysize = ARC4_MAX_KEY_SIZE,
- .setkey = arc4_set_key,
- .encrypt = ecb_arc4_encrypt,
- .decrypt = ecb_arc4_decrypt,
- }
- }
+static struct skcipher_alg ifxdeu_ecb_arc4_alg = {
+ .base.cra_name = "ecb(arc4)",
+ .base.cra_driver_name = "ifxdeu-ecb(arc4)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = ARC4_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct arc4_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ecb_arc4_alg.base.cra_list),
+ .min_keysize = ARC4_MIN_KEY_SIZE,
+ .max_keysize = ARC4_MAX_KEY_SIZE,
+ .setkey = arc4_set_key_skcipher,
+ .encrypt = ecb_arc4_encrypt,
+ .decrypt = ecb_arc4_decrypt,
};
/*! \fn int ifxdeu_init_arc4(void)
if ((ret = crypto_register_alg(&ifxdeu_arc4_alg)))
goto arc4_err;
- if ((ret = crypto_register_alg(&ifxdeu_ecb_arc4_alg)))
+ if ((ret = crypto_register_skcipher(&ifxdeu_ecb_arc4_alg)))
goto ecb_arc4_err;
arc4_chip_init ();
printk(KERN_ERR "IFX arc4 initialization failed!\n");
return ret;
ecb_arc4_err:
- crypto_unregister_alg(&ifxdeu_ecb_arc4_alg);
+ crypto_unregister_skcipher(&ifxdeu_ecb_arc4_alg);
printk (KERN_ERR "IFX ecb_arc4 initialization failed!\n");
return ret;
void ifxdeu_fini_arc4(void)
{
crypto_unregister_alg (&ifxdeu_arc4_alg);
- crypto_unregister_alg (&ifxdeu_ecb_arc4_alg);
+ crypto_unregister_skcipher (&ifxdeu_ecb_arc4_alg);
}
#include <linux/delay.h>
#include <asm/byteorder.h>
#include <crypto/algapi.h>
+#include <crypto/internal/skcipher.h>
#include "ifxmips_deu.h"
#if defined(CONFIG_DANUBE)
}
+/*! \fn int des_set_key (struct crypto_skcipher *tfm, const uint8_t *in_key, unsigned int key_len)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief sets the AES keys for skcipher
+ * \param tfm linux crypto skcipher
+ * \param in_key input key
+ * \param key_len key lengths of 16, 24 and 32 bytes supported
+ * \return -EINVAL - bad key length, 0 - SUCCESS
+*/
+int des_setkey_skcipher (struct crypto_skcipher *tfm, const u8 *in_key, unsigned int key_len)
+{
+ return des_setkey(crypto_skcipher_tfm(tfm), in_key, key_len);
+}
+
+
/*! \fn void ifx_deu_des(void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, u32 nbytes, int encdec, int mode)
* \ingroup IFX_DES_FUNCTIONS
* \brief main interface to DES hardware
return 0;
}
+/*! \fn int des3_ede_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen)
+ * \ingroup IFX_DES_FUNCTIONS
+ * \brief sets 3DES key
+ * \param tfm linux crypto skcipher transform
+ * \param key input key
+ * \param keylen key length
+*/
+int des3_ede_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
+ unsigned int keylen)
+{
+ return des3_ede_setkey(crypto_skcipher_tfm(tfm), key, keylen);
+}
+
/*
* \brief DES function mappings
*/
.cia_decrypt = des_decrypt } }
};
-/*! \fn int ecb_des_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
- * \ingroup IFX_DES_FUNCTIONS
- * \brief ECB DES encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
-*/
-int ecb_des_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+/*! \fn int ecb_des_encrypt(struct skcipher_req *req)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief ECB DES encrypt using linux crypto skcipher
+ * \param req skcipher request
+ * \return err
+*/
+int ecb_des_encrypt(struct skcipher_request *req)
{
- struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct des_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int enc_bytes;
+ unsigned int enc_bytes, nbytes;
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = enc_bytes = walk.nbytes)) {
enc_bytes -= (nbytes % DES_BLOCK_SIZE);
ifx_deu_des_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, enc_bytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes &= DES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*! \fn int ecb_des_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
- * \ingroup IFX_DES_FUNCTIONS
- * \brief ECB DES decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+/*! \fn int ecb_des_decrypt(struct skcipher_req *req)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief ECB DES decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int ecb_des_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int ecb_des_decrypt(struct skcipher_request *req)
{
- struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct des_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int dec_bytes;
+ unsigned int dec_bytes, nbytes;
DPRINTF(1, "\n");
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = dec_bytes = walk.nbytes)) {
dec_bytes -= (nbytes % DES_BLOCK_SIZE);
ifx_deu_des_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
NULL, dec_bytes, CRYPTO_DIR_DECRYPT, 0);
nbytes &= DES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
/*
* \brief DES function mappings
-*/
-struct crypto_alg ifxdeu_ecb_des_alg = {
- .cra_name = "ecb(des)",
- .cra_driver_name = "ifxdeu-ecb(des)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = DES_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = DES_KEY_SIZE,
- .max_keysize = DES_KEY_SIZE,
- .setkey = des_setkey,
- .encrypt = ecb_des_encrypt,
- .decrypt = ecb_des_decrypt,
- }
- }
+*/
+struct skcipher_alg ifxdeu_ecb_des_alg = {
+ .base.cra_name = "ecb(des)",
+ .base.cra_driver_name = "ifxdeu-ecb(des)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = DES_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct des_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des_alg.base.cra_list),
+ .min_keysize = DES_KEY_SIZE,
+ .max_keysize = DES_KEY_SIZE,
+ .setkey = des_setkey_skcipher,
+ .encrypt = ecb_des_encrypt,
+ .decrypt = ecb_des_decrypt,
};
/*
* \brief DES function mappings
-*/
-struct crypto_alg ifxdeu_ecb_des3_ede_alg = {
- .cra_name = "ecb(des3_ede)",
- .cra_driver_name = "ifxdeu-ecb(des3_ede)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des3_ede_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = DES3_EDE_KEY_SIZE,
- .max_keysize = DES3_EDE_KEY_SIZE,
- .setkey = des3_ede_setkey,
- .encrypt = ecb_des_encrypt,
- .decrypt = ecb_des_decrypt,
- }
- }
+*/
+struct skcipher_alg ifxdeu_ecb_des3_ede_alg = {
+ .base.cra_name = "ecb(des3_ede)",
+ .base.cra_driver_name = "ifxdeu-ecb(des3_ede)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct des_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des3_ede_alg.base.cra_list),
+ .min_keysize = DES3_EDE_KEY_SIZE,
+ .max_keysize = DES3_EDE_KEY_SIZE,
+ .setkey = des3_ede_setkey_skcipher,
+ .encrypt = ecb_des_encrypt,
+ .decrypt = ecb_des_decrypt,
};
-/*! \fn int cbc_des_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
- * \ingroup IFX_DES_FUNCTIONS
- * \brief CBC DES encrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+/*! \fn int cbc_des_encrypt(struct skcipher_req *req)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief CBC DES encrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int cbc_des_encrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int cbc_des_encrypt(struct skcipher_request *req)
{
- struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct des_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int enc_bytes;
+ unsigned int enc_bytes, nbytes;
DPRINTF(1, "\n");
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = enc_bytes = walk.nbytes)) {
u8 *iv = walk.iv;
ifx_deu_des_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
iv, enc_bytes, CRYPTO_DIR_ENCRYPT, 0);
nbytes &= DES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
}
-/*! \fn int cbc_des_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
- * \ingroup IFX_DES_FUNCTIONS
- * \brief CBC DES decrypt using linux crypto blkcipher
- * \param desc blkcipher descriptor
- * \param dst output scatterlist
- * \param src input scatterlist
- * \param nbytes data size in bytes
+/*! \fn int cbc_des_encrypt(struct skcipher_req *req)
+ * \ingroup IFX_AES_FUNCTIONS
+ * \brief CBC DES decrypt using linux crypto skcipher
+ * \param req skcipher request
* \return err
-*/
-int cbc_des_decrypt(struct blkcipher_desc *desc,
- struct scatterlist *dst, struct scatterlist *src,
- unsigned int nbytes)
+*/
+int cbc_des_decrypt(struct skcipher_request *req)
{
- struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
- struct blkcipher_walk walk;
+ struct des_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ struct skcipher_walk walk;
int err;
- unsigned int dec_bytes;
+ unsigned int dec_bytes, nbytes;
DPRINTF(1, "\n");
- blkcipher_walk_init(&walk, dst, src, nbytes);
- err = blkcipher_walk_virt(desc, &walk);
+ err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = dec_bytes = walk.nbytes)) {
u8 *iv = walk.iv;
ifx_deu_des_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
iv, dec_bytes, CRYPTO_DIR_DECRYPT, 0);
nbytes &= DES_BLOCK_SIZE - 1;
- err = blkcipher_walk_done(desc, &walk, nbytes);
+ err = skcipher_walk_done(&walk, nbytes);
}
return err;
/*
* \brief DES function mappings
-*/
-struct crypto_alg ifxdeu_cbc_des_alg = {
- .cra_name = "cbc(des)",
- .cra_driver_name = "ifxdeu-cbc(des)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = DES_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = DES_KEY_SIZE,
- .max_keysize = DES_KEY_SIZE,
- .ivsize = DES_BLOCK_SIZE,
- .setkey = des_setkey,
- .encrypt = cbc_des_encrypt,
- .decrypt = cbc_des_decrypt,
- }
- }
+*/
+struct skcipher_alg ifxdeu_cbc_des_alg = {
+ .base.cra_name = "cbc(des)",
+ .base.cra_driver_name = "ifxdeu-cbc(des)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = DES_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct des_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des_alg.base.cra_list),
+ .min_keysize = DES_KEY_SIZE,
+ .max_keysize = DES_KEY_SIZE,
+ .ivsize = DES_BLOCK_SIZE,
+ .setkey = des_setkey_skcipher,
+ .encrypt = cbc_des_encrypt,
+ .decrypt = cbc_des_decrypt,
};
/*
* \brief DES function mappings
-*/
-struct crypto_alg ifxdeu_cbc_des3_ede_alg = {
- .cra_name = "cbc(des3_ede)",
- .cra_driver_name = "ifxdeu-cbc(des3_ede)",
- .cra_priority = 400,
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des_ctx),
- .cra_type = &crypto_blkcipher_type,
- .cra_module = THIS_MODULE,
- .cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des3_ede_alg.cra_list),
- .cra_u = {
- .blkcipher = {
- .min_keysize = DES3_EDE_KEY_SIZE,
- .max_keysize = DES3_EDE_KEY_SIZE,
- .ivsize = DES_BLOCK_SIZE,
- .setkey = des3_ede_setkey,
- .encrypt = cbc_des_encrypt,
- .decrypt = cbc_des_decrypt,
- }
- }
+*/
+struct skcipher_alg ifxdeu_cbc_des3_ede_alg = {
+ .base.cra_name = "cbc(des3_ede)",
+ .base.cra_driver_name = "ifxdeu-cbc(des3_ede)",
+ .base.cra_priority = 400,
+ .base.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_KERN_DRIVER_ONLY,
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct des_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des3_ede_alg.base.cra_list),
+ .min_keysize = DES3_EDE_KEY_SIZE,
+ .max_keysize = DES3_EDE_KEY_SIZE,
+ .ivsize = DES_BLOCK_SIZE,
+ .setkey = des3_ede_setkey_skcipher,
+ .encrypt = cbc_des_encrypt,
+ .decrypt = cbc_des_decrypt,
};
/*! \fn int ifxdeu_init_des (void)
if (ret < 0)
goto des_err;
- ret = crypto_register_alg(&ifxdeu_ecb_des_alg);
+ ret = crypto_register_skcipher(&ifxdeu_ecb_des_alg);
if (ret < 0)
goto ecb_des_err;
- ret = crypto_register_alg(&ifxdeu_cbc_des_alg);
+ ret = crypto_register_skcipher(&ifxdeu_cbc_des_alg);
if (ret < 0)
goto cbc_des_err;
if (ret < 0)
goto des3_ede_err;
- ret = crypto_register_alg(&ifxdeu_ecb_des3_ede_alg);
+ ret = crypto_register_skcipher(&ifxdeu_ecb_des3_ede_alg);
if (ret < 0)
goto ecb_des3_ede_err;
- ret = crypto_register_alg(&ifxdeu_cbc_des3_ede_alg);
+ ret = crypto_register_skcipher(&ifxdeu_cbc_des3_ede_alg);
if (ret < 0)
goto cbc_des3_ede_err;
printk(KERN_ERR "IFX des initialization failed!\n");
return ret;
ecb_des_err:
- crypto_unregister_alg(&ifxdeu_ecb_des_alg);
+ crypto_unregister_skcipher(&ifxdeu_ecb_des_alg);
printk (KERN_ERR "IFX ecb_des initialization failed!\n");
return ret;
cbc_des_err:
- crypto_unregister_alg(&ifxdeu_cbc_des_alg);
+ crypto_unregister_skcipher(&ifxdeu_cbc_des_alg);
printk (KERN_ERR "IFX cbc_des initialization failed!\n");
return ret;
des3_ede_err:
printk(KERN_ERR "IFX des3_ede initialization failed!\n");
return ret;
ecb_des3_ede_err:
- crypto_unregister_alg(&ifxdeu_ecb_des3_ede_alg);
+ crypto_unregister_skcipher(&ifxdeu_ecb_des3_ede_alg);
printk (KERN_ERR "IFX ecb_des3_ede initialization failed!\n");
return ret;
cbc_des3_ede_err:
- crypto_unregister_alg(&ifxdeu_cbc_des3_ede_alg);
+ crypto_unregister_skcipher(&ifxdeu_cbc_des3_ede_alg);
printk (KERN_ERR "IFX cbc_des3_ede initialization failed!\n");
return ret;
void ifxdeu_fini_des (void)
{
crypto_unregister_alg (&ifxdeu_des_alg);
- crypto_unregister_alg (&ifxdeu_ecb_des_alg);
- crypto_unregister_alg (&ifxdeu_cbc_des_alg);
+ crypto_unregister_skcipher (&ifxdeu_ecb_des_alg);
+ crypto_unregister_skcipher (&ifxdeu_cbc_des_alg);
crypto_unregister_alg (&ifxdeu_des3_ede_alg);
- crypto_unregister_alg (&ifxdeu_ecb_des3_ede_alg);
- crypto_unregister_alg (&ifxdeu_cbc_des3_ede_alg);
+ crypto_unregister_skcipher (&ifxdeu_ecb_des3_ede_alg);
+ crypto_unregister_skcipher (&ifxdeu_cbc_des3_ede_alg);
}