FreeBSD/Linux Kernel Cross Reference
sys/crypto/digest.c
1 /*
2 * Cryptographic API.
3 *
4 * Digest operations.
5 *
6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
7 *
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)
11 * any later version.
12 *
13 */
14 #include <linux/crypto.h>
15 #include <linux/mm.h>
16 #include <linux/errno.h>
17 #include <linux/highmem.h>
18 #include <asm/scatterlist.h>
19 #include "internal.h"
20
21 static void init(struct crypto_tfm *tfm)
22 {
23 tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm));
24 }
25
26 static void update(struct crypto_tfm *tfm,
27 struct scatterlist *sg, unsigned int nsg)
28 {
29 unsigned int i;
30
31 for (i = 0; i < nsg; i++) {
32 char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
33 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
34 p, sg[i].length);
35 crypto_kunmap(p, 0);
36 crypto_yield(tfm);
37 }
38 }
39
40 static void final(struct crypto_tfm *tfm, u8 *out)
41 {
42 tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out);
43 }
44
45 static void digest(struct crypto_tfm *tfm,
46 struct scatterlist *sg, unsigned int nsg, u8 *out)
47 {
48 unsigned int i;
49
50 tfm->crt_digest.dit_init(tfm);
51
52 for (i = 0; i < nsg; i++) {
53 char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
54 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
55 p, sg[i].length);
56 crypto_kunmap(p, 0);
57 crypto_yield(tfm);
58 }
59 crypto_digest_final(tfm, out);
60 }
61
62 int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)
63 {
64 return flags ? -EINVAL : 0;
65 }
66
67 int crypto_init_digest_ops(struct crypto_tfm *tfm)
68 {
69 struct digest_tfm *ops = &tfm->crt_digest;
70
71 ops->dit_init = init;
72 ops->dit_update = update;
73 ops->dit_final = final;
74 ops->dit_digest = digest;
75
76 return crypto_alloc_hmac_block(tfm);
77 }
78
79 void crypto_exit_digest_ops(struct crypto_tfm *tfm)
80 {
81 crypto_free_hmac_block(tfm);
82 }
Cache object: 185680e8a4189c1cb443f1c2abe90e53
|