33
33
int main (int argc , char * * argv )
34
34
{
35
35
struct s2n_connection * conn ;
36
- uint8_t random_data [S2N_MAXIMUM_FRAGMENT_LENGTH + 1 ];
36
+ uint8_t random_data [S2N_DEFAULT_FRAGMENT_LENGTH + 1 ];
37
37
uint8_t mac_key [] = "sample mac key" ;
38
38
uint8_t aes128_key [] = "123456789012345" ;
39
39
uint8_t aes256_key [] = "1234567890123456789012345678901" ;
@@ -59,18 +59,21 @@ int main(int argc, char **argv)
59
59
EXPECT_SUCCESS (s2n_hmac_init (& conn -> active .server_record_mac , S2N_HMAC_SHA1 , mac_key , sizeof (mac_key )));
60
60
conn -> actual_protocol_version = S2N_TLS12 ;
61
61
62
- int max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - ( S2N_MAXIMUM_FRAGMENT_LENGTH % 16 ) ;
63
- for (int i = 0 ; i <= max_aligned_fragment + 1 ; i ++ ) {
62
+ int max_fragment = S2N_DEFAULT_FRAGMENT_LENGTH ;
63
+ for (int i = 0 ; i <= max_fragment + 1 ; i ++ ) {
64
64
struct s2n_blob in = {.data = random_data ,.size = i };
65
65
int bytes_written ;
66
66
67
67
EXPECT_SUCCESS (s2n_stuffer_wipe (& conn -> out ));
68
68
EXPECT_SUCCESS (bytes_written = s2n_record_write (conn , TLS_APPLICATION_DATA , & in ));
69
69
70
- if (i < max_aligned_fragment - 20 - 8 - 1 ) {
70
+ static const int overhead = 20 /* TLS header */
71
+ + 8 /* IV */
72
+ + 16 ; /* TAG */
73
+ if (i < max_fragment - overhead ) {
71
74
EXPECT_EQUAL (bytes_written , i );
72
75
} else {
73
- EXPECT_EQUAL (bytes_written , max_aligned_fragment - 20 - 8 - 1 );
76
+ EXPECT_EQUAL (bytes_written , max_fragment - overhead );
74
77
}
75
78
76
79
uint16_t predicted_length = bytes_written + 20 ;
@@ -187,18 +190,20 @@ int main(int argc, char **argv)
187
190
EXPECT_SUCCESS (s2n_hmac_init (& conn -> active .server_record_mac , S2N_HMAC_SHA1 , mac_key , sizeof (mac_key )));
188
191
conn -> actual_protocol_version = S2N_TLS12 ;
189
192
190
- max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 16 );
191
- for (int i = 0 ; i <= max_aligned_fragment + 1 ; i ++ ) {
193
+ for (int i = 0 ; i <= max_fragment + 1 ; i ++ ) {
192
194
struct s2n_blob in = {.data = random_data ,.size = i };
193
195
int bytes_written ;
194
196
195
197
EXPECT_SUCCESS (s2n_stuffer_wipe (& conn -> out ));
196
198
EXPECT_SUCCESS (bytes_written = s2n_record_write (conn , TLS_APPLICATION_DATA , & in ));
197
199
198
- if (i < max_aligned_fragment - 20 - 8 - 1 ) {
200
+ static const int overhead = 20 /* TLS header */
201
+ + 8 /* IV */
202
+ + 16 ; /* TAG */
203
+ if (i < max_fragment - overhead ) {
199
204
EXPECT_EQUAL (bytes_written , i );
200
205
} else {
201
- EXPECT_EQUAL (bytes_written , max_aligned_fragment - 20 - 8 - 1 );
206
+ EXPECT_EQUAL (bytes_written , max_fragment - overhead );
202
207
}
203
208
204
209
uint16_t predicted_length = bytes_written + 20 ;
0 commit comments