Skip to content

Commit acb6666

Browse files
committed
Merge pull request #56 from venkat1109/master
Renamed S2N_MAXIMUM_FRAGMENT_ to S2N_DEFAULT_FRAGMENT_. Updated default leng...
2 parents 48e21b6 + 5fe34ec commit acb6666

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

tests/unit/s2n_3des_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ int main(int argc, char **argv)
3636
uint8_t mac_key[] = "sample mac key";
3737
uint8_t des3_key[] = "12345678901234567890123";
3838
struct s2n_blob des3 = {.data = des3_key,.size = sizeof(des3_key) };
39-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH + 1];
39+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH + 1];
4040

4141
BEGIN_TEST();
4242

4343
EXPECT_SUCCESS(s2n_init());
4444
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
45-
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_MAXIMUM_FRAGMENT_LENGTH + 1));
45+
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_DEFAULT_FRAGMENT_LENGTH + 1));
4646

4747
/* Peer and we are in sync */
4848
conn->server = &conn->active;
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
5757
EXPECT_SUCCESS(s2n_hmac_init(&conn->active.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
5858
conn->actual_protocol_version = S2N_TLS11;
5959

60-
int max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 8);
60+
int max_aligned_fragment = S2N_DEFAULT_FRAGMENT_LENGTH - (S2N_DEFAULT_FRAGMENT_LENGTH % 8);
6161
for (int i = 0; i <= max_aligned_fragment + 1; i++) {
6262
struct s2n_blob in = {.data = random_data,.size = i };
6363
int bytes_written;

tests/unit/s2n_aes_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ int main(int argc, char **argv)
3838
uint8_t aes256_key[] = "1234567890123456789012345678901";
3939
struct s2n_blob aes128 = {.data = aes128_key,.size = sizeof(aes128_key) };
4040
struct s2n_blob aes256 = {.data = aes256_key,.size = sizeof(aes256_key) };
41-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH + 1];
41+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH + 1];
4242

4343
BEGIN_TEST();
4444

4545
EXPECT_SUCCESS(s2n_init());
4646
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
47-
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_MAXIMUM_FRAGMENT_LENGTH + 1));
47+
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_DEFAULT_FRAGMENT_LENGTH + 1));
4848

4949
/* Peer and we are in sync */
5050
conn->server = &conn->active;
@@ -59,7 +59,7 @@ int main(int argc, char **argv)
5959
EXPECT_SUCCESS(s2n_hmac_init(&conn->active.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
6060
conn->actual_protocol_version = S2N_TLS11;
6161

62-
int max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 16);
62+
int max_aligned_fragment = S2N_DEFAULT_FRAGMENT_LENGTH - (S2N_DEFAULT_FRAGMENT_LENGTH % 16);
6363
for (int i = 0; i <= max_aligned_fragment + 1; i++) {
6464
struct s2n_blob in = {.data = random_data,.size = i };
6565
int bytes_written;
@@ -120,7 +120,7 @@ int main(int argc, char **argv)
120120
EXPECT_SUCCESS(s2n_hmac_init(&conn->active.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
121121
conn->actual_protocol_version = S2N_TLS11;
122122

123-
max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 16);
123+
max_aligned_fragment = S2N_DEFAULT_FRAGMENT_LENGTH - (S2N_DEFAULT_FRAGMENT_LENGTH % 16);
124124
for (int i = 0; i <= max_aligned_fragment + 1; i++) {
125125
struct s2n_blob in = {.data = random_data,.size = i };
126126
int bytes_written;

tests/unit/s2n_cbc_verify_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,21 @@ int main(int argc, char **argv)
115115
{
116116
struct s2n_connection *conn;
117117
uint8_t mac_key[] = "sample mac key";
118-
uint8_t fragment[S2N_MAXIMUM_FRAGMENT_LENGTH];
119-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH];
118+
uint8_t fragment[S2N_DEFAULT_FRAGMENT_LENGTH];
119+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH];
120120
struct s2n_hmac_state check_mac, record_mac;
121121

122122
BEGIN_TEST();
123123

124124
EXPECT_SUCCESS(s2n_init());
125125
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
126-
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_MAXIMUM_FRAGMENT_LENGTH));
126+
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_DEFAULT_FRAGMENT_LENGTH));
127127

128128
/* Emulate TLS1.2 */
129129
conn->actual_protocol_version = S2N_TLS12;
130130

131131
/* Try every 16 bytes to simulate block alignments */
132-
for (int i = 288; i < S2N_MAXIMUM_FRAGMENT_LENGTH; i += 16) {
132+
for (int i = 288; i < S2N_DEFAULT_FRAGMENT_LENGTH; i += 16) {
133133

134134
EXPECT_SUCCESS(s2n_hmac_init(&record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
135135

tests/unit/s2n_rc4_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ int main(int argc, char **argv)
3636
uint8_t mac_key[] = "sample mac key";
3737
uint8_t rc4_key[] = "123456789012345";
3838
struct s2n_blob key_iv = {.data = rc4_key,.size = sizeof(rc4_key) };
39-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH + 1];
39+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH + 1];
4040

4141
BEGIN_TEST();
4242

4343
EXPECT_SUCCESS(s2n_init());
4444
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
45-
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_MAXIMUM_FRAGMENT_LENGTH + 1));
45+
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_DEFAULT_FRAGMENT_LENGTH + 1));
4646

