aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-12-05 05:08:36 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-01-10 16:16:44 -0500
commitecfc43292f68566c144afca966b46b371c26d56c (patch)
treeef332abe1573434836a90e188257a252ca9f896a /include
parent927eead52c958829ef62c8aa5da2751033a2cf98 (diff)
[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>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/internal/skcipher.h18
-rw-r--r--include/linux/crypto.h18
2 files changed, 32 insertions, 4 deletions
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
index c9402dd12d03..07e7c82324ad 100644
--- a/include/crypto/internal/skcipher.h
+++ b/include/crypto/internal/skcipher.h
@@ -15,6 +15,9 @@
15 15
16#include <crypto/algapi.h> 16#include <crypto/algapi.h>
17#include <crypto/skcipher.h> 17#include <crypto/skcipher.h>
18#include <linux/types.h>
19
20struct rtattr;
18 21
19struct crypto_skcipher_spawn { 22struct crypto_skcipher_spawn {
20 struct crypto_spawn base; 23 struct crypto_spawn base;
@@ -50,6 +53,21 @@ static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
50 crypto_skcipher_mask(0))); 53 crypto_skcipher_mask(0)));
51} 54}
52 55
56const char *crypto_default_geniv(const struct crypto_alg *alg);
57
58struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
59 struct rtattr **tb, u32 type,
60 u32 mask);
61void skcipher_geniv_free(struct crypto_instance *inst);
62int skcipher_geniv_init(struct crypto_tfm *tfm);
63void skcipher_geniv_exit(struct crypto_tfm *tfm);
64
65static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
66 struct crypto_ablkcipher *geniv)
67{
68 return crypto_ablkcipher_crt(geniv)->base;
69}
70
53static inline void *skcipher_givcrypt_reqctx( 71static inline void *skcipher_givcrypt_reqctx(
54 struct skcipher_givcrypt_request *req) 72 struct skcipher_givcrypt_request *req)
55{ 73{
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index facafa1bd8ca..fa7afa9b9f4f 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -53,6 +53,12 @@
53#define CRYPTO_ALG_NEED_FALLBACK 0x00000100 53#define CRYPTO_ALG_NEED_FALLBACK 0x00000100
54 54
55/* 55/*
56 * This bit is set for symmetric key ciphers that have already been wrapped
57 * with a generic IV generator to prevent them from being wrapped again.
58 */
59#define CRYPTO_ALG_GENIV 0x00000200
60
61/*
56 * Transform masks and values (for crt_flags). 62 * Transform masks and values (for crt_flags).
57 */ 63 */
58#define CRYPTO_TFM_REQ_MASK 0x000fff00 64#define CRYPTO_TFM_REQ_MASK 0x000fff00
@@ -331,6 +337,8 @@ struct ablkcipher_tfm {
331 int (*givencrypt)(struct skcipher_givcrypt_request *req); 337 int (*givencrypt)(struct skcipher_givcrypt_request *req);
332 int (*givdecrypt)(struct skcipher_givcrypt_request *req); 338 int (*givdecrypt)(struct skcipher_givcrypt_request *req);
333 339
340 struct crypto_ablkcipher *base;
341
334 unsigned int ivsize; 342 unsigned int ivsize;
335 unsigned int reqsize; 343 unsigned int reqsize;
336}; 344};
@@ -541,14 +549,14 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
541 549
542static inline u32 crypto_skcipher_type(u32 type) 550static inline u32 crypto_skcipher_type(u32 type)
543{ 551{
544 type &= ~CRYPTO_ALG_TYPE_MASK; 552 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
545 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 553 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
546 return type; 554 return type;
547} 555}
548 556
549static inline u32 crypto_skcipher_mask(u32 mask) 557static inline u32 crypto_skcipher_mask(u32 mask)
550{ 558{
551 mask &= ~CRYPTO_ALG_TYPE_MASK; 559 mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
552 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; 560 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
553 return mask; 561 return mask;
554} 562}
@@ -623,7 +631,9 @@ static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
623static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, 631static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
624 const u8 *key, unsigned int keylen) 632 const u8 *key, unsigned int keylen)
625{ 633{
626 return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen); 634 struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
635
636 return crt->setkey(crt->base, key, keylen);
627} 637}
628 638
629static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm( 639static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
@@ -655,7 +665,7 @@ static inline unsigned int crypto_ablkcipher_reqsize(
655static inline void ablkcipher_request_set_tfm( 665static inline void ablkcipher_request_set_tfm(
656 struct ablkcipher_request *req, struct crypto_ablkcipher *tfm) 666 struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
657{ 667{
658 req->base.tfm = crypto_ablkcipher_tfm(tfm); 668 req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base);
659} 669}
660 670
661static inline struct ablkcipher_request *ablkcipher_request_cast( 671static inline struct ablkcipher_request *ablkcipher_request_cast(