1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 #ifndef _FIPS_VALIDATION_H_ 6 #define _FIPS_VALIDATION_H_ 7 8 #define FIPS_PARSE_ERR(fmt, args) \ 9 RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args) 10 11 #define ERR_MSG_SIZE 128 12 #define MAX_CASE_LINE 15 13 #define MAX_LINE_CHAR 204800 /*< max number of characters per line */ 14 #define MAX_NB_TESTS 10240 15 #define MAX_BUF_SIZE 2048 16 #define MAX_STRING_SIZE 64 17 #define MAX_FILE_NAME_SIZE 256 18 #define MAX_DIGEST_SIZE 64 19 20 #define POSITIVE_TEST 0 21 #define NEGATIVE_TEST -1 22 23 #define REQ_FILE_PERFIX "req" 24 #define RSP_FILE_PERFIX "rsp" 25 #define FAX_FILE_PERFIX "fax" 26 27 enum fips_test_algorithms { 28 FIPS_TEST_ALGO_AES = 0, 29 FIPS_TEST_ALGO_AES_GCM, 30 FIPS_TEST_ALGO_AES_CMAC, 31 FIPS_TEST_ALGO_AES_CCM, 32 FIPS_TEST_ALGO_HMAC, 33 FIPS_TEST_ALGO_TDES, 34 FIPS_TEST_ALGO_SHA, 35 FIPS_TEST_ALGO_AES_XTS, 36 FIPS_TEST_ALGO_MAX 37 }; 38 39 enum file_types { 40 FIPS_TYPE_REQ = 1, 41 FIPS_TYPE_FAX, 42 FIPS_TYPE_RSP 43 }; 44 45 enum fips_test_op { 46 FIPS_TEST_ENC_AUTH_GEN = 1, 47 FIPS_TEST_DEC_AUTH_VERIF, 48 }; 49 50 #define MAX_LINE_PER_VECTOR 16 51 52 struct fips_val { 53 uint8_t *val; 54 uint32_t len; 55 }; 56 57 struct fips_test_vector { 58 union { 59 struct { 60 struct fips_val key; 61 struct fips_val digest; 62 struct fips_val auth_aad; 63 struct fips_val aad; 64 } cipher_auth; 65 struct { 66 struct fips_val key; 67 struct fips_val digest; 68 struct fips_val aad; 69 } aead; 70 }; 71 72 struct fips_val pt; 73 struct fips_val ct; 74 struct fips_val iv; 75 76 enum rte_crypto_op_status status; 77 }; 78 79 typedef int (*post_prcess_t)(struct fips_val *val); 80 81 typedef int (*parse_callback_t)(const char *key, char *text, 82 struct fips_val *val); 83 84 struct fips_test_callback { 85 const char *key; 86 parse_callback_t cb; 87 struct fips_val *val; 88 }; 89 90 enum fips_aesavs_test_types { 91 AESAVS_TYPE_GFXBOX = 1, 92 AESAVS_TYPE_KEYSBOX, 93 AESAVS_TYPE_VARKEY, 94 AESAVS_TYPE_VARTXT, 95 AESAVS_TYPE_MMT, 96 AESAVS_TYPE_MCT, 97 }; 98 99 enum fips_tdes_test_types { 100 TDES_INVERSE_PERMUTATION = 0, 101 TDES_PERMUTATION, 102 TDES_SUBSTITUTION_TABLE, 103 TDES_VARIABLE_KEY, 104 TDES_VARIABLE_TEXT, 105 TDES_KAT, 106 TDES_MCT, /* Monte Carlo (Modes) Test */ 107 TDES_MMT /* Multi block Message Test */ 108 }; 109 110 enum fips_tdes_test_mode { 111 TDES_MODE_CBC = 0, 112 TDES_MODE_ECB 113 }; 114 115 enum fips_ccm_test_types { 116 CCM_VADT = 1, /* Variable Associated Data Test */ 117 CCM_VPT, /* Variable Payload Test */ 118 CCM_VNT, /* Variable Nonce Test */ 119 CCM_VTT, /* Variable Tag Test */ 120 CCM_DVPT, /* Decryption-Verification Process Test */ 121 }; 122 123 enum fips_sha_test_types { 124 SHA_KAT = 0, 125 SHA_MCT 126 }; 127 128 struct aesavs_interim_data { 129 enum fips_aesavs_test_types test_type; 130 uint32_t cipher_algo; 131 uint32_t key_len; 132 }; 133 134 struct hmac_interim_data { 135 enum rte_crypto_auth_algorithm algo; 136 }; 137 138 struct tdes_interim_data { 139 enum fips_tdes_test_types test_type; 140 enum fips_tdes_test_mode test_mode; 141 uint32_t nb_keys; 142 }; 143 144 struct ccm_interim_data { 145 enum fips_ccm_test_types test_type; 146 uint32_t aad_len; 147 uint32_t pt_len; 148 uint32_t digest_len; 149 uint32_t key_len; 150 uint32_t iv_len; 151 }; 152 153 struct sha_interim_data { 154 enum fips_sha_test_types test_type; 155 enum rte_crypto_auth_algorithm algo; 156 }; 157 158 struct fips_test_interim_info { 159 FILE *fp_rd; 160 FILE *fp_wr; 161 enum file_types file_type; 162 enum fips_test_algorithms algo; 163 char *one_line_text; 164 char *vec[MAX_LINE_PER_VECTOR]; 165 uint32_t vec_start_off; 166 uint32_t nb_vec_lines; 167 char device_name[MAX_STRING_SIZE]; 168 char file_name[MAX_FILE_NAME_SIZE]; 169 float version; 170 171 union { 172 struct aesavs_interim_data aes_data; 173 struct hmac_interim_data hmac_data; 174 struct tdes_interim_data tdes_data; 175 struct ccm_interim_data ccm_data; 176 struct sha_interim_data sha_data; 177 } interim_info; 178 179 enum fips_test_op op; 180 181 const struct fips_test_callback *callbacks; 182 const struct fips_test_callback *interim_callbacks; 183 const struct fips_test_callback *writeback_callbacks; 184 185 post_prcess_t parse_writeback; 186 post_prcess_t kat_check; 187 }; 188 189 extern struct fips_test_vector vec; 190 extern struct fips_test_interim_info info; 191 192 int 193 fips_test_init(const char *req_file_path, const char *rsp_file_path, 194 const char *device_name); 195 196 void 197 fips_test_clear(void); 198 199 int 200 fips_test_fetch_one_block(void); 201 202 int 203 fips_test_parse_one_case(void); 204 205 void 206 fips_test_write_one_case(void); 207 208 int 209 parse_test_aes_init(void); 210 211 int 212 parse_test_tdes_init(void); 213 214 int 215 parse_test_hmac_init(void); 216 217 int 218 parse_test_gcm_init(void); 219 220 int 221 parse_test_cmac_init(void); 222 223 int 224 parse_test_ccm_init(void); 225 226 int 227 parse_test_sha_init(void); 228 229 int 230 parse_test_xts_init(void); 231 232 int 233 parser_read_uint8_hex(uint8_t *value, const char *p); 234 235 int 236 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val); 237 238 int 239 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val); 240 241 int 242 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 243 244 int 245 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val); 246 247 int 248 parser_read_uint32(uint32_t *value, char *p); 249 250 int 251 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 252 253 int 254 writeback_hex_str(const char *key, char *dst, struct fips_val *val); 255 256 void 257 parse_write_hex_str(struct fips_val *src); 258 259 int 260 update_info_vec(uint32_t count); 261 262 #endif 263