1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-23 20:15:19 -07:00

More tests

This commit is contained in:
Frank Denis 2019-05-06 11:40:57 +02:00
parent ffdaf6d16b
commit 06e4a485c4
5 changed files with 65 additions and 7 deletions

View File

@ -127,7 +127,7 @@ crypto_core_salsa20_constbytes(void)
} }
#ifndef MINIMAL #ifndef MINIMAL
/* LCOV_EXCL_START */
int int
crypto_core_salsa2012(unsigned char *out, const unsigned char *in, crypto_core_salsa2012(unsigned char *out, const unsigned char *in,
const unsigned char *k, const unsigned char *c) const unsigned char *k, const unsigned char *c)
@ -191,5 +191,5 @@ crypto_core_salsa208_constbytes(void)
{ {
return crypto_core_salsa208_CONSTBYTES; return crypto_core_salsa208_CONSTBYTES;
} }
/* LCOV_EXCL_END */
#endif #endif

View File

@ -113,9 +113,11 @@ allocate_memory(block_region **region, uint32_t m_cost)
} }
#endif #endif
if (base == NULL) { if (base == NULL) {
/* LCOV_EXCL_START */
free(*region); free(*region);
*region = NULL; *region = NULL;
return ARGON2_MEMORY_ALLOCATION_ERROR; /* LCOV_EXCL_LINE */ return ARGON2_MEMORY_ALLOCATION_ERROR;
/* LCOV_EXCL_STOP */
} }
(*region)->base = base; (*region)->base = base;
(*region)->memory = memory; (*region)->memory = memory;

View File

@ -203,11 +203,13 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
unsigned int cpu_info7[4]; unsigned int cpu_info7[4];
_cpuid(cpu_info7, 0x00000007); _cpuid(cpu_info7, 0x00000007);
/* LCOV_EXCL_START */
if ((cpu_info7[1] & CPUID_EBX_AVX512F) == CPUID_EBX_AVX512F && if ((cpu_info7[1] & CPUID_EBX_AVX512F) == CPUID_EBX_AVX512F &&
(xcr0 & (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM)) (xcr0 & (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM))
== (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM)) { == (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM)) {
cpu_features->has_avx512f = 1; cpu_features->has_avx512f = 1;
} }
/* LCOV_EXCL_STOP */
} }
#endif #endif

View File

@ -2,8 +2,8 @@
#define TEST_NAME "box_seal" #define TEST_NAME "box_seal"
#include "cmptest.h" #include "cmptest.h"
int static
main(void) void tv1(void)
{ {
unsigned char pk[crypto_box_PUBLICKEYBYTES]; unsigned char pk[crypto_box_PUBLICKEYBYTES];
unsigned char sk[crypto_box_SECRETKEYBYTES]; unsigned char sk[crypto_box_SECRETKEYBYTES];
@ -22,11 +22,11 @@ main(void)
randombytes_buf(m, m_len); randombytes_buf(m, m_len);
if (crypto_box_seal(c, m, m_len, pk) != 0) { if (crypto_box_seal(c, m, m_len, pk) != 0) {
printf("crypto_box_seal() failure\n"); printf("crypto_box_seal() failure\n");
return 1; return;
} }
if (crypto_box_seal_open(m2, c, c_len, pk, sk) != 0) { if (crypto_box_seal_open(m2, c, c_len, pk, sk) != 0) {
printf("crypto_box_seal_open() failure\n"); printf("crypto_box_seal_open() failure\n");
return 1; return;
} }
printf("%d\n", memcmp(m, m2, m_len)); printf("%d\n", memcmp(m, m2, m_len));
@ -39,6 +39,56 @@ main(void)
sodium_free(m2); sodium_free(m2);
assert(crypto_box_sealbytes() == crypto_box_SEALBYTES); assert(crypto_box_sealbytes() == crypto_box_SEALBYTES);
}
#ifndef SODIUM_LIBRARY_MINIMAL
static
void tv2(void)
{
unsigned char pk[crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES];
unsigned char sk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES];
unsigned char *c;
unsigned char *m;
unsigned char *m2;
size_t m_len;
size_t c_len;
crypto_box_curve25519xchacha20poly1305_keypair(pk, sk);
m_len = (size_t) randombytes_uniform(1000);
c_len = crypto_box_curve25519xchacha20poly1305_SEALBYTES + m_len;
m = (unsigned char *) sodium_malloc(m_len);
m2 = (unsigned char *) sodium_malloc(m_len);
c = (unsigned char *) sodium_malloc(c_len);
randombytes_buf(m, m_len);
if (crypto_box_curve25519xchacha20poly1305_seal(c, m, m_len, pk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal() failure\n");
return;
}
if (crypto_box_curve25519xchacha20poly1305_seal_open(m2, c, c_len, pk, sk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal_open() failure\n");
return;
}
printf("%d\n", memcmp(m, m2, m_len));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, 0U, pk, sk));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, c_len - 1U, pk, sk));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, c_len, sk, pk));
sodium_free(c);
sodium_free(m);
sodium_free(m2);
assert(crypto_box_curve25519xchacha20poly1305_sealbytes() ==
crypto_box_curve25519xchacha20poly1305_SEALBYTES);
}
#endif
int
main(void)
{
tv1();
#ifndef SODIUM_LIBRARY_MINIMAL
tv2();
#endif
return 0; return 0;
} }

View File

@ -2,3 +2,7 @@
-1 -1
-1 -1
-1 -1
0
-1
-1
-1