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 18 #define POSITIVE_TEST 0 19 #define NEGATIVE_TEST -1 20 21 #define REQ_FILE_PERFIX "req" 22 #define RSP_FILE_PERFIX "rsp" 23 #define FAX_FILE_PERFIX "fax" 24 25 enum fips_test_algorithms { 26 FIPS_TEST_ALGO_AES = 0, 27 FIPS_TEST_ALGO_AES_GCM, 28 FIPS_TEST_ALGO_AES_CMAC, 29 FIPS_TEST_ALGO_AES_CCM, 30 FIPS_TEST_ALGO_HMAC, 31 FIPS_TEST_ALGO_TDES, 32 FIPS_TEST_ALGO_MAX 33 }; 34 35 enum file_types { 36 FIPS_TYPE_REQ = 1, 37 FIPS_TYPE_FAX, 38 FIPS_TYPE_RSP 39 }; 40 41 enum fips_test_op { 42 FIPS_TEST_ENC_AUTH_GEN = 1, 43 FIPS_TEST_DEC_AUTH_VERIF, 44 }; 45 46 #define MAX_LINE_PER_VECTOR 16 47 48 struct fips_val { 49 uint8_t *val; 50 uint32_t len; 51 }; 52 53 struct fips_test_vector { 54 union { 55 struct { 56 struct fips_val key; 57 struct fips_val digest; 58 struct fips_val auth_aad; 59 struct fips_val aad; 60 } cipher_auth; 61 struct { 62 struct fips_val key; 63 struct fips_val digest; 64 struct fips_val aad; 65 } aead; 66 }; 67 68 struct fips_val pt; 69 struct fips_val ct; 70 struct fips_val iv; 71 72 enum rte_crypto_op_status status; 73 }; 74 75 typedef int (*post_prcess_t)(struct fips_val *val); 76 77 typedef int (*parse_callback_t)(const char *key, char *text, 78 struct fips_val *val); 79 80 struct fips_test_callback { 81 const char *key; 82 parse_callback_t cb; 83 struct fips_val *val; 84 }; 85 86 enum fips_aesavs_test_types { 87 AESAVS_TYPE_GFXBOX = 1, 88 AESAVS_TYPE_KEYSBOX, 89 AESAVS_TYPE_VARKEY, 90 AESAVS_TYPE_VARTXT, 91 AESAVS_TYPE_MMT, 92 AESAVS_TYPE_MCT, 93 }; 94 95 enum fips_tdes_test_types { 96 TDES_INVERSE_PERMUTATION = 0, 97 TDES_PERMUTATION, 98 TDES_SUBSTITUTION_TABLE, 99 TDES_VARIABLE_KEY, 100 TDES_VARIABLE_TEXT, 101 TDES_KAT, 102 TDES_MCT, /* Monte Carlo (Modes) Test */ 103 TDES_MMT /* Multi block Message Test */ 104 }; 105 106 enum fips_ccm_test_types { 107 CCM_VADT = 1, /* Variable Associated Data Test */ 108 CCM_VPT, /* Variable Payload Test */ 109 CCM_VNT, /* Variable Nonce Test */ 110 CCM_VTT, /* Variable Tag Test */ 111 CCM_DVPT, /* Decryption-Verification Process Test */ 112 }; 113 114 struct aesavs_interim_data { 115 enum fips_aesavs_test_types test_type; 116 uint32_t cipher_algo; 117 uint32_t key_len; 118 }; 119 120 struct hmac_interim_data { 121 enum rte_crypto_auth_algorithm algo; 122 }; 123 124 struct tdes_interim_data { 125 enum fips_tdes_test_types test_type; 126 uint32_t nb_keys; 127 }; 128 129 struct ccm_interim_data { 130 enum fips_ccm_test_types test_type; 131 uint32_t aad_len; 132 uint32_t pt_len; 133 uint32_t digest_len; 134 uint32_t key_len; 135 uint32_t iv_len; 136 }; 137 138 struct fips_test_interim_info { 139 FILE *fp_rd; 140 FILE *fp_wr; 141 enum file_types file_type; 142 enum fips_test_algorithms algo; 143 char *one_line_text; 144 char *vec[MAX_LINE_PER_VECTOR]; 145 uint32_t nb_vec_lines; 146 char device_name[MAX_STRING_SIZE]; 147 148 union { 149 struct aesavs_interim_data aes_data; 150 struct hmac_interim_data hmac_data; 151 struct tdes_interim_data tdes_data; 152 struct ccm_interim_data ccm_data; 153 154 } interim_info; 155 156 enum fips_test_op op; 157 158 const struct fips_test_callback *callbacks; 159 const struct fips_test_callback *interim_callbacks; 160 const struct fips_test_callback *writeback_callbacks; 161 162 post_prcess_t parse_writeback; 163 post_prcess_t kat_check; 164 }; 165 166 extern struct fips_test_vector vec; 167 extern struct fips_test_interim_info info; 168 169 int 170 fips_test_init(const char *req_file_path, const char *rsp_file_path, 171 const char *device_name); 172 173 void 174 fips_test_clear(void); 175 176 int 177 fips_test_fetch_one_block(void); 178 179 int 180 fips_test_parse_one_case(void); 181 182 void 183 fips_test_write_one_case(void); 184 185 int 186 parse_test_aes_init(void); 187 188 int 189 parse_test_tdes_init(void); 190 191 int 192 parse_test_hmac_init(void); 193 194 int 195 parse_test_gcm_init(void); 196 197 int 198 parse_test_cmac_init(void); 199 200 int 201 parse_test_ccm_init(void); 202 203 int 204 parser_read_uint8_hex(uint8_t *value, const char *p); 205 206 int 207 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val); 208 209 int 210 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val); 211 212 int 213 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 214 215 int 216 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val); 217 218 int 219 parser_read_uint32(uint32_t *value, char *p); 220 221 int 222 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 223 224 int 225 writeback_hex_str(const char *key, char *dst, struct fips_val *val); 226 227 void 228 parse_write_hex_str(struct fips_val *src); 229 230 int 231 update_info_vec(uint32_t count); 232 233 #endif 234