Merge pull request #184 from libtom/pr/file-related-tests

Facelift of *_file functions
This commit is contained in:
karel-m 2017-04-21 17:20:41 +02:00 committed by GitHub
commit 65ace1a378
15 changed files with 259 additions and 113 deletions

View File

@ -24,6 +24,7 @@ static const struct {
LTC_TEST_FN(ecc_tests),
LTC_TEST_FN(dsa_test),
LTC_TEST_FN(katja_test),
LTC_TEST_FN(file_test),
};
int main(int argc, char **argv)

View File

@ -27,7 +27,7 @@
int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen)
{
hash_state md;
unsigned char buf[512];
unsigned char *buf;
size_t x;
int err;
@ -35,30 +35,36 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
LTC_ARGCHK(outlen != NULL);
LTC_ARGCHK(in != NULL);
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = hash_is_valid(hash)) != CRYPT_OK) {
return err;
goto LBL_ERR;
}
if (*outlen < hash_descriptor[hash].hashsize) {
*outlen = hash_descriptor[hash].hashsize;
return CRYPT_BUFFER_OVERFLOW;
err = CRYPT_BUFFER_OVERFLOW;
goto LBL_ERR;
}
if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) {
return err;
goto LBL_ERR;
}
*outlen = hash_descriptor[hash].hashsize;
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = hash_descriptor[hash].process(&md, buf, (unsigned long)x)) != CRYPT_OK) {
return err;
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
} while (x == LTC_FILE_READ_BUFSIZE);
err = hash_descriptor[hash].done(&md, out);
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
XFREE(buf);
return err;
}
#endif /* #ifndef LTC_NO_FILE */

View File

