libsodium-1.0.19-stable.tar.gz

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4490 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-10-05 00:32:37 +00:00
parent d1e494b730
commit 424b9b5a2f
175 changed files with 10484 additions and 4227 deletions

View File

@ -3098,6 +3098,7 @@ tv(void)
size_t detached_ciphertext_len;
size_t i = 0U;
size_t message_len;
int res;
key = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_KEYBYTES);
nonce = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_NPUBBYTES);
@ -3136,34 +3137,48 @@ tv(void)
ciphertext = (unsigned char *) sodium_malloc(ciphertext_len);
detached_ciphertext = (unsigned char *) sodium_malloc(detached_ciphertext_len);
crypto_aead_aes256gcm_encrypt_detached(detached_ciphertext, mac,
&found_mac_len,
message, message_len,
ad, ad_len, NULL, nonce, key);
res = crypto_aead_aes256gcm_encrypt_detached(detached_ciphertext, mac,
&found_mac_len,
message, message_len,
ad, ad_len, NULL, nonce, key);
assert(found_mac_len == crypto_aead_aes256gcm_ABYTES);
if (memcmp(detached_ciphertext, expected_ciphertext,
detached_ciphertext_len) != 0 ||
memcmp(mac, expected_ciphertext + message_len,
crypto_aead_aes256gcm_ABYTES) != 0) {
printf("Detached encryption of test vector #%u failed\n", (unsigned int) i);
printf("Detached encryption of test vector #%u failed (res=%d)\n",
(unsigned int) i, res);
hex = (char *) sodium_malloc((size_t) ciphertext_len * 2 + 1);
sodium_bin2hex(hex, (size_t) ciphertext_len * 2 + 1,
ciphertext, ciphertext_len);
sodium_bin2hex(hex, (size_t) detached_ciphertext_len * 2 + 1,
detached_ciphertext, detached_ciphertext_len);
printf("Computed: [%s]\n", hex);
sodium_bin2hex(hex, (size_t) detached_ciphertext_len * 2 + 1,
expected_ciphertext, detached_ciphertext_len);
printf("Expected: [%s]\n", hex);
sodium_bin2hex(hex, (size_t) found_mac_len * 2 + 1,
mac, found_mac_len);
printf("Computed mac: [%s]\n", hex);
sodium_bin2hex(hex, (size_t) found_mac_len * 2 + 1,
expected_ciphertext + message_len, found_mac_len);
printf("Expected mac: [%s]\n", hex);
sodium_free(hex);
}
crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len,
message, message_len,
ad, ad_len, NULL, nonce, key);
res = crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len,
message, message_len,
ad, ad_len, NULL, nonce, key);
assert((size_t) found_ciphertext_len == ciphertext_len);
if (memcmp(ciphertext, expected_ciphertext, ciphertext_len) != 0) {
printf("Encryption of test vector #%u failed\n", (unsigned int) i);
printf("Encryption of test vector #%u failed (res=%d)\n",
(unsigned int) i, res);
hex = (char *) sodium_malloc((size_t) found_ciphertext_len * 2 + 1);
sodium_bin2hex(hex, (size_t) found_ciphertext_len * 2 + 1,
ciphertext, ciphertext_len);
printf("Computed: [%s]\n", hex);
sodium_bin2hex(hex, (size_t) ciphertext_len * 2 + 1,
expected_ciphertext, ciphertext_len);
printf("Expected: [%s]\n", hex);
sodium_free(hex);
}