1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 #include <string.h> 6 #include <time.h> 7 #include <stdio.h> 8 9 #include <rte_cryptodev.h> 10 11 #include "fips_validation.h" 12 13 #define NEW_LINE_STR "#" 14 #define OP_STR "GCM " 15 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 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 = " 30 31 #define OP_ENC_STR "Encrypt" 32 #define OP_DEC_STR "Decrypt" 33 34 #define NEG_TEST_STR "FAIL" 35 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, 42 &vec.aead.digest}, 43 {NULL, NULL, NULL} /**< end pointer */ 44 }; 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. 52 */ 53 {AADLEN_STR, parser_read_uint32_bit_val, &vec.aead.aad}, 54 {TAGLEN_STR, parser_read_uint32_bit_val, 55 &vec.aead.digest}, 56 {NULL, NULL, NULL} /**< end pointer */ 57 }; 58 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 */ 65 }; 66 67 static int 68 parse_test_gcm_writeback(struct fips_val *val) 69 { 70 struct fips_val tmp_val; 71 72 if (info.op == FIPS_TEST_ENC_AUTH_GEN) { 73 fprintf(info.fp_wr, "%s", CT_STR); 74 75 tmp_val.val = val->val; 76 tmp_val.len = vec.pt.len; 77 78 parse_write_hex_str(&tmp_val); 79 80 fprintf(info.fp_wr, "%s", TAG_STR); 81 82 tmp_val.val = val->val + vec.pt.len; 83 tmp_val.len = val->len - vec.pt.len; 84 85 parse_write_hex_str(&tmp_val); 86 } else { 87 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) { 88 fprintf(info.fp_wr, "%s", PT_STR); 89 90 tmp_val.val = val->val; 91 tmp_val.len = vec.pt.len; 92 93 parse_write_hex_str(&tmp_val); 94 } else 95 fprintf(info.fp_wr, "%s\n", NEG_TEST_STR); 96 } 97 98 return 0; 99 } 100 101 int 102 parse_test_gcm_init(void) 103 { 104 char *tmp; 105 uint32_t i; 106 107 108 for (i = 0; i < info.nb_vec_lines; i++) { 109 char *line = info.vec[i]; 110 111 112 tmp = strstr(line, OP_STR); 113 if (tmp) { 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; 120 } else 121 return -EINVAL; 122 } 123 } 124 125 info.interim_callbacks = gcm_interim_vectors; 126 info.parse_writeback = parse_test_gcm_writeback; 127 128 return 0; 129 } 130