1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2019-2021 NXP
4  *
5  * CAAM hash/HMAC local header.
6  */
7 #ifndef __LOCAL_H__
8 #define __LOCAL_H__
9 
10 #include <caam_common.h>
11 
12 /*
13  * Full hashing/HMAC data SW context
14  */
15 struct hashctx {
16 	uint32_t *descriptor;	   /* Job descriptor */
17 	struct caamblock blockbuf; /* Temporary block buffer */
18 	struct caambuf ctx;	   /* Hash context used by the CAAM */
19 	const struct hashalg *alg; /* Reference to the algo constants */
20 	struct caambuf key;	   /* HMAC split key */
21 	bool initialized;	   /* Context initialization flag */
22 };
23 
24 /*
25  * Hash/HMAC algorithm definition
26  */
27 struct hashalg {
28 	uint32_t type;	     /* Algo type for operation */
29 	uint8_t size_digest; /* Digest size */
30 	uint8_t size_block;  /* Computing block size */
31 	uint8_t size_ctx;    /* CAAM context register size (8 + digest size) */
32 	uint8_t size_key;    /* HMAC split key size */
33 };
34 
35 /* First part CAAM HW context - message length */
36 #define HASH_MSG_LEN 8
37 
38 /*
39  * Initialization of the hash/HMAC operation
40  *
41  * @ctx   Operation software context
42  */
43 TEE_Result caam_hash_hmac_init(struct hashctx *ctx);
44 
45 /*
46  * Update the hash/HMAC operation
47  *
48  * @ctx   Operation software context
49  * @data  Data to hash
50  * @len   Data length
51  */
52 TEE_Result caam_hash_hmac_update(struct hashctx *ctx, const uint8_t *data,
53 				 size_t len);
54 
55 /*
56  * Finalize the hash/HMAC operation
57  *
58  * @ctx     Operation software context
59  * @digest  [out] Hash digest buffer
60  * @len     Digest buffer length
61  */
62 TEE_Result caam_hash_hmac_final(struct hashctx *ctx, uint8_t *digest,
63 				size_t len);
64 
65 /*
66  * Copy sofware hashing context
67  *
68  * @dst  [out] Reference the destination context
69  * @src  Reference the source context
70  */
71 void caam_hash_hmac_copy_state(struct hashctx *dst, struct hashctx *src);
72 
73 /*
74  * Free the software context
75  *
76  * @ctx    [in/out] Caller context variable
77  */
78 void caam_hash_hmac_free(struct hashctx *ctx);
79 
80 /*
81  * Get hash/HMAC algorithm definition
82  *
83  * @algo   Hash algorithm
84  */
85 const struct hashalg *caam_hash_get_alg(uint32_t algo);
86 
87 /*
88  * Allocate the internal hashing data context
89  *
90  * @ctx    [in/out] Caller context variable
91  */
92 TEE_Result caam_hash_hmac_allocate(struct hashctx *ctx);
93 
94 #endif /* __LOCAL_H__ */
95