]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/examples/fips_validation/fips_validation_gcm.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / examples / fips_validation / fips_validation_gcm.c
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.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 */
44 };
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 */
53 };
54
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 */
61 };
62
63 static int
64 parse_test_gcm_writeback(struct fips_val *val)
65 {
66 struct fips_val tmp_val;
67
68 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
69 fprintf(info.fp_wr, "%s", CT_STR);
70
71 tmp_val.val = val->val;
72 tmp_val.len = vec.pt.len;
73
74 parse_write_hex_str(&tmp_val);
75
76 fprintf(info.fp_wr, "%s", TAG_STR);
77
78 tmp_val.val = val->val + vec.pt.len;
79 tmp_val.len = val->len - vec.pt.len;
80
81 parse_write_hex_str(&tmp_val);
82 } else {
83 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
84 fprintf(info.fp_wr, "%s", PT_STR);
85
86 tmp_val.val = val->val;
87 tmp_val.len = vec.pt.len;
88
89 parse_write_hex_str(&tmp_val);
90 } else
91 fprintf(info.fp_wr, "%s\n", NEG_TEST_STR);
92 }
93
94 return 0;
95 }
96
97 int
98 parse_test_gcm_init(void)
99 {
100 char *tmp;
101 uint32_t i;
102
103
104 for (i = 0; i < info.nb_vec_lines; i++) {
105 char *line = info.vec[i];
106
107
108 tmp = strstr(line, OP_STR);
109 if (tmp) {
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;
116 } else
117 return -EINVAL;
118 }
119 }
120
121 info.interim_callbacks = gcm_interim_vectors;
122 info.parse_writeback = parse_test_gcm_writeback;
123
124 return 0;
125 }