1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
9 #include <rte_cryptodev.h>
11 #include "fips_validation.h"
13 #define NEW_LINE_STR "#"
16 #define PARAM_PREFIX "["
17 #define KEYLEN_STR "Keylen = "
18 #define IVLEN_STR "IVlen = "
19 #define PTLEN_STR "PTlen = "
20 #define AADLEN_STR "AADlen = "
21 #define TAGLEN_STR "Taglen = "
23 #define COUNT_STR "Count = "
24 #define KEY_STR "Key = "
25 #define IV_STR "IV = "
26 #define PT_STR "PT = "
27 #define CT_STR "CT = "
28 #define TAG_STR "Tag = "
29 #define AAD_STR "AAD = "
31 #define OP_ENC_STR "Encrypt"
32 #define OP_DEC_STR "Decrypt"
34 #define NEG_TEST_STR "FAIL"
36 struct fips_test_callback gcm_dec_vectors[] = {
37 {KEY_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key},
38 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
39 {CT_STR, parse_uint8_known_len_hex_str, &vec.ct},
40 {AAD_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.aad},
41 {TAG_STR, parse_uint8_known_len_hex_str,
42 &vec.cipher_auth.digest},
43 {NULL, NULL, NULL} /**< end pointer */
45 struct fips_test_callback gcm_interim_vectors[] = {
46 {KEYLEN_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key},
47 {IVLEN_STR, parser_read_uint32_bit_val, &vec.iv},
48 {PTLEN_STR, parser_read_uint32_bit_val, &vec.pt},
49 {AADLEN_STR, parser_read_uint32_bit_val, &vec.cipher_auth.aad},
50 {TAGLEN_STR, parser_read_uint32_bit_val,
51 &vec.cipher_auth.digest},
52 {NULL, NULL, NULL} /**< end pointer */
55 struct fips_test_callback gcm_enc_vectors[] = {
56 {KEY_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key},
57 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
58 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
59 {AAD_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.aad},
60 {NULL, NULL, NULL} /**< end pointer */
64 parse_test_gcm_writeback(struct fips_val *val)
66 struct fips_val tmp_val;
68 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
69 fprintf(info.fp_wr, "%s", CT_STR);
71 tmp_val.val = val->val;
72 tmp_val.len = vec.pt.len;
74 parse_write_hex_str(&tmp_val);
76 fprintf(info.fp_wr, "%s", TAG_STR);
78 tmp_val.val = val->val + vec.pt.len;
79 tmp_val.len = val->len - vec.pt.len;
81 parse_write_hex_str(&tmp_val);
83 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
84 fprintf(info.fp_wr, "%s", PT_STR);
86 tmp_val.val = val->val;
87 tmp_val.len = vec.pt.len;
89 parse_write_hex_str(&tmp_val);
91 fprintf(info.fp_wr, "%s\n", NEG_TEST_STR);
98 parse_test_gcm_init(void)
104 for (i = 0; i < info.nb_vec_lines; i++) {
105 char *line = info.vec[i];
108 tmp = strstr(line, OP_STR);
110 if (strstr(line, OP_ENC_STR)) {
111 info.op = FIPS_TEST_ENC_AUTH_GEN;
112 info.callbacks = gcm_enc_vectors;
113 } else if (strstr(line, OP_DEC_STR)) {
114 info.op = FIPS_TEST_DEC_AUTH_VERIF;
115 info.callbacks = gcm_dec_vectors;
121 info.interim_callbacks = gcm_interim_vectors;
122 info.parse_writeback = parse_test_gcm_writeback;