1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2020 Marvell International Ltd.
9 #include <rte_cryptodev.h>
11 #include "fips_validation.h"
13 #define MODE_STR "XTS"
14 #define ALGO_STR "test data for "
15 #define OP_STR "State"
16 #define KEY_SIZE_STR "Key Length : "
18 #define COUNT_STR "COUNT = "
19 #define KEY_STR "Key = "
21 #define PT_STR "PT = "
22 #define CT_STR "CT = "
24 #define OP_ENC_STR "ENCRYPT"
25 #define OP_DEC_STR "DECRYPT"
28 parse_interim_xts_enc_dec(const char *key,
29 __rte_unused char *text,
30 __rte_unused struct fips_val *val)
32 if (strcmp(key, OP_ENC_STR) == 0)
33 info.op = FIPS_TEST_ENC_AUTH_GEN;
34 else if (strcmp(key, OP_DEC_STR) == 0)
35 info.op = FIPS_TEST_DEC_AUTH_VERIF;
41 struct fips_test_callback xts_tests_vectors[] = {
42 {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
43 {IV_STR, parse_uint8_hex_str, &vec.iv},
44 {PT_STR, parse_uint8_hex_str, &vec.pt},
45 {CT_STR, parse_uint8_hex_str, &vec.ct},
46 {NULL, NULL, NULL} /**< end pointer */
49 struct fips_test_callback xts_tests_interim_vectors[] = {
50 {OP_ENC_STR, parse_interim_xts_enc_dec, NULL},
51 {OP_DEC_STR, parse_interim_xts_enc_dec, NULL},
52 {NULL, NULL, NULL} /**< end pointer */
55 struct fips_test_callback xts_writeback_callbacks[] = {
56 /** First element is used to pass COUNT string */
57 {COUNT_STR, NULL, NULL},
58 {IV_STR, writeback_hex_str, &vec.iv},
59 {KEY_STR, writeback_hex_str, &vec.cipher_auth.key},
60 {PT_STR, writeback_hex_str, &vec.pt},
61 {CT_STR, writeback_hex_str, &vec.ct},
62 {NULL, NULL, NULL} /**< end pointer */
66 parse_test_xts_writeback(struct fips_val *val)
68 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
69 fprintf(info.fp_wr, "%s", CT_STR);
71 fprintf(info.fp_wr, "%s", PT_STR);
73 parse_write_hex_str(val);
78 rsp_test_xts_check(struct fips_val *val)
80 struct fips_val *data;
81 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
86 if (memcmp(val->val, data->val, val->len) == 0)
87 fprintf(info.fp_wr, "Success\n");
89 fprintf(info.fp_wr, "Failed\n");
93 int parse_test_xts_init(void)
97 for (i = 0; i < info.nb_vec_lines; i++) {
98 char *line = info.vec[i];
99 tmp = strstr(line, KEY_SIZE_STR);
101 tmp += (strlen(KEY_SIZE_STR) + strlen("AES"));
102 if (parser_read_uint32(
103 &info.interim_info.aes_data.key_len,
106 info.interim_info.aes_data.key_len =
107 (info.interim_info.aes_data.key_len*2) / 8;
112 info.parse_writeback = parse_test_xts_writeback;
113 info.callbacks = xts_tests_vectors;
114 info.interim_callbacks = xts_tests_interim_vectors;
115 info.writeback_callbacks = xts_writeback_callbacks;
116 info.kat_check = rsp_test_xts_check;