static int check(const struct TEST_VECTOR *test) { unsigned char out[MAX_OUT_LEN]; struct BLOCK_MODE_STATE ctx; size_t total = 0, out_len; struct BLOCK_STATE blk; if (!prim_avail(test->cipher)) return 1; ASSERT_SUCCESS(block_init(&blk, test->key, test->key_len, test->cipher, 0)); ASSERT_SUCCESS(block_mode_init(&ctx, &blk, test->iv, test->iv_len, 1, BLOCK_MODE_ECB, test->use_params ? &test->params : 0)); block_mode_update(&ctx, &blk, test->in, test->in_len, out, &out_len); total += out_len; ASSERT_SUCCESS(block_mode_final(&ctx, &blk, out + total, &out_len)); total += out_len; ASSERT_EQ(total, test->out_len); ASSERT_BUF_EQ(out, test->out, test->out_len); total = 0; ASSERT_SUCCESS(block_mode_init(&ctx, &blk, test->iv, test->iv_len, 0, BLOCK_MODE_ECB, test->use_params ? &test->params : 0)); block_mode_update(&ctx, &blk, test->out, test->out_len, out, &out_len); total += out_len; ASSERT_SUCCESS(block_mode_final(&ctx, &blk, out + total, &out_len)); total += out_len; ASSERT_EQ(total, test->in_len); ASSERT_BUF_EQ(out, test->in, test->in_len); block_final(&blk); return 1; }
TEST doubles() { uint8_t buf[16] = { 0 }; uint8_t buf_le[16] = { 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0, 0, 0, 0, 0, 0, 0 }; tm_buffer_double_write (buf, 1, 1.0, LE); ASSERT_BUF_EQ(buf_le, buf); uint8_t buf_ge[16] = { 0, 0x3f, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0 }; tm_buffer_double_write (buf, 1, 1.0, BE); ASSERT_BUF_EQ(buf_ge, buf); PASS(); }
TEST floats() { uint8_t buf[16] = { 0 }; uint8_t buf_le[16] = { 0, 0x00, 0x00, 0x80, 0x3f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; tm_buffer_float_write (buf, 1, 1.0, LE); ASSERT_BUF_EQ(buf_le, buf); uint8_t buf_ge[16] = { 0, 0x3f, 0x80, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; tm_buffer_float_write (buf, 1, 1.0, BE); ASSERT_BUF_EQ(buf_ge, buf); PASS(); }
TEST_END TEST_START(clax_buf_append_appends_buffer) { unsigned char *buf = NULL; size_t len = 0; clax_buf_append(&buf, &len, "foo", 3); ASSERT_EQ(len, 3); ASSERT_BUF_EQ(buf, "foo", 3); clax_buf_append(&buf, &len, "bar", 3); ASSERT_EQ(len, 6); ASSERT_BUF_EQ(buf, "foobar", 6); free(buf); }
static int check(const struct TEST_VECTOR *test) { unsigned char out[MAX_OUT_LEN]; struct BLOCK_STATE state; ASSERT_SUCCESS(block_init(&state, test->key, test->key_len, BLOCK_AES, test->use_params ? &test->params : 0)); memcpy(out, test->in, test->in_len); block_forward(&state, out); ASSERT_BUF_EQ(out, test->out, test->out_len); block_inverse(&state, out); ASSERT_BUF_EQ(out, test->in, test->in_len); block_final(&state); return 1; }
static int check(const struct TEST_VECTOR *test) { unsigned char out[MAX_OUT_LEN]; if (!prim_avail(test->hash)) return 1; ASSERT_SUCCESS(kdf_hkdf(test->hash, 0, test->key, test->key_len, test->salt, test->salt_len, test->info, test->info_len, out, test->out_len)); ASSERT_BUF_EQ(out, test->out, test->out_len); return 1; }