Skip to content

Commit 4bbce8d

Browse files
committed
Merge pull request #58 from baldwinmatt/master
Fix s2n_aead_aes_test.c after commit acb6666
2 parents acb6666 + e721bb6 commit 4bbce8d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tests/unit/s2n_aead_aes_test.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
int main(int argc, char **argv)
3434
{
3535
struct s2n_connection *conn;
36-
uint8_t random_data[S2N_MAXIMUM_FRAGMENT_LENGTH + 1];
36+
uint8_t random_data[S2N_DEFAULT_FRAGMENT_LENGTH + 1];
3737
uint8_t mac_key[] = "sample mac key";
3838
uint8_t aes128_key[] = "123456789012345";
3939
uint8_t aes256_key[] = "1234567890123456789012345678901";
@@ -59,18 +59,21 @@ 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_TLS12;
6161

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++) {
6464
struct s2n_blob in = {.data = random_data,.size = i };
6565
int bytes_written;
6666

6767
EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out));
6868
EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &in));
6969

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) {
7174
EXPECT_EQUAL(bytes_written, i);
7275
} else {
73-
EXPECT_EQUAL(bytes_written, max_aligned_fragment - 20 - 8 - 1);
76+
EXPECT_EQUAL(bytes_written, max_fragment - overhead);
7477
}
7578

7679
uint16_t predicted_length = bytes_written + 20;
@@ -187,18 +190,20 @@ int main(int argc, char **argv)
187190
EXPECT_SUCCESS(s2n_hmac_init(&conn->active.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key)));
188191
conn->actual_protocol_version = S2N_TLS12;
189192

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++) {
192194
struct s2n_blob in = {.data = random_data,.size = i };
193195
int bytes_written;
194196

195197
EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out));
196198
EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &in));
197199

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) {
199204
EXPECT_EQUAL(bytes_written, i);
200205
} else {
201-
EXPECT_EQUAL(bytes_written, max_aligned_fragment - 20 - 8 - 1);
206+
EXPECT_EQUAL(bytes_written, max_fragment - overhead);
202207
}
203208

204209
uint16_t predicted_length = bytes_written + 20;

0 commit comments

Comments
 (0)