mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Remove mlen_p from the AEAD detached interface
This commit is contained in:
@@ -3167,6 +3167,7 @@ tv(void)
|
||||
}
|
||||
|
||||
decrypted = (unsigned char *) sodium_malloc(message_len);
|
||||
found_message_len = 1;
|
||||
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
||||
NULL, ciphertext,
|
||||
randombytes_uniform(ciphertext_len),
|
||||
@@ -3174,6 +3175,9 @@ tv(void)
|
||||
printf("Verification of test vector #%u after truncation succeeded\n",
|
||||
(unsigned int) i);
|
||||
}
|
||||
if (found_message_len != 0) {
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
||||
NULL, ciphertext,
|
||||
randombytes_uniform(crypto_aead_aes256gcm_ABYTES),
|
||||
@@ -3190,15 +3194,13 @@ tv(void)
|
||||
if (memcmp(decrypted, message, message_len) != 0) {
|
||||
printf("Incorrect decryption of test vector #%u\n", (unsigned int) i);
|
||||
}
|
||||
|
||||
memset(decrypted, 0xd0, message_len);
|
||||
if (crypto_aead_aes256gcm_decrypt_detached(decrypted, &found_message_len,
|
||||
if (crypto_aead_aes256gcm_decrypt_detached(decrypted,
|
||||
NULL, detached_ciphertext,
|
||||
detached_ciphertext_len,
|
||||
mac, ad, ad_len, nonce, key) != 0) {
|
||||
printf("Detached verification of test vector #%u failed\n", (unsigned int) i);
|
||||
}
|
||||
assert((size_t) found_message_len == message_len);
|
||||
if (memcmp(decrypted, message, message_len) != 0) {
|
||||
printf("Incorrect decryption of test vector #%u\n", (unsigned int) i);
|
||||
}
|
||||
|
||||
@@ -66,15 +66,12 @@ tv(void)
|
||||
printf("m != m2\n");
|
||||
}
|
||||
memset(m2, 0, m2len);
|
||||
if (crypto_aead_chacha20poly1305_decrypt_detached(m2, &m2len, NULL,
|
||||
if (crypto_aead_chacha20poly1305_decrypt_detached(m2, NULL,
|
||||
c, MLEN, mac,
|
||||
ad, ADLEN,
|
||||
nonce, firstkey) != 0) {
|
||||
printf("crypto_aead_chacha20poly1305_decrypt_detached() failed\n");
|
||||
}
|
||||
if (m2len != MLEN) {
|
||||
printf("detached m2len is not properly set\n");
|
||||
}
|
||||
if (memcmp(m, m2, MLEN) != 0) {
|
||||
printf("detached m != m2\n");
|
||||
}
|
||||
@@ -112,18 +109,25 @@ tv(void)
|
||||
if (memcmp(m, m2, MLEN) != 0) {
|
||||
printf("m != m2 (adlen=0)\n");
|
||||
}
|
||||
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_decrypt(
|
||||
m2, &m2len, NULL, c, crypto_aead_chacha20poly1305_ABYTES / 2, NULL,
|
||||
0U, nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
|
||||
"ciphertext\n");
|
||||
}
|
||||
if (m2len != 0) {
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
|
||||
nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_decrypt() worked with an empty "
|
||||
"ciphertext\n");
|
||||
}
|
||||
if (m2len != 0) {
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
|
||||
memcpy(c, m, MLEN);
|
||||
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, c, MLEN,
|
||||
@@ -234,15 +238,12 @@ tv_ietf(void)
|
||||
printf("m != m2\n");
|
||||
}
|
||||
memset(m2, 0, m2len);
|
||||
if (crypto_aead_chacha20poly1305_ietf_decrypt_detached(m2, &m2len, NULL,
|
||||
if (crypto_aead_chacha20poly1305_ietf_decrypt_detached(m2, NULL,
|
||||
c, MLEN, mac,
|
||||
ad, ADLEN,
|
||||
nonce, firstkey) != 0) {
|
||||
printf("crypto_aead_chacha20poly1305_ietf_decrypt_detached() failed\n");
|
||||
}
|
||||
if (m2len != MLEN) {
|
||||
printf("detached m2len is not properly set\n");
|
||||
}
|
||||
if (memcmp(m, m2, MLEN) != 0) {
|
||||
printf("detached m != m2\n");
|
||||
}
|
||||
@@ -278,18 +279,25 @@ tv_ietf(void)
|
||||
if (memcmp(m, m2, MLEN) != 0) {
|
||||
printf("m != m2 (adlen=0)\n");
|
||||
}
|
||||
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_ietf_decrypt(
|
||||
m2, &m2len, NULL, c, crypto_aead_chacha20poly1305_ietf_ABYTES / 2, NULL,
|
||||
0U, nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with a short "
|
||||
"ciphertext\n");
|
||||
}
|
||||
if (m2len != 0) {
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
|
||||
nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with an empty "
|
||||
"ciphertext\n");
|
||||
}
|
||||
if (m2len != 0) {
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
|
||||
memcpy(c, m, MLEN);
|
||||
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, c, MLEN,
|
||||
|
||||
Reference in New Issue
Block a user