mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-28 20:57:13 +09:00
Add a test for chacha20poly1305 with overlapping pointers
This commit is contained in:
@@ -95,6 +95,31 @@ int main(void)
|
||||
"ciphertext\n");
|
||||
}
|
||||
|
||||
memcpy(c, m, sizeof m);
|
||||
crypto_aead_chacha20poly1305_encrypt(c, &clen, c, sizeof m, NULL, 0U, NULL,
|
||||
nonce, firstkey);
|
||||
if (clen != sizeof m + crypto_aead_chacha20poly1305_abytes()) {
|
||||
printf("clen is not properly set (adlen=0)\n");
|
||||
}
|
||||
for (i = 0U; i < sizeof c; ++i) {
|
||||
printf(",0x%02x", (unsigned int)c[i]);
|
||||
if (i % 8 == 7) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c, sizeof c,
|
||||
NULL, 0U, nonce, firstkey) != 0) {
|
||||
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
|
||||
}
|
||||
if (m2len != sizeof c - crypto_aead_chacha20poly1305_abytes()) {
|
||||
printf("m2len is not properly set (adlen=0)\n");
|
||||
}
|
||||
if (memcmp(m, c, sizeof m) != 0) {
|
||||
printf("m != c (adlen=0)\n");
|
||||
}
|
||||
|
||||
assert(crypto_aead_chacha20poly1305_keybytes() > 0U);
|
||||
assert(crypto_aead_chacha20poly1305_npubbytes() > 0U);
|
||||
assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U);
|
||||
|
||||
@@ -6,3 +6,7 @@
|
||||
,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95
|
||||
,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31
|
||||
,0x61,0xdc
|
||||
,0xe3,0xe4,0x46,0xf7,0xed,0xe9,0xa1,0x9b
|
||||
,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95
|
||||
,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31
|
||||
,0x61,0xdc
|
||||
|
||||
Reference in New Issue
Block a user