ath9k: implement IO serialization
[linux/fpc-iii.git] / include / crypto / hash.h
blobee48ef8fb2eafff29c8aefe67024709d7696e69d
1 /*
2 * Hash: Hash algorithms under the crypto API
3 *
4 * Copyright (c) 2008 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_HASH_H
14 #define _CRYPTO_HASH_H
16 #include <linux/crypto.h>
18 struct crypto_ahash {
19 struct crypto_tfm base;
22 static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)
24 return (struct crypto_ahash *)tfm;
27 static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name,
28 u32 type, u32 mask)
30 type &= ~CRYPTO_ALG_TYPE_MASK;
31 mask &= ~CRYPTO_ALG_TYPE_MASK;
32 type |= CRYPTO_ALG_TYPE_AHASH;
33 mask |= CRYPTO_ALG_TYPE_AHASH_MASK;
35 return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask));
38 static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)
40 return &tfm->base;
43 static inline void crypto_free_ahash(struct crypto_ahash *tfm)
45 crypto_free_tfm(crypto_ahash_tfm(tfm));
48 static inline unsigned int crypto_ahash_alignmask(
49 struct crypto_ahash *tfm)
51 return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm));
54 static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm)
56 return &crypto_ahash_tfm(tfm)->crt_ahash;
59 static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm)
61 return crypto_ahash_crt(tfm)->digestsize;
64 static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm)
66 return crypto_tfm_get_flags(crypto_ahash_tfm(tfm));
69 static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags)
71 crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags);
74 static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags)
76 crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags);
79 static inline struct crypto_ahash *crypto_ahash_reqtfm(
80 struct ahash_request *req)
82 return __crypto_ahash_cast(req->base.tfm);
85 static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm)
87 return crypto_ahash_crt(tfm)->reqsize;
90 static inline int crypto_ahash_setkey(struct crypto_ahash *tfm,
91 const u8 *key, unsigned int keylen)
93 struct ahash_tfm *crt = crypto_ahash_crt(tfm);
95 return crt->setkey(tfm, key, keylen);
98 static inline int crypto_ahash_digest(struct ahash_request *req)
100 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req));
101 return crt->digest(req);
104 static inline int crypto_ahash_init(struct ahash_request *req)
106 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req));
107 return crt->init(req);
110 static inline int crypto_ahash_update(struct ahash_request *req)
112 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req));
113 return crt->update(req);
116 static inline int crypto_ahash_final(struct ahash_request *req)
118 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req));
119 return crt->final(req);
122 static inline void ahash_request_set_tfm(struct ahash_request *req,
123 struct crypto_ahash *tfm)
125 req->base.tfm = crypto_ahash_tfm(tfm);
128 static inline struct ahash_request *ahash_request_alloc(
129 struct crypto_ahash *tfm, gfp_t gfp)
131 struct ahash_request *req;
133 req = kmalloc(sizeof(struct ahash_request) +
134 crypto_ahash_reqsize(tfm), gfp);
136 if (likely(req))
137 ahash_request_set_tfm(req, tfm);
139 return req;
142 static inline void ahash_request_free(struct ahash_request *req)
144 kfree(req);
147 static inline struct ahash_request *ahash_request_cast(
148 struct crypto_async_request *req)
150 return container_of(req, struct ahash_request, base);
153 static inline void ahash_request_set_callback(struct ahash_request *req,
154 u32 flags,
155 crypto_completion_t complete,
156 void *data)
158 req->base.complete = complete;
159 req->base.data = data;
160 req->base.flags = flags;
163 static inline void ahash_request_set_crypt(struct ahash_request *req,
164 struct scatterlist *src, u8 *result,
165 unsigned int nbytes)
167 req->src = src;
168 req->nbytes = nbytes;
169 req->result = result;
172 #endif /* _CRYPTO_HASH_H */