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>
21 int (*init)(struct shash_desc *desc);
22 int (*update)(struct shash_desc *desc, const u8 *data, unsigned len);
23 int (*final)(struct shash_desc *desc, u8 *out);
24 int (*finup)(struct shash_desc *desc, const u8 *data,
25 unsigned len, u8 *out);
26 int (*digest)(struct shash_desc *desc, const u8 *data,
27 unsigned len, u8 *out);
31 struct crypto_alg base;
34 int crypto_register_shash(struct shash_alg *alg);
38 struct crypto_tfm base;
41 struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
44 static inline void crypto_free_shash(struct crypto_shash *tfm)
49 static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm)
51 return container_of(tfm->base.alg, struct shash_alg, base);
54 static inline unsigned crypto_shash_digestsize(struct crypto_shash *tfm)
56 return crypto_shash_alg(tfm)->digestsize;
59 static inline unsigned crypto_shash_descsize(struct crypto_shash *tfm)
65 struct crypto_shash *tfm;
68 void *ctx[] CRYPTO_MINALIGN_ATTR;
71 #define SHASH_DESC_ON_STACK(shash, tfm) \
72 char __##shash##_desc[sizeof(struct shash_desc) + \
73 crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR; \
74 struct shash_desc *shash = (struct shash_desc *)__##shash##_desc
76 static inline int crypto_shash_init(struct shash_desc *desc)
78 return crypto_shash_alg(desc->tfm)->init(desc);
81 static inline int crypto_shash_update(struct shash_desc *desc,
82 const u8 *data, unsigned len)
84 return crypto_shash_alg(desc->tfm)->update(desc, data, len);
87 static inline int crypto_shash_final(struct shash_desc *desc, u8 *out)
89 return crypto_shash_alg(desc->tfm)->final(desc, out);
92 static inline int crypto_shash_finup(struct shash_desc *desc, const u8 *data,
93 unsigned len, u8 *out)
95 return crypto_shash_alg(desc->tfm)->finup(desc, data, len, out);
98 static inline int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
99 unsigned len, u8 *out)
101 return crypto_shash_alg(desc->tfm)->digest(desc, data, len, out);
104 #endif /* _CRYPTO_HASH_H */