Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
4 */
5
6#ifndef _SHA_H_
7#define _SHA_H_
8
9#include <crypto/scatterwalk.h>
10#include <crypto/sha1.h>
11#include <crypto/sha2.h>
12
13#include "common.h"
14#include "core.h"
15
16#define QCE_SHA_MAX_BLOCKSIZE SHA256_BLOCK_SIZE
17#define QCE_SHA_MAX_DIGESTSIZE SHA256_DIGEST_SIZE
18
19struct qce_sha_ctx {
20 u8 authkey[QCE_SHA_MAX_BLOCKSIZE];
21};
22
23/**
24 * struct qce_sha_reqctx - holds private ahash objects per request
25 * @buf: used during update, import and export
26 * @tmpbuf: buffer for internal use
27 * @digest: calculated digest buffer
28 * @buflen: length of the buffer
29 * @flags: operation flags
30 * @src_orig: original request sg list
31 * @nbytes_orig: original request number of bytes
32 * @src_nents: source number of entries
33 * @byte_count: byte count
34 * @count: save count in states during update, import and export
35 * @first_blk: is it the first block
36 * @last_blk: is it the last block
37 * @sg: used to chain sg lists
38 * @authkey: pointer to auth key in sha ctx
39 * @authklen: auth key length
40 * @result_sg: scatterlist used for result buffer
41 */
42struct qce_sha_reqctx {
43 u8 buf[QCE_SHA_MAX_BLOCKSIZE];
44 u8 tmpbuf[QCE_SHA_MAX_BLOCKSIZE];
45 u8 digest[QCE_SHA_MAX_DIGESTSIZE];
46 unsigned int buflen;
47 unsigned long flags;
48 struct scatterlist *src_orig;
49 unsigned int nbytes_orig;
50 int src_nents;
51 __be32 byte_count[2];
52 u64 count;
53 bool first_blk;
54 bool last_blk;
55 struct scatterlist sg[2];
56 u8 *authkey;
57 unsigned int authklen;
58 struct scatterlist result_sg;
59};
60
61static inline struct qce_alg_template *to_ahash_tmpl(struct crypto_tfm *tfm)
62{
63 struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
64 struct ahash_alg *alg = container_of(crypto_hash_alg_common(ahash),
65 struct ahash_alg, halg);
66
67 return container_of(alg, struct qce_alg_template, alg.ahash);
68}
69
70extern const struct qce_algo_ops ahash_ops;
71
72#endif /* _SHA_H_ */
1/*
2 * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef _SHA_H_
15#define _SHA_H_
16
17#include <crypto/scatterwalk.h>
18#include <crypto/sha.h>
19
20#include "common.h"
21#include "core.h"
22
23#define QCE_SHA_MAX_BLOCKSIZE SHA256_BLOCK_SIZE
24#define QCE_SHA_MAX_DIGESTSIZE SHA256_DIGEST_SIZE
25
26struct qce_sha_ctx {
27 u8 authkey[QCE_SHA_MAX_BLOCKSIZE];
28};
29
30/**
31 * struct qce_sha_reqctx - holds private ahash objects per request
32 * @buf: used during update, import and export
33 * @tmpbuf: buffer for internal use
34 * @digest: calculated digest buffer
35 * @buflen: length of the buffer
36 * @flags: operation flags
37 * @src_orig: original request sg list
38 * @nbytes_orig: original request number of bytes
39 * @src_nents: source number of entries
40 * @byte_count: byte count
41 * @count: save count in states during update, import and export
42 * @first_blk: is it the first block
43 * @last_blk: is it the last block
44 * @sg: used to chain sg lists
45 * @authkey: pointer to auth key in sha ctx
46 * @authklen: auth key length
47 * @result_sg: scatterlist used for result buffer
48 */
49struct qce_sha_reqctx {
50 u8 buf[QCE_SHA_MAX_BLOCKSIZE];
51 u8 tmpbuf[QCE_SHA_MAX_BLOCKSIZE];
52 u8 digest[QCE_SHA_MAX_DIGESTSIZE];
53 unsigned int buflen;
54 unsigned long flags;
55 struct scatterlist *src_orig;
56 unsigned int nbytes_orig;
57 int src_nents;
58 __be32 byte_count[2];
59 u64 count;
60 bool first_blk;
61 bool last_blk;
62 struct scatterlist sg[2];
63 u8 *authkey;
64 unsigned int authklen;
65 struct scatterlist result_sg;
66};
67
68static inline struct qce_alg_template *to_ahash_tmpl(struct crypto_tfm *tfm)
69{
70 struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
71 struct ahash_alg *alg = container_of(crypto_hash_alg_common(ahash),
72 struct ahash_alg, halg);
73
74 return container_of(alg, struct qce_alg_template, alg.ahash);
75}
76
77extern const struct qce_algo_ops ahash_ops;
78
79#endif /* _SHA_H_ */