Skip to content

Commit d656092

Browse files
committed
Adds new monotonicity check
1 parent daa4251 commit d656092

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

BUILDING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If in doubt, use the most recent stable version of each build tool.
2020
`PERL_EXECUTABLE`.
2121
* To build without Perl (not recommended) see [this section.](#using-pre-generated-build-files)
2222

23-
* [Go](https://golang.org/dl/) 1.18 or later is required. If not found by
23+
* [Go](https://golang.org/dl/) 1.20 or later is required. If not found by
2424
CMake, the go executable may be configured explicitly by setting
2525
`GO_EXECUTABLE`.
2626
* To build without Go (not recommended) see [this section.](#using-pre-generated-build-files)

crypto/cipher_extra/aead_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,48 @@ TEST(AEADTest, TestGCMSIV256Change16Alignment) {
13641364
free(encrypt_ctx_256);
13651365
}
13661366

1367+
TEST(AEADTest, TestMonotonicityCheck) {
1368+
1369+
static const uint8_t kEvpAeadCtxKey[32] = {0};
1370+
1371+
// Only the tls13() ciphers have monotonicity checks
1372+
struct {
1373+
const EVP_AEAD *cipher;
1374+
const size_t key_len;
1375+
} ctx[] = { { .cipher = EVP_aead_aes_128_gcm_tls13(), .key_len = 16},
1376+
{ .cipher = EVP_aead_aes_256_gcm_tls13(), .key_len = 32} };
1377+
1378+
for (int i = 0; i < 2; i++) {
1379+
const EVP_AEAD *cipher = ctx[i].cipher;
1380+
EVP_AEAD_CTX *encrypt_ctx =
1381+
(EVP_AEAD_CTX *)malloc(sizeof(EVP_AEAD_CTX) + 8);
1382+
ASSERT_TRUE(encrypt_ctx);
1383+
1384+
EVP_AEAD_CTX_zero(encrypt_ctx);
1385+
ASSERT_TRUE(EVP_AEAD_CTX_init(encrypt_ctx, cipher, kEvpAeadCtxKey, ctx[i].key_len, 16, NULL))
1386+
<< ERR_error_string(ERR_get_error(), NULL);
1387+
1388+
uint8_t nonce[12] = {0};
1389+
uint8_t last_byte = sizeof(nonce) - 1;
1390+
uint8_t plaintext[16] = {0};
1391+
uint8_t ciphertext[32] = {0};
1392+
size_t out_len = 0;
1393+
1394+
// Checks that sequence numbers are allowed to increment by more than one
1395+
// as long as monotonicity is preserved. Here the implicit IV is presumed
1396+
// to be a zero-filled array. That lets us update the nonce value directly
1397+
// with an increasing sequence number.
1398+
for (size_t sequence_num = 0; sequence_num <= 255; sequence_num+=10) {
1399+
nonce[last_byte] = sequence_num;
1400+
ASSERT_TRUE(EVP_AEAD_CTX_seal(encrypt_ctx, ciphertext, &out_len,
1401+
sizeof(ciphertext), nonce, sizeof(nonce), plaintext,
1402+
sizeof(plaintext), nullptr /* ad */, 0));
1403+
}
1404+
1405+
free(encrypt_ctx);
1406+
}
1407+
}
1408+
13671409
struct EvpAeadCtxSerdeTestParams {
13681410
const char *name;
13691411
const EVP_AEAD *cipher;

0 commit comments

Comments
 (0)