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.aead.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.aead.aad},
41 {TAG_STR, parse_uint8_known_len_hex_str,
43 {NULL, NULL, NULL} /**< end pointer */
45 struct fips_test_callback gcm_interim_vectors[] = {
46 {KEYLEN_STR, parser_read_uint32_bit_val, &vec.aead.key},
47 {IVLEN_STR, parser_read_uint32_bit_val, &vec.iv},
48 {PTLEN_STR, parser_read_uint32_bit_val, &vec.pt},
49 {PTLEN_STR, parser_read_uint32_bit_val, &vec.ct},
50 /**< The NIST test vectors use 'PTlen' to denote input text
51 * length in case of decrypt & encrypt operations.
53 {AADLEN_STR, parser_read_uint32_bit_val, &vec.aead.aad},
54 {TAGLEN_STR, parser_read_uint32_bit_val,
56 {NULL, NULL, NULL} /**< end pointer */
59 struct fips_test_callback gcm_enc_vectors[] = {
60 {KEY_STR, parse_uint8_known_len_hex_str, &vec.aead.key},
61 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
62 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
63 {AAD_STR, parse_uint8_known_len_hex_str, &vec.aead.aad},
64 {NULL, NULL, NULL} /**< end pointer */
68 parse_test_gcm_writeback(struct fips_val *val)
70 struct fips_val tmp_val;
72 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
73 fprintf(info.fp_wr, "%s", CT_STR);
75 tmp_val.val = val->val;
76 tmp_val.len = vec.pt.len;
78 parse_write_hex_str(&tmp_val);
80 fprintf(info.fp_wr, "%s", TAG_STR);
82 tmp_val.val = val->val + vec.pt.len;
83 tmp_val.len = val->len - vec.pt.len;
85 parse_write_hex_str(&tmp_val);
87 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
88 fprintf(info.fp_wr, "%s", PT_STR);
90 tmp_val.val = val->val;
91 tmp_val.len = vec.pt.len;
93 parse_write_hex_str(&tmp_val);
95 fprintf(info.fp_wr, "%s\n", NEG_TEST_STR);
102 parse_test_gcm_init(void)
108 for (i = 0; i < info.nb_vec_lines; i++) {
109 char *line = info.vec[i];
112 tmp = strstr(line, OP_STR);
114 if (strstr(line, OP_ENC_STR)) {
115 info.op = FIPS_TEST_ENC_AUTH_GEN;
116 info.callbacks = gcm_enc_vectors;
117 } else if (strstr(line, OP_DEC_STR)) {
118 info.op = FIPS_TEST_DEC_AUTH_VERIF;
119 info.callbacks = gcm_dec_vectors;
125 info.interim_callbacks = gcm_interim_vectors;
126 info.parse_writeback = parse_test_gcm_writeback;