@ -22,14 +22,14 @@
@param cipher The index of the cipher desired
@param key The secret key
@param keylen The length of the secret key (octets)
@param filename The name of the file you wish to f9
@param fname The name of the file you wish to f9
@param out [out] Where the authentication tag is to be stored
@param outlen [in/out] The max size and resulting size of the authentication tag
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
*/
int f9_file(int cipher,
const unsigned char *key, unsigned long keylen,
const char *filename,
const char *fname,
unsigned char *out, unsigned long *outlen)
{
#ifdef LTC_NO_FILE
@ -39,41 +39,50 @@ int f9_file(int cipher,
int err;
f9_state f9;
FILE *in;
unsigned char buf[512];
unsigned char *buf;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(filename != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(fname != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
in = fopen(filename, "rb");
if (in == NULL) {
return CRYPT_FILE_NOTFOUND;
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = f9_init(&f9, cipher, key, keylen)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_ERR;
}
in = fopen(fname, "rb");
if (in == NULL) {
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = f9_process(&f9, buf, (unsigned long)x)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
fclose(in);
} while (x == LTC_FILE_READ_BUFSIZE);
if ((err = f9_done(&f9, out, outlen)) != CRYPT_OK) {
return err;
if (fclose(in) != 0) {
err = CRYPT_ERROR;
goto LBL_CLEANBUF;
}
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
err = f9_done(&f9, out, outlen);
return CRYPT_OK;
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(&f9, sizeof(f9_state));
#endif
XFREE(buf);
return err;
#endif
}

View File

@ -36,7 +36,7 @@ int hmac_file(int hash, const char *fname,
#else
hmac_state hmac;
FILE *in;
unsigned char buf[512];
unsigned char *buf;
size_t x;
int err;
@ -45,49 +45,52 @@ int hmac_file(int hash, const char *fname,
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
if((err = hash_is_valid(hash)) != CRYPT_OK) {
return err;
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = hash_is_valid(hash)) != CRYPT_OK) {
goto LBL_ERR;
}
if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
return err;
goto LBL_ERR;
}
in = fopen(fname, "rb");
if (in == NULL) {
return CRYPT_FILE_NOTFOUND;
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
/* process the file contents */
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = hmac_process(&hmac, buf, (unsigned long)x)) != CRYPT_OK) {
/* we don't trap this error since we're already returning an error! */
fclose(in);
return err;
fclose(in); /* we don't trap this error since we're already returning an error! */
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
} while (x == LTC_FILE_READ_BUFSIZE);
if (fclose(in) != 0) {
return CRYPT_ERROR;
err = CRYPT_ERROR;
goto LBL_CLEANBUF;
}
/* get final hmac */
if ((err = hmac_done(&hmac, out, outlen)) != CRYPT_OK) {
return err;
}
err = hmac_done(&hmac, out, outlen);
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
/* clear memory */
zeromem(buf, sizeof(buf));
zeromem(&hmac, sizeof(hmac_state));
#endif
return CRYPT_OK;
XFREE(buf);
return err;
#endif
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -39,41 +39,50 @@ int omac_file(int cipher,
int err;
omac_state omac;
FILE *in;
unsigned char buf[512];
unsigned char *buf;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(filename != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
in = fopen(filename, "rb");
if (in == NULL) {
return CRYPT_FILE_NOTFOUND;
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_ERR;
}
in = fopen(filename, "rb");
if (in == NULL) {
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = omac_process(&omac, buf, (unsigned long)x)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
fclose(in);
} while (x == LTC_FILE_READ_BUFSIZE);
if ((err = omac_done(&omac, out, outlen)) != CRYPT_OK) {
return err;
if (fclose(in) != 0) {
err = CRYPT_ERROR;
goto LBL_CLEANBUF;
}
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
err = omac_done(&omac, out, outlen);
return CRYPT_OK;
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(&omac, sizeof(omac_state));
#endif
XFREE(buf);
return err;
#endif
}

View File

@ -39,7 +39,7 @@ int pmac_file(int cipher,
int err;
pmac_state pmac;
FILE *in;
unsigned char buf[512];
unsigned char *buf;
LTC_ARGCHK(key != NULL);
@ -47,34 +47,43 @@ int pmac_file(int cipher,
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
in = fopen(filename, "rb");
if (in == NULL) {
return CRYPT_FILE_NOTFOUND;
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_ERR;
}
in = fopen(filename, "rb");
if (in == NULL) {
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = pmac_process(&pmac, buf, (unsigned long)x)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
fclose(in);
} while (x == LTC_FILE_READ_BUFSIZE);
if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) {
return err;
if (fclose(in) != 0) {
err = CRYPT_ERROR;
goto LBL_CLEANBUF;
}
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
err = pmac_done(&pmac, out, outlen);
return CRYPT_OK;
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(&pmac, sizeof(pmac_state));
#endif
XFREE(buf);
return err;
#endif
}

View File

@ -21,8 +21,8 @@
@param fname The name of the file you wish to POLY1305
@param key The secret key
@param keylen The length of the secret key
@param out [out] The POLY1305 authentication tag
@param outlen [in/out] The max size and resulting size of the authentication tag
@param mac [out] The POLY1305 authentication tag
@param maclen [in/out] The max size and resulting size of the authentication tag
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
*/
int poly1305_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen)
@ -41,23 +41,37 @@ int poly1305_file(const char *fname, const unsigned char *key, unsigned long key
LTC_ARGCHK(mac != NULL);
LTC_ARGCHK(maclen != NULL);
if ((in = fopen(fname, "rb")) == NULL) { return CRYPT_FILE_NOTFOUND; }
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) { return CRYPT_MEM; }
if ((err = poly1305_init(&st, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = poly1305_init(&st, key, keylen)) != CRYPT_OK) {
goto LBL_ERR;
}
in = fopen(fname, "rb");
if (in == NULL) {
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
do {
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = poly1305_process(&st, buf, (unsigned long)x)) != CRYPT_OK) {
fclose(in);
goto LBL_ERR;
goto LBL_CLEANBUF;
}
} while (x == LTC_FILE_READ_BUFSIZE);
if (fclose(in) != 0) {
if (fclose(in) != 0) {
err = CRYPT_ERROR;
goto LBL_ERR;
goto LBL_CLEANBUF;
}
err = poly1305_done(&st, mac, maclen);
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(&st, sizeof(poly1305_state));

View File

@ -39,41 +39,50 @@ int xcbc_file(int cipher,
int err;
xcbc_state xcbc;
FILE *in;
unsigned char buf[512];
unsigned char *buf;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(filename != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
in = fopen(filename, "rb");
if (in == NULL) {
return CRYPT_FILE_NOTFOUND;
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
return CRYPT_MEM;
}
if ((err = xcbc_init(&xcbc, cipher, key, keylen)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_ERR;
}
in = fopen(filename, "rb");
if (in == NULL) {
err = CRYPT_FILE_NOTFOUND;
goto LBL_ERR;
}
do {
x = fread(buf, 1, sizeof(buf), in);
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
if ((err = xcbc_process(&xcbc, buf, (unsigned long)x)) != CRYPT_OK) {
fclose(in);
return err;
goto LBL_CLEANBUF;
}
} while (x == sizeof(buf));
fclose(in);
} while (x == LTC_FILE_READ_BUFSIZE);
if ((err = xcbc_done(&xcbc, out, outlen)) != CRYPT_OK) {
return err;
if (fclose(in) != 0) {
err = CRYPT_ERROR;
goto LBL_CLEANBUF;
}
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
err = xcbc_done(&xcbc, out, outlen);
return CRYPT_OK;
LBL_CLEANBUF:
zeromem(buf, LTC_FILE_READ_BUFSIZE);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(&xcbc, sizeof(xcbc_state));
#endif
XFREE(buf);
return err;
#endif
}

85
testprof/file_test.c Normal file
View File

@ -0,0 +1,85 @@
/* test file related functions */
#include <tomcrypt_test.h>
int file_test(void)
{
#ifdef LTC_NO_FILE
return CRYPT_NOP;
#else
unsigned char key[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
unsigned char buf[200];
unsigned long len;
char *fname = "testprof/test.key";
FILE *in;
int err, isha256, iaes;
/* expected results */
unsigned char exp_sha256[32] = { 0x76, 0xEC, 0x7F, 0xAE, 0xBD, 0xC4, 0x2A, 0x4D, 0xE3, 0x5C, 0xA7, 0x00, 0x24, 0xC2, 0xD2, 0x73,
0xE9, 0xF7, 0x85, 0x6C, 0xA6, 0x16, 0x12, 0xE8, 0x9F, 0x5F, 0x66, 0x35, 0x0B, 0xA8, 0xCF, 0x5F };
isha256 = find_hash("sha256");
iaes = find_cipher("aes");
len = sizeof(buf);
if ((in = fopen(fname, "rb")) == NULL) return CRYPT_FILE_NOTFOUND;
if ((err = hash_filehandle(isha256, in, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_sha256, 32, "hash_filehandle", 1)) return 1;
len = sizeof(buf);
if ((err = hash_file(isha256, fname, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_sha256, 32, "hash_file", 1)) return 1;
#ifdef LTC_HMAC
{
unsigned char exp_hmacsha256[32] = { 0xE4, 0x07, 0x74, 0x95, 0xF1, 0xF8, 0x5B, 0xB5, 0xF1, 0x4F, 0x7D, 0x4F, 0x59, 0x8E, 0x4B, 0xBC,
0x8F, 0x68, 0xCF, 0xBA, 0x2E, 0xAD, 0xC4, 0x63, 0x9D, 0x7F, 0x02, 0x99, 0x8C, 0x08, 0xAC, 0xC0 };
len = sizeof(buf);
if ((err = hmac_file(isha256, fname, key, 32, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_hmacsha256, 32, "hmac_file", 1)) return 1;
}
#endif
#ifdef LTC_OMAC
{
unsigned char exp_omacaes[16] = { 0x50, 0xB4, 0x6C, 0x62, 0xE9, 0xCA, 0x48, 0xFC, 0x38, 0x8D, 0xF4, 0xA2, 0x7D, 0x6A, 0x1E, 0xD8 };
len = sizeof(buf);
if ((err = omac_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_omacaes, 16, "omac_file", 1)) return 1;
}
#endif
#ifdef LTC_PMAC
{
unsigned char exp_pmacaes[16] = { 0x7D, 0x65, 0xF0, 0x75, 0x4F, 0x8D, 0xE2, 0xB0, 0xE4, 0xFA, 0x54, 0x4E, 0x45, 0x01, 0x36, 0x1B };
len = sizeof(buf);
if ((err = pmac_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_pmacaes, 16, "pmac_file", 1)) return 1;
}
#endif
#ifdef LTC_XCBC
{
unsigned char exp_xcbcaes[16] = { 0x9C, 0x73, 0xA2, 0xD7, 0x90, 0xA5, 0x86, 0x25, 0x4D, 0x3C, 0x8A, 0x6A, 0x24, 0x6D, 0xD1, 0xAB };
len = sizeof(buf);
if ((err = xcbc_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_xcbcaes, 16, "xcbc_file", 1)) return 1;
}
#endif
#ifdef LTC_F9_MODE
{
unsigned char exp_f9aes[16] = { 0x6B, 0x6A, 0x18, 0x34, 0x13, 0x8E, 0x01, 0xEF, 0x33, 0x8E, 0x7A, 0x3F, 0x5B, 0x9A, 0xA6, 0x7A };
len = sizeof(buf);
if ((err = f9_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_f9aes, 16, "f9_file", 1)) return 1;
}
#endif
#ifdef LTC_POLY1305
{
unsigned char exp_poly1305[16] = { 0xD0, 0xC7, 0xFB, 0x13, 0xA8, 0x87, 0x84, 0x23, 0x21, 0xCC, 0xA9, 0x43, 0x81, 0x18, 0x75, 0xBE };
len = sizeof(buf);
if ((err = poly1305_file(fname, key, 32, buf, &len)) != CRYPT_OK) return err;
if (compare_testvector(buf, len, exp_poly1305, 16, "poly1305_file", 1)) return 1;
}
#endif
return CRYPT_OK;
#endif
}

View File

@ -17,7 +17,7 @@ ifneq ($V,1)
endif
${silent} ${CC} ${CFLAGS} -c $< -o $@
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o \
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o file_test.o \
dsa_test.o ecc_test.o mac_test.o misc_test.o modes_test.o pkcs_1_test.o rsa_test.o \
store_test.o rotate_test.o test_driver.o x86_prof.o katja_test.o dh_test.o \
pkcs_1_pss_test.o pkcs_1_oaep_test.o pkcs_1_emsa_test.o pkcs_1_eme_test.o

View File

@ -1,7 +1,7 @@
CFLAGS += -I../src/headers -I./
CC?=icc
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o \
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o file_test.o \
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
store_test.o rotate_test.o test_driver.o x86_prof.o katja_test.o dh_test.o misc_test.o \
pkcs_1_pss_test.o pkcs_1_oaep_test.o pkcs_1_emsa_test.o pkcs_1_eme_test.o

View File

@ -4,7 +4,7 @@
CFLAGS = $(CFLAGS_OPTS) -I../src/headers -I../../libtommath -I. -Wall -Wextra -DUSE_LTM -DLTM_DESC
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o \
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o file_test.o \
dsa_test.o ecc_test.o mac_test.o misc_test.o modes_test.o pkcs_1_test.o rsa_test.o \
store_test.o rotate_test.o test_driver.o x86_prof.o katja_test.o dh_test.o pkcs_1_pss_test.o \
pkcs_1_oaep_test.o pkcs_1_emsa_test.o pkcs_1_eme_test.o

View File

@ -1,6 +1,6 @@
CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /DLTC_SOURCE /DUSE_LTM /W3
OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj no_prng.obj \
OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj no_prng.obj file_test.obj \
dsa_test.obj ecc_test.obj mac_test.obj modes_test.obj pkcs_1_test.obj \
rsa_test.obj store_test.obj rotate_test.obj test_driver.obj x86_prof.obj katja_test.obj \
dh_test.obj misc_test.obj pkcs_1_pss_test.obj pkcs_1_oaep_test.obj \

View File

@ -6,7 +6,7 @@ LTCOMPILE = $(LT) --mode=compile --tag=CC $(CC)
CFLAGS += -I../src/headers -I./ -Wall -Wsign-compare -W -Wshadow -Wno-unused-parameter
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o \
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o no_prng.o file_test.o \
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
store_test.o rotate_test.o test_driver.o x86_prof.o katja_test.o dh_test.o misc_test.o \
pkcs_1_pss_test.o pkcs_1_oaep_test.o pkcs_1_emsa_test.o pkcs_1_eme_test.o

View File

@ -65,6 +65,7 @@ int dsa_test(void);
int der_tests(void);
int misc_test(void);
int base64_test(void);
int file_test(void);
/* timing */
#define KTIMES 25