aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/crypto.h')
-rw-r--r--include/linux/crypto.h214
1 files changed, 210 insertions, 4 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 357e8cfedc37..fc32694287e2 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -34,6 +34,7 @@
34#define CRYPTO_ALG_TYPE_HASH 0x00000003 34#define CRYPTO_ALG_TYPE_HASH 0x00000003
35#define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 35#define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
36#define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 36#define CRYPTO_ALG_TYPE_COMPRESS 0x00000005
37#define CRYPTO_ALG_TYPE_AEAD 0x00000006
37 38
38#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e 39#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
39 40
@@ -91,9 +92,9 @@
91struct scatterlist; 92struct scatterlist;
92struct crypto_ablkcipher; 93struct crypto_ablkcipher;
93struct crypto_async_request; 94struct crypto_async_request;
95struct crypto_aead;
94struct crypto_blkcipher; 96struct crypto_blkcipher;
95struct crypto_hash; 97struct crypto_hash;
96struct crypto_queue;
97struct crypto_tfm; 98struct crypto_tfm;
98struct crypto_type; 99struct crypto_type;
99 100
@@ -121,6 +122,32 @@ struct ablkcipher_request {
121 void *__ctx[] CRYPTO_MINALIGN_ATTR; 122 void *__ctx[] CRYPTO_MINALIGN_ATTR;
122}; 123};
123 124
125/**
126 * struct aead_request - AEAD request
127 * @base: Common attributes for async crypto requests
128 * @assoclen: Length in bytes of associated data for authentication
129 * @cryptlen: Length of data to be encrypted or decrypted
130 * @iv: Initialisation vector
131 * @assoc: Associated data
132 * @src: Source data
133 * @dst: Destination data
134 * @__ctx: Start of private context data
135 */
136struct aead_request {
137 struct crypto_async_request base;
138
139 unsigned int assoclen;
140 unsigned int cryptlen;
141
142 u8 *iv;
143
144 struct scatterlist *assoc;
145 struct scatterlist *src;
146 struct scatterlist *dst;
147
148 void *__ctx[] CRYPTO_MINALIGN_ATTR;
149};
150
124struct blkcipher_desc { 151struct blkcipher_desc {
125 struct crypto_blkcipher *tfm; 152 struct crypto_blkcipher *tfm;
126 void *info; 153 void *info;
@@ -150,13 +177,21 @@ struct ablkcipher_alg {
150 int (*encrypt)(struct ablkcipher_request *req); 177 int (*encrypt)(struct ablkcipher_request *req);
151 int (*decrypt)(struct ablkcipher_request *req); 178 int (*decrypt)(struct ablkcipher_request *req);
152 179
153 struct crypto_queue *queue;
154
155 unsigned int min_keysize; 180 unsigned int min_keysize;
156 unsigned int max_keysize; 181 unsigned int max_keysize;
157 unsigned int ivsize; 182 unsigned int ivsize;
158}; 183};
159 184
185struct aead_alg {
186 int (*setkey)(struct crypto_aead *tfm, const u8 *key,
187 unsigned int keylen);
188 int (*encrypt)(struct aead_request *req);
189 int (*decrypt)(struct aead_request *req);
190
191 unsigned int ivsize;
192 unsigned int authsize;
193};
194
160struct blkcipher_alg { 195struct blkcipher_alg {
161 int (*setkey)(struct crypto_tfm *tfm, const u8 *key, 196 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
162 unsigned int keylen); 197 unsigned int keylen);
@@ -212,6 +247,7 @@ struct compress_alg {
212}; 247};
213 248
214#define cra_ablkcipher cra_u.ablkcipher 249#define cra_ablkcipher cra_u.ablkcipher
250#define cra_aead cra_u.aead
215#define cra_blkcipher cra_u.blkcipher 251#define cra_blkcipher cra_u.blkcipher
216#define cra_cipher cra_u.cipher 252#define cra_cipher cra_u.cipher
217#define cra_digest cra_u.digest 253#define cra_digest cra_u.digest
@@ -237,6 +273,7 @@ struct crypto_alg {
237 273
238 union { 274 union {
239 struct ablkcipher_alg ablkcipher; 275 struct ablkcipher_alg ablkcipher;
276 struct aead_alg aead;
240 struct blkcipher_alg blkcipher; 277 struct blkcipher_alg blkcipher;
241 struct cipher_alg cipher; 278 struct cipher_alg cipher;
242 struct digest_alg digest; 279 struct digest_alg digest;
@@ -284,6 +321,16 @@ struct ablkcipher_tfm {
284 unsigned int reqsize; 321 unsigned int reqsize;
285}; 322};
286 323
324struct aead_tfm {
325 int (*setkey)(struct crypto_aead *tfm, const u8 *key,
326 unsigned int keylen);
327 int (*encrypt)(struct aead_request *req);
328 int (*decrypt)(struct aead_request *req);
329 unsigned int ivsize;
330 unsigned int authsize;
331 unsigned int reqsize;
332};
333
287struct blkcipher_tfm { 334struct blkcipher_tfm {
288 void *iv; 335 void *iv;
289 int (*setkey)(struct crypto_tfm *tfm, const u8 *key, 336 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
@@ -323,6 +370,7 @@ struct compress_tfm {
323}; 370};
324 371
325#define crt_ablkcipher crt_u.ablkcipher 372#define crt_ablkcipher crt_u.ablkcipher
373#define crt_aead crt_u.aead
326#define crt_blkcipher crt_u.blkcipher 374#define crt_blkcipher crt_u.blkcipher
327#define crt_cipher crt_u.cipher 375#define crt_cipher crt_u.cipher
328#define crt_hash crt_u.hash 376#define crt_hash crt_u.hash
@@ -334,6 +382,7 @@ struct crypto_tfm {
334 382
335 union { 383 union {
336 struct ablkcipher_tfm ablkcipher; 384 struct ablkcipher_tfm ablkcipher;
385 struct aead_tfm aead;
337 struct blkcipher_tfm blkcipher; 386 struct blkcipher_tfm blkcipher;
338 struct cipher_tfm cipher; 387 struct cipher_tfm cipher;
339 struct hash_tfm hash; 388 struct hash_tfm hash;
@@ -349,6 +398,10 @@ struct crypto_ablkcipher {
349 struct crypto_tfm base; 398 struct crypto_tfm base;
350}; 399};
351 400
401struct crypto_aead {
402 struct crypto_tfm base;
403};
404
352struct crypto_blkcipher { 405struct crypto_blkcipher {
353 struct crypto_tfm base; 406 struct crypto_tfm base;
354}; 407};
@@ -369,11 +422,15 @@ enum {
369 CRYPTOA_UNSPEC, 422 CRYPTOA_UNSPEC,
370 CRYPTOA_ALG, 423 CRYPTOA_ALG,
371 CRYPTOA_TYPE, 424 CRYPTOA_TYPE,
425 CRYPTOA_U32,
372 __CRYPTOA_MAX, 426 __CRYPTOA_MAX,
373}; 427};
374 428
375#define CRYPTOA_MAX (__CRYPTOA_MAX - 1) 429#define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
376 430
431/* Maximum number of (rtattr) parameters for each template. */
432#define CRYPTO_MAX_ATTRS 32
433
377struct crypto_attr_alg { 434struct crypto_attr_alg {
378 char name[CRYPTO_MAX_ALG_NAME]; 435 char name[CRYPTO_MAX_ALG_NAME];
379}; 436};
@@ -383,6 +440,10 @@ struct crypto_attr_type {
383 u32 mask; 440 u32 mask;
384}; 441};
385 442
443struct crypto_attr_u32 {
444 u32 num;
445};
446
386/* 447/*
387 * Transform user interface. 448 * Transform user interface.
388 */ 449 */
@@ -563,7 +624,8 @@ static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
563 return crt->decrypt(req); 624 return crt->decrypt(req);
564} 625}
565 626
566static inline int crypto_ablkcipher_reqsize(struct crypto_ablkcipher *tfm) 627static inline unsigned int crypto_ablkcipher_reqsize(
628 struct crypto_ablkcipher *tfm)
567{ 629{
568 return crypto_ablkcipher_crt(tfm)->reqsize; 630 return crypto_ablkcipher_crt(tfm)->reqsize;
569} 631}
@@ -619,6 +681,150 @@ static inline void ablkcipher_request_set_crypt(
619 req->info = iv; 681 req->info = iv;
620} 682}
621 683
684static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm)
685{
686 return (struct crypto_aead *)tfm;
687}
688
689static inline struct crypto_aead *crypto_alloc_aead(const char *alg_name,
690 u32 type, u32 mask)
691{
692 type &= ~CRYPTO_ALG_TYPE_MASK;
693 type |= CRYPTO_ALG_TYPE_AEAD;
694 mask |= CRYPTO_ALG_TYPE_MASK;
695
696 return __crypto_aead_cast(crypto_alloc_base(alg_name, type, mask));
697}
698
699static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)
700{
701 return &tfm->base;
702}
703
704static inline void crypto_free_aead(struct crypto_aead *tfm)
705{
706 crypto_free_tfm(crypto_aead_tfm(tfm));
707}
708
709static inline struct aead_tfm *crypto_aead_crt(struct crypto_aead *tfm)
710{
711 return &crypto_aead_tfm(tfm)->crt_aead;
712}
713
714static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm)
715{
716 return crypto_aead_crt(tfm)->ivsize;
717}
718
719static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm)
720{
721 return crypto_aead_crt(tfm)->authsize;
722}
723
724static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm)
725{
726 return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm));
727}
728
729static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm)
730{
731 return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm));
732}
733
734static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm)
735{
736 return crypto_tfm_get_flags(crypto_aead_tfm(tfm));
737}
738
739static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags)
740{
741 crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags);
742}
743
744static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
745{
746 crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags);
747}
748
749static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key,
750 unsigned int keylen)
751{
752 return crypto_aead_crt(tfm)->setkey(tfm, key, keylen);
753}
754
755static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
756{
757 return __crypto_aead_cast(req->base.tfm);
758}
759
760static inline int crypto_aead_encrypt(struct aead_request *req)
761{
762 return crypto_aead_crt(crypto_aead_reqtfm(req))->encrypt(req);
763}
764
765static inline int crypto_aead_decrypt(struct aead_request *req)
766{
767 return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req);
768}
769
770static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
771{
772 return crypto_aead_crt(tfm)->reqsize;
773}
774
775static inline void aead_request_set_tfm(struct aead_request *req,
776 struct crypto_aead *tfm)
777{
778 req->base.tfm = crypto_aead_tfm(tfm);
779}
780
781static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
782 gfp_t gfp)
783{
784 struct aead_request *req;
785
786 req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
787
788 if (likely(req))
789 aead_request_set_tfm(req, tfm);
790
791 return req;
792}
793
794static inline void aead_request_free(struct aead_request *req)
795{
796 kfree(req);
797}
798
799static inline void aead_request_set_callback(struct aead_request *req,
800 u32 flags,
801 crypto_completion_t complete,
802 void *data)
803{
804 req->base.complete = complete;
805 req->base.data = data;
806 req->base.flags = flags;
807}
808
809static inline void aead_request_set_crypt(struct aead_request *req,
810 struct scatterlist *src,
811 struct scatterlist *dst,
812 unsigned int cryptlen, u8 *iv)
813{
814 req->src = src;
815 req->dst = dst;
816 req->cryptlen = cryptlen;
817 req->iv = iv;
818}
819
820static inline void aead_request_set_assoc(struct aead_request *req,
821 struct scatterlist *assoc,
822 unsigned int assoclen)
823{
824 req->assoc = assoc;
825 req->assoclen = assoclen;
826}
827
622static inline struct crypto_blkcipher *__crypto_blkcipher_cast( 828static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
623 struct crypto_tfm *tfm) 829 struct crypto_tfm *tfm)
624{ 830{