Avoid beyond bounds copy while caching ACL
[zen-stable.git] / drivers / staging / rtl8192u / ieee80211 / digest.c
blob301ed514ac9e132cdd2c0eae0b011988cfc3643d
1 /*
2 * Cryptographic API.
4 * Digest operations.
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)
11 * any later version.
14 //#include <linux/crypto.h>
15 #include "rtl_crypto.h"
16 #include <linux/mm.h>
17 #include <linux/errno.h>
18 #include <linux/highmem.h>
19 #include <asm/scatterlist.h>
20 #include "internal.h"
22 static void init(struct crypto_tfm *tfm)
24 tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm));
27 static void update(struct crypto_tfm *tfm,
28 struct scatterlist *sg, unsigned int nsg)
30 unsigned int i;
32 for (i = 0; i < nsg; i++) {
34 struct page *pg = sg[i].page;
35 unsigned int offset = sg[i].offset;
36 unsigned int l = sg[i].length;
38 do {
39 unsigned int bytes_from_page = min(l, ((unsigned int)
40 (PAGE_SIZE)) -
41 offset);
42 char *p = crypto_kmap(pg, 0) + offset;
44 tfm->__crt_alg->cra_digest.dia_update
45 (crypto_tfm_ctx(tfm), p,
46 bytes_from_page);
47 crypto_kunmap(p, 0);
48 crypto_yield(tfm);
49 offset = 0;
50 pg++;
51 l -= bytes_from_page;
52 } while (l > 0);
56 static void final(struct crypto_tfm *tfm, u8 *out)
58 tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out);
61 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
63 u32 flags;
64 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
65 return -ENOSYS;
66 return tfm->__crt_alg->cra_digest.dia_setkey(crypto_tfm_ctx(tfm),
67 key, keylen, &flags);
70 static void digest(struct crypto_tfm *tfm,
71 struct scatterlist *sg, unsigned int nsg, u8 *out)
73 unsigned int i;
75 tfm->crt_digest.dit_init(tfm);
77 for (i = 0; i < nsg; i++) {
78 char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
79 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
80 p, sg[i].length);
81 crypto_kunmap(p, 0);
82 crypto_yield(tfm);
84 crypto_digest_final(tfm, out);
87 int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)
89 return flags ? -EINVAL : 0;
92 int crypto_init_digest_ops(struct crypto_tfm *tfm)
94 struct digest_tfm *ops = &tfm->crt_digest;
96 ops->dit_init = init;
97 ops->dit_update = update;
98 ops->dit_final = final;
99 ops->dit_digest = digest;
100 ops->dit_setkey = setkey;
102 return crypto_alloc_hmac_block(tfm);
105 void crypto_exit_digest_ops(struct crypto_tfm *tfm)
107 crypto_free_hmac_block(tfm);