6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
14 #include <linux/crypto.h>
16 #include <linux/errno.h>
17 #include <linux/highmem.h>
18 #include <asm/scatterlist.h>
21 static void init(struct crypto_tfm *tfm)
23 tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm));
26 static void update(struct crypto_tfm *tfm,
27 struct scatterlist *sg, unsigned int nsg)
31 for (i = 0; i < nsg; i++) {
33 struct page *pg = sg[i].page;
34 unsigned int offset = sg[i].offset;
35 unsigned int l = sg[i].length;
38 unsigned int bytes_from_page = min(l, ((unsigned int)
41 char *p = crypto_kmap(pg, 0) + offset;
43 tfm->__crt_alg->cra_digest.dia_update
44 (crypto_tfm_ctx(tfm), p,
55 static void update_kernel(struct crypto_tfm *tfm,
56 const void *data, size_t count)
58 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm), data, count);
62 static void final(struct crypto_tfm *tfm, u8 *out)
64 tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out);
67 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
70 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
72 return tfm->__crt_alg->cra_digest.dia_setkey(crypto_tfm_ctx(tfm),
76 static void digest(struct crypto_tfm *tfm,
77 struct scatterlist *sg, unsigned int nsg, u8 *out)
81 tfm->crt_digest.dit_init(tfm);
83 for (i = 0; i < nsg; i++) {
84 char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
85 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
90 crypto_digest_final(tfm, out);
93 int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)
95 return flags ? -EINVAL : 0;
98 int crypto_init_digest_ops(struct crypto_tfm *tfm)
100 struct digest_tfm *ops = &tfm->crt_digest;
102 ops->dit_init = init;
103 ops->dit_update = update;
104 ops->dit_update_kernel = update_kernel;
105 ops->dit_final = final;
106 ops->dit_digest = digest;
107 ops->dit_setkey = setkey;
109 return crypto_alloc_hmac_block(tfm);
112 void crypto_exit_digest_ops(struct crypto_tfm *tfm)
114 crypto_free_hmac_block(tfm);