1 /***************************************************************************//** 2 * \file cy_cryptolite_common.h 3 * \version 2.30 4 * 5 * \brief 6 * This file provides common constants and parameters 7 * for the Cryptolite driver. 8 * 9 ******************************************************************************** 10 * Copyright 2022 Cypress Semiconductor Corporation 11 * SPDX-License-Identifier: Apache-2.0 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an "AS IS" BASIS, 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 *******************************************************************************/ 25 26 #if !defined (CY_CRYPTOLITE_COMMON_H) 27 #define CY_CRYPTOLITE_COMMON_H 28 29 #include "cy_device.h" 30 31 #if defined (CY_IP_MXCRYPTOLITE) 32 33 #include "cy_syslib.h" 34 35 #if defined(__cplusplus) 36 extern "C" { 37 #endif 38 39 #include <stddef.h> 40 #include <stdbool.h> 41 #include <stdlib.h> 42 43 #include "cy_cryptolite_hw.h" 44 #include "cy_cryptolite_config.h" 45 46 /** 47 * \addtogroup group_cryptolite_macros 48 * \{ 49 */ 50 /** Driver major version */ 51 #define CY_CRYPTOLITE_DRV_VERSION_MAJOR 2 52 53 /** Driver minor version */ 54 #define CY_CRYPTOLITE_DRV_VERSION_MINOR 30 55 56 /** Cryptolite Driver PDL ID */ 57 #define CY_CRYPTOLITE_ID CY_PDL_DRV_ID(0x74u) 58 /** \} group_cryptolite_macros */ 59 60 /** \cond INTERNAL */ 61 62 63 /* Calculates the actual size in bytes of the bits value */ 64 #define CY_CRYPTOLITE_BYTE_SIZE_OF_BITS(x) (uint32_t)(((uint32_t)(x) + 7U) >> 3U) 65 66 /** \endcond */ 67 68 /** 69 * \addtogroup group_cryptolite_enums 70 * \{ 71 */ 72 73 /** Errors of the Cryptolite block */ 74 typedef enum 75 { 76 /** Operation completed successfully. */ 77 CY_CRYPTOLITE_SUCCESS = 0x00u, 78 /** The Crypto operation parameters are incorrect. */ 79 CY_CRYPTOLITE_BAD_PARAMS = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x01u, 80 /** The Crypto HW is busy. */ 81 CY_CRYPTOLITE_HW_BUSY = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x02u, 82 /** The Crypto AHB bus error. */ 83 CY_CRYPTOLITE_BUS_ERROR = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x03u, 84 /** The Crypto feature not supported error. */ 85 CY_CRYPTOLITE_NOT_SUPPORTED = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x04u, 86 /** The size of input data is not multiple of 16. */ 87 CY_CRYPTOLITE_SIZE_NOT_X16 = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x05u, 88 /** The Address passed is not aligned to 4 bytes. */ 89 CY_CRYPTOLITE_ALIGNMENT_ERROR = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x06u, 90 /** The TRNG is not enabled. */ 91 CY_CRYPTOLITE_TRNG_NOT_ENABLED = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x07u, 92 /** The TRNG is unhealthy. */ 93 CY_CRYPTOLITE_TRNG_UNHEALTHY = CY_CRYPTOLITE_ID | CY_PDL_STATUS_ERROR | 0x08u, 94 } cy_en_cryptolite_status_t; 95 96 /** \} group_cryptolite_enums */ 97 98 99 100 /** \cond INTERNAL */ 101 /** The cryptolite task descriptor structure. 102 * All fields for the structure are internal. Firmware never reads or 103 * writes these values. 104 */ 105 typedef struct cy_stc_cryptolite_descr_t { 106 uint32_t data0; 107 uint32_t data1; 108 uint32_t data2; 109 uint32_t data3; 110 } cy_stc_cryptolite_descr_t; 111 /** \endcond */ 112 113 114 /** 115 * \addtogroup group_cryptolite_enums 116 * \{ 117 */ 118 /** Defines modes of SHA method */ 119 typedef enum 120 { 121 CY_CRYPTOLITE_MODE_SHA1 = 0x00u, /**< Sets the SHA1 mode */ 122 CY_CRYPTOLITE_MODE_SHA224 = 0x01u, /**< Sets the SHA224 mode */ 123 CY_CRYPTOLITE_MODE_SHA256 = 0x02u, /**< Sets the SHA256 mode */ 124 CY_CRYPTOLITE_MODE_SHA384 = 0x03u, /**< Sets the SHA384 mode */ 125 CY_CRYPTOLITE_MODE_SHA512 = 0x04u, /**< Sets the SHA512 mode */ 126 CY_CRYPTOLITE_MODE_SHA512_256 = 0x05u, /**< Sets the SHA512/256 mode */ 127 CY_CRYPTOLITE_MODE_SHA512_224 = 0x06u, /**< Sets the SHA512/224 mode */ 128 CY_CRYPTOLITE_MODE_SHA_NONE = 0x07u, /**< Sets the SHA NONE mode */ 129 } cy_en_cryptolite_sha_mode_t; 130 131 132 /** Signature verification status */ 133 typedef enum 134 { 135 /** The signature is valid */ 136 CY_CRYPTOLITE_SIG_VALID = 0x05555555u, 137 /** The signature is invalid */ 138 CY_CRYPTOLITE_SIG_INVALID = 0x0AAAAAAAu, 139 } cy_en_cryptolite_sig_verify_result_t; 140 141 /** \} group_cryptolite_enums */ 142 143 144 #if defined(CY_CRYPTOLITE_CFG_ECP_DP_SECP521R1_ENABLED) 145 #define BIT_SIZE ((uint32_t)521) 146 #elif defined(CY_CRYPTOLITE_CFG_ECP_DP_SECP384R1_ENABLED) 147 #define BIT_SIZE ((uint32_t)384) 148 #elif defined(CY_CRYPTOLITE_CFG_ECP_DP_SECP256R1_ENABLED) 149 #define BIT_SIZE ((uint32_t)256) 150 #elif defined(CY_CRYPTOLITE_CFG_ECP_DP_SECP224R1_ENABLED) 151 #define BIT_SIZE ((uint32_t)224) 152 #elif defined(CY_CRYPTOLITE_CFG_ECP_DP_SECP192R1_ENABLED) 153 #define BIT_SIZE ((uint32_t)192) 154 #else 155 #define BIT_SIZE ((uint32_t)256) 156 #endif 157 158 typedef enum cy_en_cryptolite_ecc_red_mul_algs_t { 159 CY_CRYPTOLITE_NIST_P_CURVE_SPECIFIC_RED_ALG = 0, 160 CY_CRYPTOLITE_NIST_P_SHIFT_MUL_RED_ALG, 161 CY_CRYPTOLITE_NIST_P_BARRETT_RED_ALG 162 } cy_en_cryptolite_ecc_red_mul_algs_t; 163 164 165 /** 166 * \addtogroup group_cryptolite_enums 167 * \{ 168 */ 169 170 /** Defines the direction of the Crypto methods */ 171 typedef enum 172 { 173 /** The forward mode, plain text will be encrypted into cipher text */ 174 CY_CRYPTOLITE_ENCRYPT = 0x00u, 175 /** The reverse mode, cipher text will be decrypted into plain text */ 176 CY_CRYPTOLITE_DECRYPT = 0x01u 177 } cy_en_cryptolite_dir_mode_t; 178 179 /** \} group_cryptolite_enums */ 180 181 182 #if defined(__cplusplus) 183 } 184 #endif 185 186 #endif /* CY_IP_MXCRYPTOLITE */ 187 188 #endif /* #if !defined (CY_CRYPTOLITE_COMMON_H) */ 189 /** \} group_cryptolite */ 190 191 /* [] END OF FILE */ 192