mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-28 22:21:15 -07:00
Test crypto_box[_open]_easy_afternm() with short and overflowing lengths
This commit is contained in:
parent
9b85fddfa9
commit
9a386d0a6d
@ -63,12 +63,19 @@ int main(void)
|
|||||||
crypto_box_beforenm(k2, bobpk, alicesk);
|
crypto_box_beforenm(k2, bobpk, alicesk);
|
||||||
|
|
||||||
memset(m2, 0, sizeof m2);
|
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_easy_afternm(c, m, (unsigned long long) mlen, nonce, k1);
|
||||||
crypto_box_open_easy_afternm(m2, c,
|
crypto_box_open_easy_afternm(m2, c,
|
||||||
(unsigned long long) mlen + crypto_box_MACBYTES,
|
(unsigned long long) mlen + crypto_box_MACBYTES,
|
||||||
nonce, k2);
|
nonce, k2);
|
||||||
printf("%d\n", memcmp(m, m2, mlen));
|
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);
|
memset(m2, 0, sizeof m2);
|
||||||
crypto_box_detached(c, mac, m, (unsigned long long) mlen,
|
crypto_box_detached(c, mac, m, (unsigned long long) mlen,
|
||||||
nonce, alicepk, bobsk);
|
nonce, alicepk, bobsk);
|
||||||
|
Loading…
Reference in New Issue
Block a user