1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2021 NXP
4  *
5  * Brief   Crypto Driver exported constants and interfaces.
6  */
7 #ifndef __DRVCRYPT_H__
8 #define __DRVCRYPT_H__
9 
10 #include <tee_api_types.h>
11 #include <trace.h>
12 #include <util.h>
13 
14 /*
15  * Debug Macros function of Crypto Driver Debug Level setting
16  * The CFG_CRYPTO_DRV_DBG is a bit mask 32 bits value defined
17  * as followed:
18  */
19 #define DRV_DBG_TRACE BIT32(0) /* Driver trace */
20 #define DRV_DBG_BUF   BIT32(1) /* Driver dump Buffer */
21 
22 #if (CFG_CRYPTO_DRIVER_DEBUG & DRV_DBG_TRACE)
23 #define CRYPTO_TRACE DMSG
24 #else
25 #define CRYPTO_TRACE(...)
26 #endif
27 #if (CFG_CRYPTO_DRIVER_DEBUG & DRV_DBG_BUF)
28 #define CRYPTO_DUMPBUF(title, buf, len)                                        \
29 	do {                                                                   \
30 		__typeof__(buf) _buf = (buf);                                  \
31 		__typeof__(len) _len = (len);                                  \
32 		CRYPTO_TRACE("%s @%p: %zu", title, _buf, _len);                \
33 		dhex_dump(NULL, 0, 0, _buf, _len);                             \
34 	} while (0)
35 #else
36 #define CRYPTO_DUMPBUF(...)
37 #endif
38 
39 /*
40  * Definition of a crypto buffer type
41  */
42 struct drvcrypt_buf {
43 	uint8_t *data;
44 	size_t length;
45 };
46 
47 /*
48  * Crypto Library Algorithm enumeration
49  */
50 enum drvcrypt_algo_id {
51 	CRYPTO_HASH = 0, /* Hash driver */
52 	CRYPTO_HMAC,	 /* HMAC driver */
53 	CRYPTO_CMAC,	 /* CMAC driver */
54 	CRYPTO_RSA,      /* Asymmetric RSA driver */
55 	CRYPTO_MATH,	 /* Mathematical driver */
56 	CRYPTO_CIPHER,   /* Cipher driver */
57 	CRYPTO_ECC,      /* Asymmetric ECC driver */
58 	CRYPTO_DH,       /* Asymmetric DH driver */
59 	CRYPTO_DSA,	 /* Asymmetric DSA driver */
60 	CRYPTO_AUTHENC,  /* Authenticated Encryption driver */
61 	CRYPTO_MAX_ALGO  /* Maximum number of algo supported */
62 };
63 
64 /*
65  * Register the Cryptographic's operation in the table of modules
66  *
67  * @algo_id  ID of the Cryptographic module
68  * @ops      Operation (function/structure) to register
69  */
70 TEE_Result drvcrypt_register(enum drvcrypt_algo_id algo_id, void *ops);
71 
72 /*
73  * Modify the Cryptographic algorithm in the table of modules
74  *
75  * @algo_id  ID of the Cryptographic module
76  * @ops      Operation (function/structure) to register
77  */
78 void drvcrypt_register_change(enum drvcrypt_algo_id algo_id, void *ops);
79 
80 /*
81  * Return the Cryptographic's operation (function/structure) registered in
82  * the table of modules.
83  *
84  * @algo_id  ID of the Cryptographic module
85  */
86 void *drvcrypt_get_ops(enum drvcrypt_algo_id algo_id);
87 
88 #endif /* __DRVCRYPT_H__ */
89