xref: /dpdk/app/test/test_cryptodev_security_tls_record.h (revision b22cdccdd366c06e45888713ed865061c3181e3a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2023 Marvell.
3  */
4 
5 #ifndef _TEST_CRYPTODEV_SECURITY_TLS_RECORD_H_
6 #define _TEST_CRYPTODEV_SECURITY_TLS_RECORD_H_
7 
8 #include <rte_cryptodev.h>
9 #include <rte_security.h>
10 
11 #include "test_security_proto.h"
12 
13 /* TLS 1.2 Ciphertext length can be up to (2^14 + 2048 + 5 (TLS Header)) Bytes */
14 #define TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN  (18437u)
15 static_assert(TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
16 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
17 
18 /* TLS 1.2 Plaintext length can be up to (2^14 + 1024) Bytes */
19 #define TLS_1_2_RECORD_PLAINTEXT_MAX_LEN   (17408u)
20 static_assert(TLS_1_2_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
21 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
22 
23 /* DTLS 1.2 Ciphertext length is similar to TLS 1.2 */
24 #define DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (18437u)
25 static_assert(DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
26 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
27 
28 /* DTLS 1.2 Plaintext length is similar to TLS 1.2 */
29 #define DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN  (17408u)
30 static_assert(DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
31 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
32 
33 /* TLS 1.3 Ciphertext length can be up to (2^14 + 256 + 5 (TLS Header)) Bytes */
34 #define TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN  (16645u)
35 static_assert(TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
36 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
37 
38 /* TLS 1.3 Plaintext length can be up to 2^14 Bytes */
39 #define TLS_1_3_RECORD_PLAINTEXT_MAX_LEN   (16384u)
40 static_assert(TLS_1_3_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
41 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
42 
43 #define TLS_RECORD_PLAINTEXT_MIN_LEN       (1u)
44 #define TLS_RECORD_PAD_CORRUPT_OFFSET      20
45 
46 enum tls_record_test_content_type {
47 	TLS_RECORD_TEST_CONTENT_TYPE_APP,
48 	/* For verifying zero packet length */
49 	TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE,
50 	/* For verifying handling of custom content types */
51 	TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM,
52 };
53 
54 struct tls_record_test_data {
55 	struct {
56 		uint8_t data[32];
57 	} key;
58 
59 	struct {
60 		uint8_t data[64];
61 	} auth_key;
62 
63 	struct {
64 		uint8_t data[TEST_SEC_CIPHERTEXT_MAX_LEN];
65 		unsigned int len;
66 	} input_text;
67 
68 	struct {
69 		uint8_t data[TEST_SEC_CIPHERTEXT_MAX_LEN];
70 		unsigned int len;
71 	} output_text;
72 
73 	struct {
74 		uint8_t data[12];
75 		unsigned int len;
76 	} imp_nonce;
77 
78 	struct {
79 		uint8_t data[16];
80 	} iv;
81 
82 	union {
83 		struct {
84 			struct rte_crypto_sym_xform cipher;
85 			struct rte_crypto_sym_xform auth;
86 		} chain;
87 		struct rte_crypto_sym_xform aead;
88 	} xform;
89 
90 	struct rte_security_tls_record_xform tls_record_xform;
91 	uint8_t app_type;
92 	bool aead;
93 	bool ar_packet;
94 };
95 
96 struct tls_record_test_flags {
97 	bool display_alg;
98 	bool data_walkthrough;
99 	bool pkt_corruption;
100 	bool zero_len;
101 	bool padding_corruption;
102 	bool out_of_place;
103 	bool skip_sess_destroy;
104 	uint8_t nb_segs_in_mbuf;
105 	uint8_t opt_padding;
106 	enum rte_security_tls_version tls_version;
107 	enum tls_record_test_content_type content_type;
108 	int ar_win_size;
109 };
110 
111 extern struct tls_record_test_data tls_test_data_aes_128_gcm_v1;
112 extern struct tls_record_test_data tls_test_data_aes_128_gcm_v2;
113 extern struct tls_record_test_data tls_test_data_aes_256_gcm;
114 extern struct tls_record_test_data dtls_test_data_aes_128_gcm;
115 extern struct tls_record_test_data dtls_test_data_aes_256_gcm;
116 extern struct tls_record_test_data tls_test_data_aes_128_cbc_sha1_hmac;
117 extern struct tls_record_test_data tls_test_data_aes_128_cbc_sha256_hmac;
118 extern struct tls_record_test_data tls_test_data_aes_256_cbc_sha1_hmac;
119 extern struct tls_record_test_data tls_test_data_aes_256_cbc_sha256_hmac;
120 extern struct tls_record_test_data tls_test_data_aes_256_cbc_sha384_hmac;
121 extern struct tls_record_test_data tls_test_data_3des_cbc_sha1_hmac;
122 extern struct tls_record_test_data tls_test_data_null_cipher_sha1_hmac;
123 extern struct tls_record_test_data tls_test_data_chacha20_poly1305;
124 extern struct tls_record_test_data dtls_test_data_chacha20_poly1305;
125 extern struct tls_record_test_data dtls_test_data_aes_128_cbc_sha1_hmac;
126 extern struct tls_record_test_data dtls_test_data_aes_128_cbc_sha256_hmac;
127 extern struct tls_record_test_data dtls_test_data_aes_256_cbc_sha1_hmac;
128 extern struct tls_record_test_data dtls_test_data_aes_256_cbc_sha256_hmac;
129 extern struct tls_record_test_data dtls_test_data_aes_256_cbc_sha384_hmac;
130 extern struct tls_record_test_data dtls_test_data_3des_cbc_sha1_hmac;
131 extern struct tls_record_test_data dtls_test_data_null_cipher_sha1_hmac;
132 extern struct tls_record_test_data tls13_test_data_aes_128_gcm;
133 extern struct tls_record_test_data tls13_test_data_aes_256_gcm;
134 extern struct tls_record_test_data tls13_test_data_chacha20_poly1305;
135 
136 int test_tls_record_status_check(struct rte_crypto_op *op,
137 				 const struct tls_record_test_data *td);
138 
139 int test_tls_record_sec_caps_verify(struct rte_security_tls_record_xform *tls_record_xform,
140 				    const struct rte_security_capability *sec_cap, bool silent);
141 
142 void test_tls_record_td_read_from_write(const struct tls_record_test_data *td_out,
143 					struct tls_record_test_data *td_in);
144 
145 int test_tls_record_td_prepare(const struct crypto_param *param1,
146 			       const struct crypto_param *param2,
147 			       const struct tls_record_test_flags *flags,
148 			       struct tls_record_test_data *td_array, int nb_td,
149 			       unsigned int data_len);
150 
151 void test_tls_record_td_update(struct tls_record_test_data td_inb[],
152 			       const struct tls_record_test_data td_outb[], int nb_td,
153 			       const struct tls_record_test_flags *flags);
154 
155 int test_tls_record_post_process(const struct rte_mbuf *m, const struct tls_record_test_data *td,
156 				 struct tls_record_test_data *res_d, bool silent,
157 				 const struct tls_record_test_flags *flags);
158 #endif
159