1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00

Test crypto_box[_open]_easy_afternm() with short and overflowing lengths

This commit is contained in:
Frank Denis 2015-01-15 14:37:26 +01:00
parent 9b85fddfa9
commit 9a386d0a6d

View File

@ -63,12 +63,19 @@ int main(void)
crypto_box_beforenm(k2, bobpk, alicesk);
memset(m2, 0, sizeof m2);
if (crypto_box_easy_afternm(c, m, SIZE_MAX - 1U, nonce, k1) == 0) {
printf("crypto_box_easy_afternm() with a short ciphertext should have failed\n");
}
crypto_box_easy_afternm(c, m, (unsigned long long) mlen, nonce, k1);
crypto_box_open_easy_afternm(m2, c,
(unsigned long long) mlen + crypto_box_MACBYTES,
nonce, k2);
printf("%d\n", memcmp(m, m2, mlen));
if (crypto_box_open_easy_afternm(m2, c, crypto_box_MACBYTES - 1U,
nonce, k2) == 0) {
printf("crypto_box_open_easy_afternm() with a huge ciphertext should have failed\n");
}
memset(m2, 0, sizeof m2);
crypto_box_detached(c, mac, m, (unsigned long long) mlen,
nonce, alicepk, bobsk);