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 = "
22 #define CTLEN_STR "CTlen = "
24 #define COUNT_STR "Count = "
25 #define KEY_STR "Key = "
26 #define IV_STR "IV = "
27 #define PT_STR "PT = "
28 #define CT_STR "CT = "
29 #define TAG_STR "Tag = "
30 #define AAD_STR "AAD = "
32 #define OP_ENC_STR "Encrypt"
33 #define OP_DEC_STR "Decrypt"
35 #define NEG_TEST_STR "FAIL"
37 struct fips_test_callback gcm_dec_vectors[] = {
38 {KEY_STR, parse_uint8_known_len_hex_str, &vec.aead.key},
39 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
40 {CT_STR, parse_uint8_known_len_hex_str, &vec.ct},
41 {AAD_STR, parse_uint8_known_len_hex_str, &vec.aead.aad},
42 {TAG_STR, parse_uint8_known_len_hex_str,
44 {NULL, NULL, NULL} /**< end pointer */
46 struct fips_test_callback gcm_interim_vectors[] = {
47 {KEYLEN_STR, parser_read_uint32_bit_val, &vec.aead.key},
48 {IVLEN_STR, parser_read_uint32_bit_val, &vec.iv},
49 {PTLEN_STR, parser_read_uint32_bit_val, &vec.pt},
50 {CTLEN_STR, parser_read_uint32_bit_val, &vec.ct},
51 {AADLEN_STR, parser_read_uint32_bit_val, &vec.aead.aad},
52 {TAGLEN_STR, parser_read_uint32_bit_val,
54 {NULL, NULL, NULL} /**< end pointer */
57 struct fips_test_callback gcm_enc_vectors[] = {
58 {KEY_STR, parse_uint8_known_len_hex_str, &vec.aead.key},
59 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
60 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
61 {AAD_STR, parse_uint8_known_len_hex_str, &vec.aead.aad},
62 {NULL, NULL, NULL} /**< end pointer */
66 parse_test_gcm_writeback(struct fips_val *val)
68 struct fips_val tmp_val;
70 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
71 fprintf(info.fp_wr, "%s", CT_STR);
73 tmp_val.val = val->val;
74 tmp_val.len = vec.pt.len;
76 parse_write_hex_str(&tmp_val);
78 fprintf(info.fp_wr, "%s", TAG_STR);
80 tmp_val.val = val->val + vec.pt.len;
81 tmp_val.len = val->len - vec.pt.len;
83 parse_write_hex_str(&tmp_val);
85 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
86 fprintf(info.fp_wr, "%s", PT_STR);
88 tmp_val.val = val->val;
89 tmp_val.len = vec.pt.len;
91 parse_write_hex_str(&tmp_val);
93 fprintf(info.fp_wr, "%s\n", NEG_TEST_STR);
100 parse_test_gcm_init(void)
106 for (i = 0; i < info.nb_vec_lines; i++) {
107 char *line = info.vec[i];
110 tmp = strstr(line, OP_STR);
112 if (strstr(line, OP_ENC_STR)) {
113 info.op = FIPS_TEST_ENC_AUTH_GEN;
114 info.callbacks = gcm_enc_vectors;
115 } else if (strstr(line, OP_DEC_STR)) {
116 info.op = FIPS_TEST_DEC_AUTH_VERIF;
117 info.callbacks = gcm_dec_vectors;
123 info.interim_callbacks = gcm_interim_vectors;
124 info.parse_writeback = parse_test_gcm_writeback;