2004-12-30 18:55:53 -05:00
|
|
|
#include <tomcrypt.h>
|
2003-07-10 22:09:41 -04:00
|
|
|
|
|
|
|
void reg_algs(void)
|
|
|
|
{
|
2004-10-29 23:00:26 -04:00
|
|
|
int err;
|
2017-03-01 05:48:39 -05:00
|
|
|
LTC_UNUSED_PARAM(err);
|
2004-10-29 23:00:26 -04:00
|
|
|
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RIJNDAEL
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&aes_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_BLOWFISH
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&blowfish_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_XTEA
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&xtea_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RC5
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&rc5_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RC6
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&rc6_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SAFERP
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&saferp_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_TWOFISH
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&twofish_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SAFER
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&safer_k64_desc);
|
|
|
|
register_cipher (&safer_sk64_desc);
|
|
|
|
register_cipher (&safer_k128_desc);
|
|
|
|
register_cipher (&safer_sk128_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RC2
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&rc2_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_DES
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&des_desc);
|
|
|
|
register_cipher (&des3_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_CAST5
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&cast5_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_NOEKEON
|
2003-07-10 22:09:41 -04:00
|
|
|
register_cipher (&noekeon_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SKIPJACK
|
2003-12-24 13:59:57 -05:00
|
|
|
register_cipher (&skipjack_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_ANUBIS
|
2004-12-30 18:55:53 -05:00
|
|
|
register_cipher (&anubis_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_KHAZAD
|
2004-12-30 18:55:53 -05:00
|
|
|
register_cipher (&khazad_desc);
|
|
|
|
#endif
|
2011-10-05 04:37:19 -04:00
|
|
|
#ifdef LTC_CAMELLIA
|
|
|
|
register_cipher (&camellia_desc);
|
|
|
|
#endif
|
2003-07-10 22:09:41 -04:00
|
|
|
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_TIGER
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&tiger_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_MD2
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&md2_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_MD4
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&md4_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_MD5
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&md5_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SHA1
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&sha1_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SHA224
|
2003-12-24 13:59:57 -05:00
|
|
|
register_hash (&sha224_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SHA256
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&sha256_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SHA384
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&sha384_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_SHA512
|
2003-07-10 22:09:41 -04:00
|
|
|
register_hash (&sha512_desc);
|
|
|
|
#endif
|
2017-04-21 11:03:16 -04:00
|
|
|
#ifdef LTC_SHA512_224
|
|
|
|
register_hash (&sha512_224_desc);
|
|
|
|
#endif
|
|
|
|
#ifdef LTC_SHA512_256
|
|
|
|
register_hash (&sha512_256_desc);
|
|
|
|
#endif
|
2017-03-22 16:22:00 -04:00
|
|
|
#ifdef LTC_SHA3
|
|
|
|
register_hash (&sha3_224_desc);
|
|
|
|
register_hash (&sha3_256_desc);
|
|
|
|
register_hash (&sha3_384_desc);
|
|
|
|
register_hash (&sha3_512_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RIPEMD128
|
2003-12-24 13:59:57 -05:00
|
|
|
register_hash (&rmd128_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_RIPEMD160
|
2003-12-24 13:59:57 -05:00
|
|
|
register_hash (&rmd160_desc);
|
|
|
|
#endif
|
2017-04-21 11:03:16 -04:00
|
|
|
#ifdef LTC_RIPEMD256
|
|
|
|
register_hash (&rmd256_desc);
|
|
|
|
#endif
|
|
|
|
#ifdef LTC_RIPEMD320
|
|
|
|
register_hash (&rmd320_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_WHIRLPOOL
|
2004-02-20 15:03:32 -05:00
|
|
|
register_hash (&whirlpool_desc);
|
|
|
|
#endif
|
2017-04-19 17:03:34 -04:00
|
|
|
#ifdef LTC_BLAKE2S
|
|
|
|
register_hash (&blake2s_128_desc);
|
|
|
|
register_hash (&blake2s_160_desc);
|
|
|
|
register_hash (&blake2s_224_desc);
|
|
|
|
register_hash (&blake2s_256_desc);
|
|
|
|
#endif
|
|
|
|
#ifdef LTC_BLAKE2B
|
|
|
|
register_hash (&blake2b_160_desc);
|
|
|
|
register_hash (&blake2b_256_desc);
|
|
|
|
register_hash (&blake2b_384_desc);
|
|
|
|
register_hash (&blake2b_512_desc);
|
|
|
|
#endif
|
2007-07-20 13:48:02 -04:00
|
|
|
#ifdef LTC_CHC_HASH
|
2004-10-29 23:00:26 -04:00
|
|
|
register_hash(&chc_desc);
|
|
|
|
if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
|
|
|
|
printf("chc_register error: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-01 12:36:47 -04:00
|
|
|
#ifdef USE_LTM
|
|
|
|
ltc_mp = ltm_desc;
|
|
|
|
#elif defined(USE_TFM)
|
|
|
|
ltc_mp = tfm_desc;
|
2006-04-06 15:48:32 -04:00
|
|
|
#elif defined(USE_GMP)
|
|
|
|
ltc_mp = gmp_desc;
|
2005-08-01 12:36:47 -04:00
|
|
|
#else
|
|
|
|
extern ltc_math_descriptor EXT_MATH_LIB;
|
|
|
|
ltc_mp = EXT_MATH_LIB;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void hash_gen(void)
|
|
|
|
{
|
2004-07-23 11:40:22 -04:00
|
|
|
unsigned char md[MAXBLOCKSIZE], *buf;
|
2003-07-10 22:09:41 -04:00
|
|
|
unsigned long outlen, x, y, z;
|
|
|
|
FILE *out;
|
2004-07-23 11:40:22 -04:00
|
|
|
int err;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
out = fopen("hash_tv.txt", "w");
|
2004-07-23 11:40:22 -04:00
|
|
|
if (out == NULL) {
|
|
|
|
perror("can't open hash_tv");
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
|
|
|
|
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
2004-10-29 23:00:26 -04:00
|
|
|
buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1);
|
2004-07-23 11:40:22 -04:00
|
|
|
if (buf == NULL) {
|
|
|
|
perror("can't alloc mem");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2003-07-10 22:09:41 -04:00
|
|
|
fprintf(out, "Hash: %s\n", hash_descriptor[x].name);
|
|
|
|
for (y = 0; y <= (hash_descriptor[x].blocksize * 2); y++) {
|
|
|
|
for (z = 0; z < y; z++) {
|
2003-12-24 13:59:57 -05:00
|
|
|
buf[z] = (unsigned char)(z & 255);
|
2003-07-10 22:09:41 -04:00
|
|
|
}
|
|
|
|
outlen = sizeof(md);
|
2004-07-23 11:40:22 -04:00
|
|
|
if ((err = hash_memory(x, buf, y, md, &outlen)) != CRYPT_OK) {
|
|
|
|
printf("hash_memory error: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2003-07-10 22:09:41 -04:00
|
|
|
fprintf(out, "%3lu: ", y);
|
|
|
|
for (z = 0; z < outlen; z++) {
|
|
|
|
fprintf(out, "%02X", md[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2004-07-23 11:40:22 -04:00
|
|
|
XFREE(buf);
|
2003-07-10 22:09:41 -04:00
|
|
|
}
|
|
|
|
fclose(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cipher_gen(void)
|
|
|
|
{
|
2004-07-23 11:40:22 -04:00
|
|
|
unsigned char *key, pt[MAXBLOCKSIZE];
|
2003-07-10 22:09:41 -04:00
|
|
|
unsigned long x, y, z, w;
|
2004-07-23 11:40:22 -04:00
|
|
|
int err, kl, lastkl;
|
2003-07-10 22:09:41 -04:00
|
|
|
FILE *out;
|
|
|
|
symmetric_key skey;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
out = fopen("cipher_tv.txt", "w");
|
2013-03-20 12:34:00 -04:00
|
|
|
|
|
|
|
fprintf(out,
|
2003-12-24 13:59:57 -05:00
|
|
|
"Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n"
|
|
|
|
"The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n");
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name);
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
/* three modes, smallest, medium, large keys */
|
|
|
|
lastkl = 10000;
|
|
|
|
for (y = 0; y < 3; y++) {
|
|
|
|
switch (y) {
|
|
|
|
case 0: kl = cipher_descriptor[x].min_key_length; break;
|
|
|
|
case 1: kl = (cipher_descriptor[x].min_key_length + cipher_descriptor[x].max_key_length)/2; break;
|
|
|
|
case 2: kl = cipher_descriptor[x].max_key_length; break;
|
|
|
|
}
|
2004-07-23 11:40:22 -04:00
|
|
|
if ((err = cipher_descriptor[x].keysize(&kl)) != CRYPT_OK) {
|
|
|
|
printf("keysize error: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2003-07-10 22:09:41 -04:00
|
|
|
if (kl == lastkl) break;
|
|
|
|
lastkl = kl;
|
|
|
|
fprintf(out, "Key Size: %d bytes\n", kl);
|
|
|
|
|
2004-07-23 11:40:22 -04:00
|
|
|
key = XMALLOC(kl);
|
|
|
|
if (key == NULL) {
|
|
|
|
perror("can't malloc memory");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
for (z = 0; (int)z < kl; z++) {
|
|
|
|
key[z] = (unsigned char)z;
|
|
|
|
}
|
2004-07-23 11:40:22 -04:00
|
|
|
if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
|
|
|
|
printf("setup error: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
|
|
|
|
pt[z] = (unsigned char)z;
|
|
|
|
}
|
2003-12-24 13:59:57 -05:00
|
|
|
for (w = 0; w < 50; w++) {
|
2003-07-10 22:09:41 -04:00
|
|
|
cipher_descriptor[x].ecb_encrypt(pt, pt, &skey);
|
|
|
|
fprintf(out, "%2lu: ", w);
|
|
|
|
for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
|
|
|
|
fprintf(out, "%02X", pt[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2003-12-24 13:59:57 -05:00
|
|
|
|
|
|
|
/* reschedule a new key */
|
|
|
|
for (z = 0; z < (unsigned long)kl; z++) {
|
|
|
|
key[z] = pt[z % cipher_descriptor[x].block_length];
|
|
|
|
}
|
2004-07-23 11:40:22 -04:00
|
|
|
if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
|
|
|
|
printf("cipher setup2 error: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2003-07-10 22:09:41 -04:00
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2004-07-23 11:40:22 -04:00
|
|
|
XFREE(key);
|
2003-07-10 22:09:41 -04:00
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2013-03-20 12:34:00 -04:00
|
|
|
}
|
2003-12-24 13:59:57 -05:00
|
|
|
|
|
|
|
void hmac_gen(void)
|
|
|
|
{
|
2004-07-23 11:40:22 -04:00
|
|
|
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input;
|
2004-08-06 12:42:41 -04:00
|
|
|
int x, y, z, err;
|
2003-12-24 13:59:57 -05:00
|
|
|
FILE *out;
|
|
|
|
unsigned long len;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
out = fopen("hmac_tv.txt", "w");
|
|
|
|
|
2013-03-20 12:34:00 -04:00
|
|
|
fprintf(out,
|
2011-01-18 13:42:38 -05:00
|
|
|
"HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are HMACed. The initial key is\n"
|
|
|
|
"of the same format (the same length as the HASH output size). The HMAC key in step N+1 is the HMAC output of\n"
|
2003-12-24 13:59:57 -05:00
|
|
|
"step N.\n\n");
|
|
|
|
|
|
|
|
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
2011-01-18 13:42:38 -05:00
|
|
|
fprintf(out, "HMAC-%s\n", hash_descriptor[x].name);
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
/* initial key */
|
|
|
|
for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
|
|
|
|
key[y] = (y&255);
|
|
|
|
}
|
2004-07-23 11:40:22 -04:00
|
|
|
|
2004-10-29 23:00:26 -04:00
|
|
|
input = XMALLOC(hash_descriptor[x].blocksize * 2 + 1);
|
2004-07-23 11:40:22 -04:00
|
|
|
if (input == NULL) {
|
|
|
|
perror("Can't malloc memory");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
|
|
|
|
for (z = 0; z < y; z++) {
|
|
|
|
input[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(output);
|
|
|
|
if ((err = hmac_memory(x, key, hash_descriptor[x].hashsize, input, y, output, &len)) != CRYPT_OK) {
|
|
|
|
printf("Error hmacing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y);
|
|
|
|
for (z = 0; z <(int) len; z++) {
|
|
|
|
fprintf(out, "%02X", output[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
memcpy(key, output, hash_descriptor[x].hashsize);
|
|
|
|
}
|
2004-07-23 11:40:22 -04:00
|
|
|
XFREE(input);
|
2003-12-24 13:59:57 -05:00
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
void omac_gen(void)
|
|
|
|
{
|
2017-03-01 06:09:50 -05:00
|
|
|
#ifdef LTC_OMAC
|
2003-12-24 13:59:57 -05:00
|
|
|
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
|
|
|
|
int err, x, y, z, kl;
|
|
|
|
FILE *out;
|
|
|
|
unsigned long len;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
out = fopen("omac_tv.txt", "w");
|
|
|
|
|
2013-03-20 12:34:00 -04:00
|
|
|
fprintf(out,
|
2011-01-18 13:42:38 -05:00
|
|
|
"OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
|
|
|
|
"of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
|
2003-12-24 13:59:57 -05:00
|
|
|
"step N (repeated as required to fill the array).\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
|
|
|
if (kl != 8 && kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
2011-01-18 13:42:38 -05:00
|
|
|
fprintf(out, "OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
/* initial key/block */
|
|
|
|
for (y = 0; y < kl; y++) {
|
|
|
|
key[y] = (y & 255);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2003-12-24 13:59:57 -05:00
|
|
|
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
|
|
|
|
for (z = 0; z < y; z++) {
|
|
|
|
input[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(output);
|
|
|
|
if ((err = omac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
|
|
|
|
printf("Error omacing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y);
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", output[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = output[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
2003-12-24 13:59:57 -05:00
|
|
|
}
|
2003-07-10 22:09:41 -04:00
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
void pmac_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_PMAC
|
2004-02-20 15:03:32 -05:00
|
|
|
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
|
|
|
|
int err, x, y, z, kl;
|
|
|
|
FILE *out;
|
|
|
|
unsigned long len;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
out = fopen("pmac_tv.txt", "w");
|
|
|
|
|
2013-03-20 12:34:00 -04:00
|
|
|
fprintf(out,
|
2011-01-18 13:42:38 -05:00
|
|
|
"PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are PMAC'ed. The initial key is\n"
|
|
|
|
"of the same format (length specified per cipher). The PMAC key in step N+1 is the PMAC output of\n"
|
2004-02-20 15:03:32 -05:00
|
|
|
"step N (repeated as required to fill the array).\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
|
|
|
if (kl != 8 && kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
/* initial key/block */
|
|
|
|
for (y = 0; y < kl; y++) {
|
|
|
|
key[y] = (y & 255);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
|
|
|
|
for (z = 0; z < y; z++) {
|
|
|
|
input[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(output);
|
|
|
|
if ((err = pmac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) {
|
|
|
|
printf("Error omacing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y);
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", output[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = output[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2004-02-20 15:03:32 -05:00
|
|
|
}
|
|
|
|
|
2004-01-25 12:40:34 -05:00
|
|
|
void eax_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_EAX_MODE
|
2004-01-25 12:40:34 -05:00
|
|
|
int err, kl, x, y1, z;
|
|
|
|
FILE *out;
|
2013-03-20 12:34:00 -04:00
|
|
|
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
|
2004-01-25 12:40:34 -05:00
|
|
|
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
out = fopen("eax_tv.txt", "w");
|
|
|
|
fprintf(out, "EAX Test Vectors. Uses the 00010203...NN-1 pattern for header/nonce/plaintext/key. The outputs\n"
|
|
|
|
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
|
|
|
"step repeated sufficiently.\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
|
|
|
if (kl != 8 && kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "EAX-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
|
|
|
|
|
|
|
/* the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = (z & 255);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-01-25 12:40:34 -05:00
|
|
|
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
plaintext[z] = (unsigned char)(z & 255);
|
|
|
|
nonce[z] = (unsigned char)(z & 255);
|
|
|
|
header[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(tag);
|
|
|
|
if ((err = eax_encrypt_authenticate_memory(x, key, kl, nonce, y1, header, y1, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
|
|
|
|
printf("Error EAX'ing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y1);
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
fprintf(out, "%02X", plaintext[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, ", ");
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", tag[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = tag[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2004-01-25 12:40:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ocb_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_OCB_MODE
|
2004-01-25 12:40:34 -05:00
|
|
|
int err, kl, x, y1, z;
|
|
|
|
FILE *out;
|
2013-03-20 12:34:00 -04:00
|
|
|
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
2004-01-25 12:40:34 -05:00
|
|
|
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
out = fopen("ocb_tv.txt", "w");
|
|
|
|
fprintf(out, "OCB Test Vectors. Uses the 00010203...NN-1 pattern for nonce/plaintext/key. The outputs\n"
|
|
|
|
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
|
|
|
"step repeated sufficiently. The nonce is fixed throughout.\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
|
|
|
if (kl != 8 && kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "OCB-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
|
|
|
|
|
|
|
/* the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = (z & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixed nonce */
|
|
|
|
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
|
|
|
|
nonce[z] = z;
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-01-25 12:40:34 -05:00
|
|
|
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
plaintext[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(tag);
|
|
|
|
if ((err = ocb_encrypt_authenticate_memory(x, key, kl, nonce, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
|
|
|
|
printf("Error OCB'ing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y1);
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
fprintf(out, "%02X", plaintext[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, ", ");
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", tag[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = tag[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2004-01-25 12:40:34 -05:00
|
|
|
}
|
|
|
|
|
2012-08-04 19:21:13 -04:00
|
|
|
void ocb3_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_OCB3_MODE
|
2012-08-04 19:21:13 -04:00
|
|
|
int err, kl, x, y1, z;
|
|
|
|
FILE *out;
|
2013-03-20 12:34:00 -04:00
|
|
|
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
2012-08-04 19:21:13 -04:00
|
|
|
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
out = fopen("ocb3_tv.txt", "w");
|
|
|
|
fprintf(out, "OCB3 Test Vectors. Uses the 00010203...NN-1 pattern for nonce/plaintext/key. The outputs\n"
|
|
|
|
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
|
|
|
"step repeated sufficiently. The nonce is fixed throughout. AAD is fixed to 3 bytes (ASCII) 'AAD'.\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
|
|
|
if (kl != 8 && kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "OCB-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
|
|
|
|
|
|
|
/* the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = (z & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixed nonce */
|
|
|
|
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
|
|
|
|
nonce[z] = z;
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2012-08-04 19:21:13 -04:00
|
|
|
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
plaintext[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(tag);
|
2014-05-01 12:01:13 -04:00
|
|
|
if ((err = ocb3_encrypt_authenticate_memory(x, key, kl, nonce, cipher_descriptor[x].block_length, (unsigned char*)"AAD", 3, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
|
2012-08-04 19:21:13 -04:00
|
|
|
printf("Error OCB'ing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y1);
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
fprintf(out, "%02X", plaintext[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, ", ");
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", tag[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = tag[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2012-08-04 19:21:13 -04:00
|
|
|
}
|
2005-04-17 07:37:13 -04:00
|
|
|
|
|
|
|
void ccm_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_CCM_MODE
|
2005-04-17 07:37:13 -04:00
|
|
|
int err, kl, x, y1, z;
|
|
|
|
FILE *out;
|
2013-03-20 12:34:00 -04:00
|
|
|
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
2005-04-17 07:37:13 -04:00
|
|
|
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
out = fopen("ccm_tv.txt", "w");
|
|
|
|
fprintf(out, "CCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
|
|
|
|
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
|
|
|
"step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 128 bit block sizes */
|
|
|
|
if (kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "CCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
|
|
|
|
|
|
|
/* the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = (z & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixed nonce */
|
|
|
|
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
|
|
|
|
nonce[z] = z;
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2005-04-17 07:37:13 -04:00
|
|
|
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
plaintext[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(tag);
|
2005-11-18 00:15:37 -05:00
|
|
|
if ((err = ccm_memory(x, key, kl, NULL, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
|
2005-04-17 07:37:13 -04:00
|
|
|
printf("Error CCM'ing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y1);
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
fprintf(out, "%02X", plaintext[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, ", ");
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", tag[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = tag[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2005-04-17 07:37:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gcm_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_GCM_MODE
|
2005-04-17 07:37:13 -04:00
|
|
|
int err, kl, x, y1, z;
|
|
|
|
FILE *out;
|
|
|
|
unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
out = fopen("gcm_tv.txt", "w");
|
|
|
|
fprintf(out, "GCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n"
|
|
|
|
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
|
|
|
"step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n");
|
|
|
|
|
|
|
|
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
|
|
|
kl = cipher_descriptor[x].block_length;
|
|
|
|
|
|
|
|
/* skip ciphers which do not have 128 bit block sizes */
|
|
|
|
if (kl != 16) continue;
|
|
|
|
|
|
|
|
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
|
|
|
kl = cipher_descriptor[x].max_key_length;
|
|
|
|
}
|
|
|
|
fprintf(out, "GCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
|
|
|
|
|
|
|
/* the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = (z & 255);
|
|
|
|
}
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2005-04-17 07:37:13 -04:00
|
|
|
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
plaintext[z] = (unsigned char)(z & 255);
|
|
|
|
}
|
|
|
|
len = sizeof(tag);
|
|
|
|
if ((err = gcm_memory(x, key, kl, plaintext, y1, plaintext, y1, plaintext, y1, plaintext, tag, &len, GCM_ENCRYPT)) != CRYPT_OK) {
|
|
|
|
printf("Error GCM'ing: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
fprintf(out, "%3d: ", y1);
|
|
|
|
for (z = 0; z < y1; z++) {
|
|
|
|
fprintf(out, "%02X", plaintext[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, ", ");
|
|
|
|
for (z = 0; z <(int)len; z++) {
|
|
|
|
fprintf(out, "%02X", tag[z]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* forward the key */
|
|
|
|
for (z = 0; z < kl; z++) {
|
|
|
|
key[z] = tag[z % len];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2005-04-17 07:37:13 -04:00
|
|
|
}
|
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
void base64_gen(void)
|
|
|
|
{
|
|
|
|
FILE *out;
|
|
|
|
unsigned char dst[256], src[32];
|
|
|
|
unsigned long x, y, len;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2004-02-20 15:03:32 -05:00
|
|
|
out = fopen("base64_tv.txt", "w");
|
|
|
|
fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n");
|
|
|
|
for (x = 0; x <= 32; x++) {
|
|
|
|
for (y = 0; y < x; y++) {
|
|
|
|
src[y] = y;
|
|
|
|
}
|
|
|
|
len = sizeof(dst);
|
|
|
|
base64_encode(src, x, dst, &len);
|
|
|
|
fprintf(out, "%2lu: %s\n", x, dst);
|
|
|
|
}
|
|
|
|
fclose(out);
|
|
|
|
}
|
|
|
|
|
2005-08-01 12:36:47 -04:00
|
|
|
void math_gen(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ecc_gen(void)
|
|
|
|
{
|
|
|
|
FILE *out;
|
|
|
|
unsigned char str[512];
|
|
|
|
void *k, *order, *modulus;
|
|
|
|
ecc_point *G, *R;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
out = fopen("ecc_tv.txt", "w");
|
|
|
|
fprintf(out, "ecc vectors. These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n");
|
|
|
|
G = ltc_ecc_new_point();
|
|
|
|
R = ltc_ecc_new_point();
|
|
|
|
mp_init(&k);
|
|
|
|
mp_init(&order);
|
|
|
|
mp_init(&modulus);
|
|
|
|
|
|
|
|
for (x = 0; ltc_ecc_sets[x].size != 0; x++) {
|
|
|
|
fprintf(out, "ECC-%d\n", ltc_ecc_sets[x].size*8);
|
|
|
|
mp_set(k, 1);
|
|
|
|
|
2006-04-06 15:48:32 -04:00
|
|
|
mp_read_radix(order, (char *)ltc_ecc_sets[x].order, 16);
|
|
|
|
mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16);
|
|
|
|
mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16);
|
|
|
|
mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16);
|
2013-03-20 12:34:00 -04:00
|
|
|
mp_set(G->z, 1);
|
2005-08-01 12:36:47 -04:00
|
|
|
|
|
|
|
while (mp_cmp(k, order) == LTC_MP_LT) {
|
2005-11-18 00:15:37 -05:00
|
|
|
ltc_mp.ecc_ptmul(k, G, R, modulus, 1);
|
2006-06-17 21:37:50 -04:00
|
|
|
mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str);
|
|
|
|
mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
|
|
|
|
mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
|
2005-08-01 12:36:47 -04:00
|
|
|
mp_mul_d(k, 3, k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_clear_multi(k, order, modulus, NULL);
|
|
|
|
ltc_ecc_del_point(G);
|
|
|
|
ltc_ecc_del_point(R);
|
|
|
|
fclose(out);
|
|
|
|
}
|
|
|
|
|
2006-04-06 15:48:32 -04:00
|
|
|
void lrw_gen(void)
|
|
|
|
{
|
2017-03-01 05:48:39 -05:00
|
|
|
#ifdef LTC_LRW_MODE
|
2006-04-06 15:48:32 -04:00
|
|
|
FILE *out;
|
|
|
|
unsigned char tweak[16], key[16], iv[16], buf[1024];
|
|
|
|
int x, y, err;
|
|
|
|
symmetric_LRW lrw;
|
2013-03-20 12:34:00 -04:00
|
|
|
|
2006-04-06 15:48:32 -04:00
|
|
|
/* initialize default key and tweak */
|
|
|
|
for (x = 0; x < 16; x++) {
|
|
|
|
tweak[x] = key[x] = iv[x] = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
out = fopen("lrw_tv.txt", "w");
|
|
|
|
for (x = 16; x < (int)(sizeof(buf)); x += 16) {
|
|
|
|
if ((err = lrw_start(find_cipher("aes"), iv, key, 16, tweak, 0, &lrw)) != CRYPT_OK) {
|
|
|
|
fprintf(stderr, "Error starting LRW-AES: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* encrypt incremental */
|
|
|
|
for (y = 0; y < x; y++) {
|
|
|
|
buf[y] = y & 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = lrw_encrypt(buf, buf, x, &lrw)) != CRYPT_OK) {
|
|
|
|
fprintf(stderr, "Error encrypting with LRW-AES: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* display it */
|
|
|
|
fprintf(out, "%d:", x);
|
|
|
|
for (y = 0; y < x; y++) {
|
|
|
|
fprintf(out, "%02x", buf[y]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
/* reset IV */
|
|
|
|
if ((err = lrw_setiv(iv, 16, &lrw)) != CRYPT_OK) {
|
|
|
|
fprintf(stderr, "Error setting IV: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy new tweak, iv and key */
|
|
|
|
for (y = 0; y < 16; y++) {
|
|
|
|
key[y] = buf[y];
|
|
|
|
iv[y] = buf[(y+16)%x];
|
|
|
|
tweak[y] = buf[(y+32)%x];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = lrw_decrypt(buf, buf, x, &lrw)) != CRYPT_OK) {
|
|
|
|
fprintf(stderr, "Error decrypting with LRW-AES: %s\n", error_to_string(err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* display it */
|
|
|
|
fprintf(out, "%d:", x);
|
|
|
|
for (y = 0; y < x; y++) {
|
|
|
|
fprintf(out, "%02x", buf[y]);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
lrw_done(&lrw);
|
|
|
|
}
|
|
|
|
fclose(out);
|
2017-03-01 05:48:39 -05:00
|
|
|
#endif
|
2013-03-20 12:34:00 -04:00
|
|
|
}
|
2006-04-06 15:48:32 -04:00
|
|
|
|
2003-07-10 22:09:41 -04:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
reg_algs();
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
|
2004-01-25 12:40:34 -05:00
|
|
|
printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n");
|
2011-01-18 13:42:38 -05:00
|
|
|
printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#ifdef LTC_OMAC
|
2011-01-18 13:42:38 -05:00
|
|
|
printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_PMAC
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_EAX_MODE
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_OCB_MODE
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_OCB3_MODE
|
2012-08-04 19:21:13 -04:00
|
|
|
printf("Generating OCB3 vectors..."); fflush(stdout); ocb3_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_CCM_MODE
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
|
|
|
#ifdef LTC_GCM_MODE
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
2011-01-18 13:42:38 -05:00
|
|
|
printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
|
2005-08-01 12:36:47 -04:00
|
|
|
printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n");
|
|
|
|
printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#ifdef LTC_LRW_MODE
|
2006-04-06 15:48:32 -04:00
|
|
|
printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n");
|
2017-03-01 06:09:50 -05:00
|
|
|
#endif
|
2003-07-10 22:09:41 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-08 20:08:13 -04:00
|
|
|
/* $Source$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
/* $Date$ */
|