u64 nb_blocks = plain.size / 64 + (plain.size % 64 != 0);
u64 new_ctr = crypto_chacha20_ctr(out.buf, plain.buf, plain.size,
key.buf, nonce.buf, ctr);
- if (new_ctr - ctr != nb_blocks) {
- printf("FAILURE: Chacha20 returned counter not correct: ");
- exit(1);
- }
+ ASSERT(new_ctr - ctr == nb_blocks);
}
static void ietf_chacha20(vector_reader *reader)
u32 nb_blocks = (u32)(plain.size / 64 + (plain.size % 64 != 0));
u32 new_ctr = crypto_ietf_chacha20_ctr(out.buf, plain.buf, plain.size,
key.buf, nonce.buf, ctr);
- if (new_ctr - ctr != nb_blocks) {
- printf("FAILURE: IETF Chacha20 returned counter not correct: ");
- exit(1);
- }
+ ASSERT(new_ctr - ctr == nb_blocks);
}
static void xchacha20(vector_reader *reader)
u64 nb_blocks = plain.size / 64 + (plain.size % 64 != 0);
u64 new_ctr = crypto_xchacha20_ctr(out.buf, plain.buf, plain.size,
key.buf, nonce.buf, ctr);
- if (new_ctr - ctr != nb_blocks) {
- printf("FAILURE: XChacha20 returned counter not correct: ");
- exit(1);
- }
+ ASSERT(new_ctr - ctr == nb_blocks);
}
static void hchacha20(vector_reader *reader)
memcpy(out.buf, public_key, 32);
u8 zeroes[32] = {0};
- if (memcmp(seed, zeroes, 32)) {
- printf("FAILURE: seed has not been wiped\n");
- exit(1);
- }
- if (memcmp(secret_key, in.buf, 32)) {
- printf("FAILURE: first half of secret key is not the seed\n");
- exit(1);
- }
- if (memcmp(secret_key + 32, public_key, 32)) {
- printf("FAILURE: second half of secret key is not the public key\n");
- exit(1);
- }
+ ASSERT(memcmp(seed , zeroes , 32) == 0);
+ ASSERT(memcmp(secret_key , in.buf , 32) == 0);
+ ASSERT(memcmp(secret_key + 32, public_key, 32) == 0);
}
static void test_edDSA()
memcpy(out.buf, public_key, 32);
u8 zeroes[32] = {0};
- if (memcmp(seed, zeroes, 32)) {
- printf("FAILURE: seed has not been wiped\n");
- exit(1);
- }
- if (memcmp(secret_key, in.buf, 32)) {
- printf("FAILURE: first half of secret key is not the seed\n");
- exit(1);
- }
- if (memcmp(secret_key + 32, public_key, 32)) {
- printf("FAILURE: second half of secret key is not the public key\n");
- exit(1);
- }
+ ASSERT(memcmp(seed , zeroes , 32) == 0);
+ ASSERT(memcmp(secret_key , in.buf , 32) == 0);
+ ASSERT(memcmp(secret_key + 32, public_key, 32) == 0);
}
static void ed_25519_check(vector_reader *reader)
u8 failure = next_input(reader).buf[0];
vector out = next_output(reader);
int check = crypto_curve_to_hidden(out.buf, point.buf, tweak);
- if ((u8)check != failure) {
- printf("Elligator inverse map: failure mismatch\n");
- exit(1);
- }
+ ASSERT((u8)check == failure);
}
static void test_elligator()
u8 failure = next_input(reader).buf[0];
vector out = next_output(reader);
int check = crypto_curve_to_hidden(out.buf, point.buf, tweak);
- if ((u8)check != failure) {
- printf("Elligator inverse map: failure mismatch\n");
- exit(1);
- }
+ ASSERT((u8)check == failure);
if (check) {
out.buf[0] = 0;
}
//@ ensures \result == 0;
int main(void) {
- int status = 0;
- status |= v_chacha20 ();
- status |= v_ietf_chacha20 ();
- status |= v_hchacha20 ();
- status |= v_xchacha20 ();
- status |= v_poly1305 ();
- status |= v_aead_ietf ();
- status |= v_blake2b ();
- status |= v_sha512 ();
- status |= v_hmac_sha512 ();
- status |= v_argon2i ();
- status |= v_x25519 ();
- status |= v_edDSA ();
- status |= v_ed_25519 ();
- status |= v_ed_25519_check();
- status |= v_elligator_dir ();
- status |= v_elligator_inv ();
-
- status |= p_from_eddsa ();
- status |= p_from_ed25519 ();
- status |= p_dirty ();
- status |= p_x25519_inverse();
- status |= p_verify16 ();
- status |= p_verify32 ();
- status |= p_verify64 ();
- return status;
+ ASSERT(v_chacha20 () == 0);
+ ASSERT(v_ietf_chacha20 () == 0);
+ ASSERT(v_hchacha20 () == 0);
+ ASSERT(v_xchacha20 () == 0);
+ ASSERT(v_poly1305 () == 0);
+ ASSERT(v_aead_ietf () == 0);
+ ASSERT(v_blake2b () == 0);
+ ASSERT(v_sha512 () == 0);
+ ASSERT(v_hmac_sha512 () == 0);
+ ASSERT(v_argon2i () == 0);
+ ASSERT(v_x25519 () == 0);
+ ASSERT(v_edDSA () == 0);
+ ASSERT(v_ed_25519 () == 0);
+ ASSERT(v_ed_25519_check() == 0);
+ ASSERT(v_elligator_dir () == 0);
+ ASSERT(v_elligator_inv () == 0);
+
+ ASSERT(p_from_eddsa () == 0);
+ ASSERT(p_from_ed25519 () == 0);
+ ASSERT(p_dirty () == 0);
+ ASSERT(p_x25519_inverse() == 0);
+ ASSERT(p_verify16 () == 0);
+ ASSERT(p_verify32 () == 0);
+ ASSERT(p_verify64 () == 0);
+ return 0;
}
return NULL;
}
void *buf = malloc(size);
- if (buf == NULL) {
- fprintf(stderr, "Allocation failed: 0x%zx bytes\n", size);
- exit(1);
- }
+ ASSERT(buf != NULL);
return buf;
}
vector next_input(vector_reader *reader)
{
- if (reader->size == 0 || reader->nb_inputs >= 10) {
- fprintf(stderr, "Input reader overload (no more vectors)\n");
- exit(1);
- }
+ ASSERT(reader->size > 0);
+ ASSERT(reader->nb_inputs < 10);
+
const char *next = *(reader->next);
vector *input = reader->inputs + reader->nb_inputs;
reader->next++;
vector next_output(vector_reader *reader)
{
- if (reader->size == 0 || reader->nb_inputs >= 10) {
- fprintf(stderr, "Input reader overload (no more vectors)\n");
- exit(1);
- }
+ ASSERT(reader->size > 0);
+ ASSERT(reader->nb_inputs < 10);
+
const char *next = *(reader->next);
reader->next++;
reader->size--;