convert aes_test
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
syntax(2)
|
syntax(2)
|
||||||
test_suite('bind9')
|
test_suite('bind9')
|
||||||
|
|
||||||
atf_test_program{name='aes_test'}
|
tap_test_program{name='aes_test'}
|
||||||
atf_test_program{name='buffer_test'}
|
atf_test_program{name='buffer_test'}
|
||||||
atf_test_program{name='counter_test'}
|
atf_test_program{name='counter_test'}
|
||||||
atf_test_program{name='errno_test'}
|
atf_test_program{name='errno_test'}
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ TARGETS = aes_test@EXEEXT@ buffer_test@EXEEXT@ \
|
|||||||
@BIND9_MAKE_RULES@
|
@BIND9_MAKE_RULES@
|
||||||
|
|
||||||
aes_test@EXEEXT@: aes_test.@O@ ${ISCDEPLIBS}
|
aes_test@EXEEXT@: aes_test.@O@ ${ISCDEPLIBS}
|
||||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||||
aes_test.@O@ ${ISCLIBS} ${LIBS}
|
${LDFLAGS} -o $@ aes_test.@O@ \
|
||||||
|
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||||
|
|
||||||
buffer_test@EXEEXT@: buffer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
buffer_test@EXEEXT@: buffer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||||
|
|||||||
@@ -9,16 +9,20 @@
|
|||||||
* information regarding copyright ownership.
|
* information regarding copyright ownership.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* ! \file */
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <atf-c.h>
|
#if HAVE_CMOCKA
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define UNIT_TESTING
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
#include <isc/aes.h>
|
#include <isc/aes.h>
|
||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
#include <isc/hex.h>
|
#include <isc/hex.h>
|
||||||
@@ -55,15 +59,15 @@ tohexstr(unsigned char *d, char *out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
fromhexstr(const char *in, unsigned char *d)
|
fromhexstr(const char *in, unsigned char *d) {
|
||||||
{
|
|
||||||
isc_buffer_t b;
|
isc_buffer_t b;
|
||||||
isc_result_t ret;
|
isc_result_t ret;
|
||||||
|
|
||||||
isc_buffer_init(&b, d, ISC_AES256_KEYLENGTH + 1);
|
isc_buffer_init(&b, d, ISC_AES256_KEYLENGTH + 1);
|
||||||
ret = isc_hex_decodestring(in, &b);
|
ret = isc_hex_decodestring(in, &b);
|
||||||
if (ret != ISC_R_SUCCESS)
|
if (ret != ISC_R_SUCCESS) {
|
||||||
return 0;
|
return (0);
|
||||||
|
}
|
||||||
return isc_buffer_usedlength(&b);
|
return isc_buffer_usedlength(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,14 +77,9 @@ typedef struct aes_testcase {
|
|||||||
const char *result;
|
const char *result;
|
||||||
} aes_testcase_t;
|
} aes_testcase_t;
|
||||||
|
|
||||||
|
/* AES 128 test vectors */
|
||||||
ATF_TC(isc_aes128);
|
static void
|
||||||
ATF_TC_HEAD(isc_aes128, tc) {
|
isc_aes128_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "AES 128 test vectors");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(isc_aes128, tc) {
|
|
||||||
UNUSED(tc);
|
|
||||||
|
|
||||||
aes_testcase_t testcases[] = {
|
aes_testcase_t testcases[] = {
|
||||||
/* Test 1 (KAT ECBVarTxt128 #3) */
|
/* Test 1 (KAT ECBVarTxt128 #3) */
|
||||||
{
|
{
|
||||||
@@ -123,26 +122,24 @@ ATF_TC_BODY(isc_aes128, tc) {
|
|||||||
|
|
||||||
aes_testcase_t *testcase = testcases;
|
aes_testcase_t *testcase = testcases;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
while (testcase->key != NULL) {
|
while (testcase->key != NULL) {
|
||||||
len = fromhexstr(testcase->key, key);
|
len = fromhexstr(testcase->key, key);
|
||||||
ATF_CHECK_EQ(len, ISC_AES128_KEYLENGTH);
|
assert_int_equal(len, ISC_AES128_KEYLENGTH);
|
||||||
len = fromhexstr(testcase->input, plaintext);
|
len = fromhexstr(testcase->input, plaintext);
|
||||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||||
isc_aes128_crypt(key, plaintext, ciphertext);
|
isc_aes128_crypt(key, plaintext, ciphertext);
|
||||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||||
ATF_CHECK_STREQ(str, testcase->result);
|
assert_string_equal(str, testcase->result);
|
||||||
|
|
||||||
testcase++;
|
testcase++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_TC(isc_aes192);
|
/* AES 192 test vectors */
|
||||||
ATF_TC_HEAD(isc_aes192, tc) {
|
static void
|
||||||
atf_tc_set_md_var(tc, "descr", "AES 192 test vectors");
|
isc_aes192_test(void **state) {
|
||||||
}
|
|
||||||
ATF_TC_BODY(isc_aes192, tc) {
|
|
||||||
UNUSED(tc);
|
|
||||||
|
|
||||||
aes_testcase_t testcases[] = {
|
aes_testcase_t testcases[] = {
|
||||||
/* Test 1 (KAT ECBVarTxt192 #3) */
|
/* Test 1 (KAT ECBVarTxt192 #3) */
|
||||||
{
|
{
|
||||||
@@ -185,26 +182,24 @@ ATF_TC_BODY(isc_aes192, tc) {
|
|||||||
|
|
||||||
aes_testcase_t *testcase = testcases;
|
aes_testcase_t *testcase = testcases;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
while (testcase->key != NULL) {
|
while (testcase->key != NULL) {
|
||||||
len = fromhexstr(testcase->key, key);
|
len = fromhexstr(testcase->key, key);
|
||||||
ATF_CHECK_EQ(len, ISC_AES192_KEYLENGTH);
|
assert_int_equal(len, ISC_AES192_KEYLENGTH);
|
||||||
len = fromhexstr(testcase->input, plaintext);
|
len = fromhexstr(testcase->input, plaintext);
|
||||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||||
isc_aes192_crypt(key, plaintext, ciphertext);
|
isc_aes192_crypt(key, plaintext, ciphertext);
|
||||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||||
ATF_CHECK_STREQ(str, testcase->result);
|
assert_string_equal(str, testcase->result);
|
||||||
|
|
||||||
testcase++;
|
testcase++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_TC(isc_aes256);
|
/* AES 256 test vectors */
|
||||||
ATF_TC_HEAD(isc_aes256, tc) {
|
static void
|
||||||
atf_tc_set_md_var(tc, "descr", "AES 256 test vectors");
|
isc_aes256_test(void **state) {
|
||||||
}
|
|
||||||
ATF_TC_BODY(isc_aes256, tc) {
|
|
||||||
UNUSED(tc);
|
|
||||||
|
|
||||||
aes_testcase_t testcases[] = {
|
aes_testcase_t testcases[] = {
|
||||||
/* Test 1 (KAT ECBVarTxt256 #3) */
|
/* Test 1 (KAT ECBVarTxt256 #3) */
|
||||||
{
|
{
|
||||||
@@ -253,26 +248,40 @@ ATF_TC_BODY(isc_aes256, tc) {
|
|||||||
|
|
||||||
aes_testcase_t *testcase = testcases;
|
aes_testcase_t *testcase = testcases;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
while (testcase->key != NULL) {
|
while (testcase->key != NULL) {
|
||||||
len = fromhexstr(testcase->key, key);
|
len = fromhexstr(testcase->key, key);
|
||||||
ATF_CHECK_EQ(len, ISC_AES256_KEYLENGTH);
|
assert_int_equal(len, ISC_AES256_KEYLENGTH);
|
||||||
len = fromhexstr(testcase->input, plaintext);
|
len = fromhexstr(testcase->input, plaintext);
|
||||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||||
isc_aes256_crypt(key, plaintext, ciphertext);
|
isc_aes256_crypt(key, plaintext, ciphertext);
|
||||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||||
ATF_CHECK_STREQ(str, testcase->result);
|
assert_string_equal(str, testcase->result);
|
||||||
|
|
||||||
testcase++;
|
testcase++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int
|
||||||
* Main
|
main(void) {
|
||||||
*/
|
const struct CMUnitTest tests[] = {
|
||||||
ATF_TP_ADD_TCS(tp) {
|
cmocka_unit_test(isc_aes128_test),
|
||||||
ATF_TP_ADD_TC(tp, isc_aes128);
|
cmocka_unit_test(isc_aes192_test),
|
||||||
ATF_TP_ADD_TC(tp, isc_aes192);
|
cmocka_unit_test(isc_aes256_test),
|
||||||
ATF_TP_ADD_TC(tp, isc_aes256);
|
};
|
||||||
return (atf_no_error());
|
|
||||||
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* HAVE_CMOCKA */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void) {
|
||||||
|
printf("1..0 # Skipped: cmocka not available\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user