Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / include / crypto / aead.h
blob0edf949f6369558eb196abf94bd131229c5b6ecd
1 /*
2 * AEAD: Authenticated Encryption with Associated Data
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
13 #ifndef _CRYPTO_AEAD_H
14 #define _CRYPTO_AEAD_H
16 #include <linux/crypto.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
20 /**
21 * struct aead_givcrypt_request - AEAD request with IV generation
22 * @seq: Sequence number for IV generation
23 * @giv: Space for generated IV
24 * @areq: The AEAD request itself
26 struct aead_givcrypt_request {
27 u64 seq;
28 u8 *giv;
30 struct aead_request areq;
33 static inline struct crypto_aead *aead_givcrypt_reqtfm(
34 struct aead_givcrypt_request *req)
36 return crypto_aead_reqtfm(&req->areq);
39 static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req)
41 struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
42 return crt->givencrypt(req);
45 static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req)
47 struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
48 return crt->givdecrypt(req);
51 static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req,
52 struct crypto_aead *tfm)
54 req->areq.base.tfm = crypto_aead_tfm(tfm);
57 static inline struct aead_givcrypt_request *aead_givcrypt_alloc(
58 struct crypto_aead *tfm, gfp_t gfp)
60 struct aead_givcrypt_request *req;
62 req = kmalloc(sizeof(struct aead_givcrypt_request) +
63 crypto_aead_reqsize(tfm), gfp);
65 if (likely(req))
66 aead_givcrypt_set_tfm(req, tfm);
68 return req;
71 static inline void aead_givcrypt_free(struct aead_givcrypt_request *req)
73 kfree(req);
76 static inline void aead_givcrypt_set_callback(
77 struct aead_givcrypt_request *req, u32 flags,
78 crypto_completion_t complete, void *data)
80 aead_request_set_callback(&req->areq, flags, complete, data);
83 static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req,
84 struct scatterlist *src,
85 struct scatterlist *dst,
86 unsigned int nbytes, void *iv)
88 aead_request_set_crypt(&req->areq, src, dst, nbytes, iv);
91 static inline void aead_givcrypt_set_assoc(struct aead_givcrypt_request *req,
92 struct scatterlist *assoc,
93 unsigned int assoclen)
95 aead_request_set_assoc(&req->areq, assoc, assoclen);
98 static inline void aead_givcrypt_set_giv(struct aead_givcrypt_request *req,
99 u8 *giv, u64 seq)
101 req->giv = giv;
102 req->seq = seq;
105 #endif /* _CRYPTO_AEAD_H */