Add tests for short messages with (secret)box_easy
This commit is contained in:
parent
931ce38f61
commit
ad7b1c58a8
@ -16,6 +16,7 @@ unsigned char bobsk[crypto_box_SECRETKEYBYTES];
|
||||
int main(void)
|
||||
{
|
||||
unsigned long long mlen;
|
||||
unsigned long long i;
|
||||
|
||||
crypto_box_keypair(alicepk, alicesk);
|
||||
crypto_box_keypair(bobpk, bobsk);
|
||||
@ -23,9 +24,18 @@ int main(void)
|
||||
randombytes_buf(m, mlen);
|
||||
randombytes_buf(nonce, sizeof nonce);
|
||||
crypto_box_easy(c, m, mlen, nonce, bobpk, alicesk);
|
||||
crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES,
|
||||
nonce, alicepk, bobsk);
|
||||
if (crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES,
|
||||
nonce, alicepk, bobsk) != 0) {
|
||||
printf("open() failed");
|
||||
return 1;
|
||||
}
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
|
||||
for (i = 0; i < mlen + crypto_box_MACBYTES - 1; i++) {
|
||||
if (crypto_box_open_easy(m2, c, i, nonce, alicepk, bobsk) == 0) {
|
||||
printf("short open() should have failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ unsigned char mac[crypto_secretbox_MACBYTES];
|
||||
int main(void)
|
||||
{
|
||||
unsigned long long mlen;
|
||||
unsigned long long i;
|
||||
|
||||
randombytes_buf(k, sizeof k);
|
||||
mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
|
||||
@ -24,6 +25,12 @@ int main(void)
|
||||
nonce, k);
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
|
||||
for (i = 0; i < mlen + crypto_secretbox_MACBYTES - 1; i++) {
|
||||
if (crypto_secretbox_open_easy(m2, c, i, nonce, k) == 0) {
|
||||
printf("short open() should have failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
crypto_secretbox_detached(c, mac, m, mlen, nonce, k);
|
||||
crypto_secretbox_open_detached(m2, c, mac, mlen, nonce, k);
|
||||
printf("%d\n", memcmp(m, m2, mlen));
|
||||
|
Loading…
Reference in New Issue
Block a user