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_MAX 28 }; 29 30 enum file_types { 31 FIPS_TYPE_REQ = 1, 32 FIPS_TYPE_FAX, 33 FIPS_TYPE_RSP 34 }; 35 36 enum fips_test_op { 37 FIPS_TEST_ENC_AUTH_GEN = 1, 38 FIPS_TEST_DEC_AUTH_VERIF, 39 }; 40 41 #define MAX_LINE_PER_VECTOR 16 42 43 struct fips_val { 44 uint8_t *val; 45 uint32_t len; 46 }; 47 48 struct fips_test_vector { 49 union { 50 struct { 51 struct fips_val key; 52 struct fips_val digest; 53 struct fips_val auth_aad; 54 struct fips_val aad; 55 } cipher_auth; 56 struct { 57 struct fips_val key; 58 struct fips_val digest; 59 struct fips_val aad; 60 } aead; 61 }; 62 63 struct fips_val pt; 64 struct fips_val ct; 65 struct fips_val iv; 66 67 enum rte_crypto_op_status status; 68 }; 69 70 typedef int (*post_prcess_t)(struct fips_val *val); 71 72 typedef int (*parse_callback_t)(const char *key, char *text, 73 struct fips_val *val); 74 75 struct fips_test_callback { 76 const char *key; 77 parse_callback_t cb; 78 struct fips_val *val; 79 }; 80 81 enum fips_aesavs_test_types { 82 AESAVS_TYPE_GFXBOX = 1, 83 AESAVS_TYPE_KEYSBOX, 84 AESAVS_TYPE_VARKEY, 85 AESAVS_TYPE_VARTXT, 86 AESAVS_TYPE_MMT, 87 AESAVS_TYPE_MCT, 88 }; 89 90 struct aesavs_interim_data { 91 enum fips_aesavs_test_types test_type; 92 uint32_t cipher_algo; 93 uint32_t key_len; 94 }; 95 96 struct fips_test_interim_info { 97 FILE *fp_rd; 98 FILE *fp_wr; 99 enum file_types file_type; 100 enum fips_test_algorithms algo; 101 char *one_line_text; 102 char *vec[MAX_LINE_PER_VECTOR]; 103 uint32_t nb_vec_lines; 104 char device_name[MAX_STRING_SIZE]; 105 106 union { 107 struct aesavs_interim_data aes_data; 108 109 } interim_info; 110 111 enum fips_test_op op; 112 113 const struct fips_test_callback *callbacks; 114 const struct fips_test_callback *interim_callbacks; 115 const struct fips_test_callback *writeback_callbacks; 116 117 post_prcess_t parse_writeback; 118 post_prcess_t kat_check; 119 }; 120 121 extern struct fips_test_vector vec; 122 extern struct fips_test_interim_info info; 123 124 int 125 fips_test_init(const char *req_file_path, const char *rsp_file_path, 126 const char *device_name); 127 128 void 129 fips_test_clear(void); 130 131 int 132 fips_test_fetch_one_block(void); 133 134 int 135 fips_test_parse_one_case(void); 136 137 void 138 fips_test_write_one_case(void); 139 140 int 141 parse_test_aes_init(void); 142 143 int 144 parser_read_uint8_hex(uint8_t *value, const char *p); 145 146 int 147 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val); 148 149 int 150 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val); 151 152 int 153 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 154 155 int 156 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val); 157 158 int 159 parser_read_uint32(uint32_t *value, char *p); 160 161 int 162 parser_read_uint32_val(const char *key, char *src, struct fips_val *val); 163 164 int 165 writeback_hex_str(const char *key, char *dst, struct fips_val *val); 166 167 void 168 parse_write_hex_str(struct fips_val *src); 169 170 int 171 update_info_vec(uint32_t count); 172 173 #endif 174