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_X25519, /* Asymmetric X25519 driver */ 59 CRYPTO_X448, /* Asymmetric X448 driver */ 60 CRYPTO_DH, /* Asymmetric DH driver */ 61 CRYPTO_DSA, /* Asymmetric DSA driver */ 62 CRYPTO_AUTHENC, /* Authenticated Encryption driver */ 63 CRYPTO_MAX_ALGO /* Maximum number of algo supported */ 64 }; 65 66 /* 67 * Register the Cryptographic's operation in the table of modules 68 * 69 * @algo_id ID of the Cryptographic module 70 * @ops Operation (function/structure) to register 71 */ 72 TEE_Result drvcrypt_register(enum drvcrypt_algo_id algo_id, void *ops); 73 74 /* 75 * Modify the Cryptographic algorithm in the table of modules 76 * 77 * @algo_id ID of the Cryptographic module 78 * @ops Operation (function/structure) to register 79 */ 80 void drvcrypt_register_change(enum drvcrypt_algo_id algo_id, void *ops); 81 82 /* 83 * Return the Cryptographic's operation (function/structure) registered in 84 * the table of modules. 85 * 86 * @algo_id ID of the Cryptographic module 87 */ 88 void *drvcrypt_get_ops(enum drvcrypt_algo_id algo_id); 89 90 #endif /* __DRVCRYPT_H__ */ 91