4747
/* Peer and we are in sync */
4848
conn->server = &conn->active;
@@ -56,17 +56,17 @@ int main(int argc, char **argv)
5656
EXPECT_SUCCESS(s2n_hmac_init(&conn->active.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
5757
conn->actual_protocol_version = S2N_TLS11;
5858

59-
for (int i = 0; i <= S2N_MAXIMUM_FRAGMENT_LENGTH + 1; i++) {
59+
for (int i = 0; i <= S2N_DEFAULT_FRAGMENT_LENGTH + 1; i++) {
6060
struct s2n_blob in = {.data = random_data,.size = i };
6161
int bytes_written;
6262

6363
EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out));
6464
EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &in));
6565

66-
if (i <= S2N_MAXIMUM_FRAGMENT_LENGTH - 20) {
66+
if (i <= S2N_DEFAULT_FRAGMENT_LENGTH - 20) {
6767
EXPECT_EQUAL(bytes_written, i);
6868
} else {
69-
EXPECT_EQUAL(bytes_written, S2N_MAXIMUM_FRAGMENT_LENGTH - 20);
69+
EXPECT_EQUAL(bytes_written, S2N_DEFAULT_FRAGMENT_LENGTH - 20);
7070
}
7171

7272
uint16_t predicted_length = bytes_written + 20;

tests/unit/s2n_record_test.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ int main(int argc, char **argv)
6363
uint8_t mac_key[] = "sample mac key";
6464
struct s2n_blob fixed_iv = {.data = mac_key,.size = sizeof(mac_key) };
6565
struct s2n_hmac_state check_mac;
66-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH + 1];
66+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH + 1];
6767

6868
BEGIN_TEST();
6969

7070
EXPECT_SUCCESS(s2n_init());
7171
EXPECT_SUCCESS(s2n_hmac_init(&check_mac, S2N_HMAC_SHA1, fixed_iv.data, fixed_iv.size));
72-
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_MAXIMUM_FRAGMENT_LENGTH + 1));
72+
EXPECT_SUCCESS(s2n_get_random_data(random_data, S2N_DEFAULT_FRAGMENT_LENGTH + 1));
7373
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
7474

7575
/* Peer and we are in sync */
@@ -79,17 +79,17 @@ int main(int argc, char **argv)
7979
conn->active.cipher_suite = &s2n_null_cipher_suite;
8080
conn->actual_protocol_version = S2N_TLS11;
8181

82-
for (int i = 0; i <= S2N_MAXIMUM_FRAGMENT_LENGTH + 1; i++) {
82+
for (int i = 0; i <= S2N_DEFAULT_FRAGMENT_LENGTH + 1; i++) {
8383
struct s2n_blob in = {.data = random_data,.size = i };
8484
int bytes_written;
8585

8686
EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out));
8787
EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &in));
8888

89-
if (i < S2N_MAXIMUM_FRAGMENT_LENGTH) {
89+
if (i < S2N_DEFAULT_FRAGMENT_LENGTH) {
9090
EXPECT_EQUAL(bytes_written, i);
9191
} else {
92-
EXPECT_EQUAL(bytes_written, S2N_MAXIMUM_FRAGMENT_LENGTH);
92+
EXPECT_EQUAL(bytes_written, S2N_DEFAULT_FRAGMENT_LENGTH);
9393
}
9494

9595
EXPECT_EQUAL(conn->out.blob.data[0], TLS_APPLICATION_DATA);
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
119119
conn->active.cipher_suite = &s2n_null_cipher_suite;
120120
conn->actual_protocol_version = S2N_TLS11;
121121

122-
for (int i = 0; i <= S2N_MAXIMUM_FRAGMENT_LENGTH + 1; i++) {
122+
for (int i = 0; i <= S2N_DEFAULT_FRAGMENT_LENGTH + 1; i++) {
123123
struct s2n_blob in = {.data = random_data,.size = i };
124124
int bytes_written;
125125

@@ -129,10 +129,10 @@ int main(int argc, char **argv)
129129
EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out));
130130
EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &in));
131131

