mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 10:05:05 -07:00
More tests
This commit is contained in:
parent
ffdaf6d16b
commit
06e4a485c4
@ -127,7 +127,7 @@ crypto_core_salsa20_constbytes(void)
|
||||
}
|
||||
|
||||
#ifndef MINIMAL
|
||||
|
||||
/* LCOV_EXCL_START */
|
||||
int
|
||||
crypto_core_salsa2012(unsigned char *out, const unsigned char *in,
|
||||
const unsigned char *k, const unsigned char *c)
|
||||
@ -191,5 +191,5 @@ crypto_core_salsa208_constbytes(void)
|
||||
{
|
||||
return crypto_core_salsa208_CONSTBYTES;
|
||||
}
|
||||
|
||||
/* LCOV_EXCL_END */
|
||||
#endif
|
||||
|
@ -113,9 +113,11 @@ allocate_memory(block_region **region, uint32_t m_cost)
|
||||
}
|
||||
#endif
|
||||
if (base == NULL) {
|
||||
/* LCOV_EXCL_START */
|
||||
free(*region);
|
||||
*region = NULL;
|
||||
return ARGON2_MEMORY_ALLOCATION_ERROR; /* LCOV_EXCL_LINE */
|
||||
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
(*region)->base = base;
|
||||
(*region)->memory = memory;
|
||||
|
@ -203,11 +203,13 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
|
||||
unsigned int cpu_info7[4];
|
||||
|
||||
_cpuid(cpu_info7, 0x00000007);
|
||||
/* LCOV_EXCL_START */
|
||||
if ((cpu_info7[1] & CPUID_EBX_AVX512F) == CPUID_EBX_AVX512F &&
|
||||
(xcr0 & (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM))
|
||||
== (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM)) {
|
||||
cpu_features->has_avx512f = 1;
|
||||
}
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define TEST_NAME "box_seal"
|
||||
#include "cmptest.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
static
|
||||
void tv1(void)
|
||||
{
|
||||
unsigned char pk[crypto_box_PUBLICKEYBYTES];
|
||||
unsigned char sk[crypto_box_SECRETKEYBYTES];
|
||||
@ -22,11 +22,11 @@ main(void)
|
||||
randombytes_buf(m, m_len);
|
||||
if (crypto_box_seal(c, m, m_len, pk) != 0) {
|
||||
printf("crypto_box_seal() failure\n");
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
if (crypto_box_seal_open(m2, c, c_len, pk, sk) != 0) {
|
||||
printf("crypto_box_seal_open() failure\n");
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
printf("%d\n", memcmp(m, m2, m_len));
|
||||
|
||||
@ -39,6 +39,56 @@ main(void)
|
||||
sodium_free(m2);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -2,3 +2,7 @@
|
||||
-1
|
||||
-1
|
||||
-1
|
||||
0
|
||||
-1
|
||||
-1
|
||||
-1
|
||||
|
Loading…
Reference in New Issue
Block a user