2 * Hash: Hash algorithms under the crypto API
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)
13 #ifndef _CRYPTO_HASH_H
14 #define _CRYPTO_HASH_H
16 #include <linux/crypto.h>
17 #include <linux/string.h>
20 struct crypto_shash *tfm;
23 void *__ctx[] CRYPTO_MINALIGN_ATTR;
26 #define SHASH_DESC_ON_STACK(shash, ctx) \
27 char __##shash##_desc[sizeof(struct shash_desc) + \
28 crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
29 struct shash_desc *shash = (struct shash_desc *)__##shash##_desc
32 int (*init)(struct shash_desc *desc);
33 int (*update)(struct shash_desc *desc, const u8 *data, unsigned len);
34 int (*final)(struct shash_desc *desc, u8 *out);
35 int (*finup)(struct shash_desc *desc, const u8 *data,
36 unsigned len, u8 *out);
37 int (*digest)(struct shash_desc *desc, const u8 *data,
38 unsigned len, u8 *out);
42 struct crypto_alg base;
47 struct crypto_tfm base;
50 struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
53 static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm)
58 static inline void crypto_free_shash(struct crypto_shash *tfm)
60 crypto_destroy_tfm(tfm, crypto_shash_tfm(tfm));
63 static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg)
65 return container_of(alg, struct shash_alg, base);
68 static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm)
70 return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg);
73 static inline unsigned crypto_shash_digestsize(struct crypto_shash *tfm)
75 return crypto_shash_alg(tfm)->digestsize;
78 static inline unsigned crypto_shash_descsize(struct crypto_shash *tfm)
83 static inline void *shash_desc_ctx(struct shash_desc *desc)
88 static inline int crypto_shash_init(struct shash_desc *desc)
90 return crypto_shash_alg(desc->tfm)->init(desc);
93 static inline int crypto_shash_update(struct shash_desc *desc,
94 const u8 *data, unsigned len)
96 return crypto_shash_alg(desc->tfm)->update(desc, data, len);
99 static inline int crypto_shash_final(struct shash_desc *desc, u8 *out)
101 return crypto_shash_alg(desc->tfm)->final(desc, out);
104 static inline int crypto_shash_finup(struct shash_desc *desc, const u8 *data,
105 unsigned len, u8 *out)
107 return crypto_shash_alg(desc->tfm)->finup(desc, data, len, out);
110 static inline int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
111 unsigned len, u8 *out)
113 return crypto_shash_alg(desc->tfm)->digest(desc, data, len, out);
116 #endif /* _CRYPTO_HASH_H */