[CRYPTO] skcipher: Add skcipher_geniv_alloc/skcipher_geniv_free

This patch creates the infrastructure to help the construction of givcipher
templates that wrap around existing blkcipher/ablkcipher algorithms by adding
an IV generator to them.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Herbert Xu
2008-01-11 08:16:44 +11:00
parent 927eead52c
commit ecfc43292f
4 changed files with 225 additions and 6 deletions
+18
View File
@@ -15,6 +15,9 @@
#include <crypto/algapi.h>
#include <crypto/skcipher.h>
#include <linux/types.h>
struct rtattr;
struct crypto_skcipher_spawn {
struct crypto_spawn base;
@@ -50,6 +53,21 @@ static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
crypto_skcipher_mask(0)));
}
const char *crypto_default_geniv(const struct crypto_alg *alg);
struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
struct rtattr **tb, u32 type,
u32 mask);
void skcipher_geniv_free(struct crypto_instance *inst);
int skcipher_geniv_init(struct crypto_tfm *tfm);
void skcipher_geniv_exit(struct crypto_tfm *tfm);
static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
struct crypto_ablkcipher *geniv)
{
return crypto_ablkcipher_crt(geniv)->base;
}
static inline void *skcipher_givcrypt_reqctx(
struct skcipher_givcrypt_request *req)
{
+14 -4
View File
@@ -52,6 +52,12 @@
*/
#define CRYPTO_ALG_NEED_FALLBACK 0x00000100
/*
* This bit is set for symmetric key ciphers that have already been wrapped
* with a generic IV generator to prevent them from being wrapped again.
*/
#define CRYPTO_ALG_GENIV 0x00000200
/*
* Transform masks and values (for crt_flags).
*/
@@ -331,6 +337,8 @@ struct ablkcipher_tfm {
int (*givencrypt)(struct skcipher_givcrypt_request *req);
int (*givdecrypt)(struct skcipher_givcrypt_request *req);
struct crypto_ablkcipher *base;
unsigned int ivsize;
unsigned int reqsize;
};
@@ -541,14 +549,14 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
static inline u32 crypto_skcipher_type(u32 type)
{
type &= ~CRYPTO_ALG_TYPE_MASK;
type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
return type;
}
static inline u32 crypto_skcipher_mask(u32 mask)
{
mask &= ~CRYPTO_ALG_TYPE_MASK;
mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
return mask;
}
@@ -623,7 +631,9 @@ static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
const u8 *key, unsigned int keylen)
{
return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
return crt->setkey(crt->base, key, keylen);
}
static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
@@ -655,7 +665,7 @@ static inline unsigned int crypto_ablkcipher_reqsize(
static inline void ablkcipher_request_set_tfm(
struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
{
req->base.tfm = crypto_ablkcipher_tfm(tfm);
req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base);
}
static inline struct ablkcipher_request *ablkcipher_request_cast(