55# include <click/cxxprotect.h>
57# include <linux/err.h>
58# include <linux/crypto.h>
59# if HAVE_LINUX_ASM_SCATTERLIST_H
60# include <asm/scatterlist.h>
62# include <linux/scatterlist.h>
64# include <click/cxxunprotect.h>
66#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
67typedef struct hash_desc md5_state_t;
69typedef struct crypto_tfm *md5_state_t;
72static inline int md5_init(md5_state_t *pms) {
73#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
74 pms->tfm = crypto_alloc_hash(
"md5", 0, CRYPTO_ALG_ASYNC);
76 return PTR_ERR(pms->tfm);
78 crypto_hash_init(pms);
81 *pms = crypto_alloc_tfm(
"md5", 0);
84 crypto_digest_init(*pms);
89static inline void md5_reinit(md5_state_t *pms) {
90#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
91 crypto_hash_init(pms);
93 crypto_digest_init(*pms);
97static inline void md5_append(md5_state_t *pms,
const unsigned char *data,
int nbytes) {
98 struct scatterlist sg;
99 if (likely(virt_addr_valid((
unsigned long)data))) {
100 sg_init_one(&sg,
const_cast<uint8_t *
>(data), nbytes);
101#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
102 crypto_hash_update(pms, &sg, nbytes);
104 crypto_digest_update(*pms, &sg, 1);
109 int off = offset_in_page(data);
110 if (off + len > (
int)PAGE_SIZE)
111 len = PAGE_SIZE - off;
112 sg_init_table(&sg, 1);
113 sg_set_page(&sg, vmalloc_to_page(
const_cast<uint8_t *
>(data)), len, off);
114#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
115 crypto_hash_update(pms, &sg, len);
117 crypto_digest_update(*pms, &sg, 1);
125static inline void md5_finish(md5_state_t *pms,
unsigned char digest[16]) {
126#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
127 crypto_hash_final(pms, digest);
129 crypto_digest_final(*pms, digest);
133static inline void md5_free(md5_state_t *pms) {
134#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
135 crypto_free_hash(pms->tfm);
137 crypto_free_tfm(*pms);
153typedef unsigned char md5_byte_t;
154typedef uint32_t md5_word_t;
157typedef struct md5_state_s {
169int md5_init(md5_state_t *pms);
172static inline void md5_reinit(md5_state_t *pms) {
177void md5_append(md5_state_t *pms,
const md5_byte_t *data,
int nbytes);
180#define MD5_DIGEST_SIZE 16
181void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
191#define MD5_TEXT_DIGEST_SIZE 22
192#define MD5_TEXT_DIGEST_MAX_SIZE 26
193int md5_finish_text(md5_state_t *pms,
char *text_digest,
int allow_at);