132-
if (i < S2N_MAXIMUM_FRAGMENT_LENGTH - 20) {
132+
if (i < S2N_DEFAULT_FRAGMENT_LENGTH - 20) {
133133
EXPECT_EQUAL(bytes_written, i);
134134
} else {
135-
EXPECT_EQUAL(bytes_written, S2N_MAXIMUM_FRAGMENT_LENGTH - 20);
135+
EXPECT_EQUAL(bytes_written, S2N_DEFAULT_FRAGMENT_LENGTH - 20);
136136
}
137137

138138
uint16_t predicted_length = bytes_written + 20;
@@ -200,7 +200,7 @@ int main(int argc, char **argv)
200200
conn->actual_protocol_version = S2N_TLS10;
201201
conn->active.cipher_suite = &mock_block_cipher_suite;
202202

203-
uint16_t max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 16);
203+
uint16_t max_aligned_fragment = S2N_DEFAULT_FRAGMENT_LENGTH - (S2N_DEFAULT_FRAGMENT_LENGTH % 16);
204204
for (int i = 0; i <= max_aligned_fragment + 1; i++) {
205205
struct s2n_blob in = {.data = random_data,.size = i };
206206
int bytes_written;
@@ -268,7 +268,7 @@ int main(int argc, char **argv)
268268
conn->actual_protocol_version = S2N_TLS11;
269269
conn->active.cipher_suite = &mock_block_cipher_suite;
270270

271-
max_aligned_fragment = S2N_MAXIMUM_FRAGMENT_LENGTH - (S2N_MAXIMUM_FRAGMENT_LENGTH % 16);
271+
max_aligned_fragment = S2N_DEFAULT_FRAGMENT_LENGTH - (S2N_DEFAULT_FRAGMENT_LENGTH % 16);
272272
for (int i = 0; i <= max_aligned_fragment + 1; i++) {
273273
struct s2n_blob in = {.data = random_data,.size = i };
274274
int bytes_written;

tls/s2n_connection.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct s2n_connection *s2n_connection_new(s2n_mode mode)
8080
blob.size = S2N_ALERT_LENGTH;
8181

8282
GUARD_PTR(s2n_stuffer_init(&conn->writer_alert_out, &blob));
83-
GUARD_PTR(s2n_stuffer_alloc(&conn->out, S2N_MAXIMUM_RECORD_LENGTH));
83+
GUARD_PTR(s2n_stuffer_alloc(&conn->out, S2N_DEFAULT_RECORD_LENGTH));
8484

8585
/* Initialize the growable stuffers. Zero length at first, but the resize
8686
* in _wipe will fix that
@@ -180,10 +180,10 @@ int s2n_connection_wipe(struct s2n_connection *conn)
180180
GUARD(s2n_stuffer_wipe(&conn->out));
181181

182182
/* Allocate or resize to their original sizes */
183-
GUARD(s2n_stuffer_resize(&conn->in, S2N_MAXIMUM_FRAGMENT_LENGTH));
183+
GUARD(s2n_stuffer_resize(&conn->in, S2N_DEFAULT_FRAGMENT_LENGTH));
184184

185185
/* Allocate memory for handling handshakes */
186-
GUARD(s2n_stuffer_resize(&conn->handshake.io, S2N_MAXIMUM_RECORD_LENGTH));
186+
GUARD(s2n_stuffer_resize(&conn->handshake.io, S2N_DEFAULT_RECORD_LENGTH));
187187

188188
/* Clone the stuffers */
189189
/* ignore gcc 4.7 address warnings because dest is allocated on the stack */
@@ -207,7 +207,7 @@ int s2n_connection_wipe(struct s2n_connection *conn)
207207
conn->pending.cipher_suite = &s2n_null_cipher_suite;
208208
conn->server = &conn->active;
209209
conn->client = &conn->active;
210-
conn->max_fragment_length = S2N_MAXIMUM_FRAGMENT_LENGTH;
210+
conn->max_fragment_length = S2N_DEFAULT_FRAGMENT_LENGTH;
211211
conn->handshake.state = CLIENT_HELLO;
212212
GUARD(s2n_hash_init(&conn->handshake.client_md5, S2N_HASH_MD5));
213213
GUARD(s2n_hash_init(&conn->handshake.client_sha1, S2N_HASH_SHA1));

tls/s2n_tls_parameters.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969

7070
/* s2n uses a record length that is aligned to the dominant internet MTU;
7171
* 1500 bytes, minus 20 bytes for an IP header, minus 20 bytes for a tcp
72-
* header */
73-
#define S2N_MAXIMUM_RECORD_LENGTH (1500 - 20 - 20)
74-
#define S2N_MAXIMUM_FRAGMENT_LENGTH (S2N_MAXIMUM_RECORD_LENGTH - S2N_TLS_RECORD_HEADER_LENGTH)
72+
* header and 20 bytes for tcp options (timestamp, sack etc) */
73+
#define S2N_DEFAULT_RECORD_LENGTH (1500 - 20 - 20 - 20)
74+
#define S2N_DEFAULT_FRAGMENT_LENGTH (S2N_DEFAULT_RECORD_LENGTH - S2N_TLS_RECORD_HEADER_LENGTH)
7575

7676
/* Put a 64k cap on the size of any handshake message */
7777
#define S2N_MAXIMUM_HANDSHAKE_MESSAGE_LENGTH (64 * 1024)

0 commit comments

Comments
 (0)