xref: /optee_os/core/drivers/crypto/caam/hash/local.h (revision a1d5c81f8834a9d2c6f4372cce2e59e70e709121)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2019-2020 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 };
22 
23 /*
24  * Hash/HMAC algorithm definition
25  */
26 struct hashalg {
27 	uint32_t type;	     /* Algo type for operation */
28 	uint8_t size_digest; /* Digest size */
29 	uint8_t size_block;  /* Computing block size */
30 	uint8_t size_ctx;    /* CAAM context register size (8 + digest size) */
31 	uint8_t size_key;    /* HMAC split key size */
32 };
33 
34 /* First part CAAM HW context - message length */
35 #define HASH_MSG_LEN 8
36 
37 /*
38  * Initialization of the hash/HMAC operation
39  *
40  * @ctx   Operation software context
41  */
42 TEE_Result caam_hash_hmac_init(struct hashctx *ctx);
43 
44 /*
45  * Update the hash/HMAC operation
46  *
47  * @ctx   Operation software context
48  * @data  Data to hash
49  * @len   Data length
50  */
51 TEE_Result caam_hash_hmac_update(struct hashctx *ctx, const uint8_t *data,
52 				 size_t len);
53 
54 /*
55  * Finalize the hash/HMAC operation
56  *
57  * @ctx     Operation software context
58  * @digest  [out] Hash digest buffer
59  * @len     Digest buffer length
60  */
61 TEE_Result caam_hash_hmac_final(struct hashctx *ctx, uint8_t *digest,
62 				size_t len);
63 
64 /*
65  * Copy sofware hashing context
66  *
67  * @dst  [out] Reference the destination context
68  * @src  Reference the source context
69  */
70 void caam_hash_hmac_copy_state(struct hashctx *dst, struct hashctx *src);
71 
72 /*
73  * Free the software context
74  *
75  * @ctx    [in/out] Caller context variable
76  */
77 void caam_hash_hmac_free(struct hashctx *ctx);
78 
79 /*
80  * Get hash/HMAC algorithm definition
81  *
82  * @algo   Hash algorithm
83  */
84 const struct hashalg *caam_hash_get_alg(uint32_t algo);
85 
86 /*
87  * Allocate the internal hashing data context
88  *
89  * @ctx    [in/out] Caller context variable
90  */
91 TEE_Result caam_hash_hmac_allocate(struct hashctx *ctx);
92 
93 #endif /* __LOCAL_H__ */
94