Commit 2895b49d authored by bg nerilex's avatar bg nerilex

moving more of the hash-test-system to Flash

parent 33dfea67
#
CSTD = gnu99
BUILD_LOG = build_log.txt
\ No newline at end of file
BUILD_LOG = log/build_log.txt
This diff is collapsed.
......@@ -22,6 +22,7 @@
#include <stdint.h>
#include "string-extras.h"
#include "flash.h"
#ifndef VOID_FPT
#define VOID_FPT
......
......@@ -67,7 +67,6 @@ void nessie_print_item(const char *name, uint8_t *buffer, uint16_t size_B)
puts_F(FSTR("\n!!! formatting error !!!"));
return;
}
putchar('\n');
for (i = 0; i < SPACES - name_len - 1; ++i) {
putchar(' ');
}
......@@ -94,11 +93,13 @@ void nessie_print_item(const char *name, uint8_t *buffer, uint16_t size_B)
toprint -= BYTESPERLINE;
}
}
putchar('\n');
putchar('\n');
}
void nessie_print_set_vector(uint8_t set, uint16_t vector)
{
printf_F(FSTR("\n\nSet %02" PRIu8 ", vector#%4" PRIu16 ":"), set, vector);
printf_F(FSTR("Set%2" PRIu8 ", vector#%3" PRIu16 ":\n"), set, vector);
}
/* example:
......@@ -107,8 +108,8 @@ Test vectors -- set 3
*/
void nessie_print_setheader(uint8_t set)
{
printf_F(FSTR("\n\nTest vectors -- set %" PRIu8 "\n"
"====================="),
printf_F(FSTR("Test vectors -- set %" PRIu8 "\n"
"=====================\n\n"),
set);
}
......@@ -136,7 +137,7 @@ void nessie_print_header(const char *name, uint16_t keysize_b,
"**************************************************************"
"******************\n"));
printf_F(FSTR("Primitive Name: %s\n"));
printf_F(FSTR("Primitive Name: %s\n"), name);
/* underline */
for (i = 0; i < 16 + strlen(name); ++i) {
cli_putc('=');
......@@ -163,11 +164,12 @@ void nessie_print_header(const char *name, uint16_t keysize_b,
printf_F(FSTR("IV size: %" PRIu16 " bits\n"), ivsize_b);
}
}
putchar('\n');
}
void nessie_print_footer(void)
{
puts_F(FSTR("\n\n\n\n"
puts_F(FSTR("\n\n\n"
"End of test vectors"
"\n"));
}
......@@ -28,6 +28,7 @@
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "flash.h"
#include "nessie_hash_test.h"
#include "nessie_common.h"
#include "dbz_strings.h"
......@@ -38,24 +39,23 @@ uint8_t nessie_hash_quick = 0;
#define HASHSIZE_B ((nessie_hash_ctx.hashsize_b + 7) / 8)
#define BLOCKSIZE_B (nessie_hash_ctx.blocksize_B)
static void ascii_hash(const char *data, const char *desc)
static void ascii_hash_F(const char *data, const char *desc)
{
uint8_t ctx[nessie_hash_ctx.ctx_size_B];
uint8_t hash[HASHSIZE_B];
uint16_t sl;
uint8_t buffer[BLOCKSIZE_B];
cli_putstr("\r\n message=");
cli_putstr(desc);
printf_F(FSTR(" message=%" PRIsFLASH "\n"), desc);
nessie_hash_ctx.hash_init(ctx);
sl = strlen(data);
sl = strlen_F(data);
while (sl >= BLOCKSIZE_B) {
memcpy(buffer, data, BLOCKSIZE_B);
memcpy_F(buffer, data, BLOCKSIZE_B);
nessie_hash_ctx.hash_next(ctx, buffer);
data += BLOCKSIZE_B;
sl -= BLOCKSIZE_B;
}
memcpy(buffer, data, sl);
memcpy_F(buffer, data, sl);
nessie_hash_ctx.hash_last(ctx, buffer, sl * 8);
nessie_hash_ctx.hash_conv(hash, ctx);
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b + 7) / 8);
......@@ -71,8 +71,7 @@ static void amillion_hash(void)
uint32_t n = 1000000LL;
uint16_t i = 0;
cli_putstr("\r\n message=");
cli_putstr("1 million times \"a\"");
puts_F(FSTR(" message=1 million times \"a\""));
memset(block, 'a', nessie_hash_ctx.blocksize_B);
nessie_hash_ctx.hash_init(ctx);
while (n >= nessie_hash_ctx.blocksize_B) {
......@@ -91,18 +90,7 @@ static void zero_hash(uint16_t n)
uint8_t hash[(nessie_hash_ctx.hashsize_b + 7) / 8];
uint8_t block[nessie_hash_ctx.blocksize_B];
cli_putstr("\r\n message=");
if (n >= 10000)
cli_putc('0' + n / 10000);
if (n >= 1000)
cli_putc('0' + (n / 1000) % 10);
if (n >= 100)
cli_putc('0' + (n / 100) % 10);
if (n >= 10)
cli_putc('0' + (n / 10) % 10);
cli_putc('0' + n % 10);
cli_putstr(" zero bits");
printf_F(FSTR(" message=%" PRIu16 " zero bits\n"), n);
memset(block, 0, nessie_hash_ctx.blocksize_B);
nessie_hash_ctx.hash_init(ctx);
while (n >= nessie_hash_ctx.blocksize_B * 8) {
......@@ -120,27 +108,22 @@ static void one_in512_hash(uint16_t pos)
uint8_t hash[(nessie_hash_ctx.hashsize_b + 7) / 8];
uint8_t block[nessie_hash_ctx.blocksize_B];
uint16_t n = 512;
char *tab[8] = {"80", "40", "20", "10", "08", "04", "02", "01"};
static const char tab_0[] FLASH = "80";
static const char tab_1[] FLASH = "40";
static const char tab_2[] FLASH = "20";
static const char tab_3[] FLASH = "10";
static const char tab_4[] FLASH = "08";
static const char tab_5[] FLASH = "04";
static const char tab_6[] FLASH = "02";
static const char tab_7[] FLASH = "01";
static const char const *tab[8] = {tab_0, tab_1, tab_2, tab_3,
tab_4, tab_5, tab_6, tab_7};
pos &= 511;
cli_putstr("\r\n message=");
cli_putstr("512-bit string: ");
if ((pos / 8) >= 10) {
cli_putc('0' + (pos / 8 / 10) % 10);
} else {
cli_putc(' ');
}
cli_putc('0' + (pos / 8) % 10);
cli_putstr("*00,");
cli_putstr(tab[pos & 7]);
cli_putc(',');
if (63 - (pos / 8) >= 10) {
cli_putc('0' + ((63 - pos / 8) / 10) % 10);
} else {
cli_putc(' ');
}
cli_putc('0' + (63 - pos / 8) % 10);
cli_putstr("*00");
printf_F(FSTR(" message=512-bit string: "
"%2d*00,%" PRIsFLASH ",%2d*00\n"),
pos / 8, tab[pos & 7], 63 - pos / 8);
/* now the real stuff */
memset(block, 0, 512 / 8);
......@@ -163,8 +146,8 @@ static void tv4_hash(void)
uint16_t n = nessie_hash_ctx.hashsize_b;
uint32_t i;
printf("\n message=%d zero bits",
nessie_hash_ctx.hashsize_b);
printf_F(FSTR(" message=%" PRIu16 " zero bits\n"),
nessie_hash_ctx.hashsize_b);
memset(block, 0, nessie_hash_ctx.hashsize_b / 8);
......@@ -176,8 +159,9 @@ static void tv4_hash(void)
nessie_hash_ctx.hash_last(ctx, block, n);
nessie_hash_ctx.hash_conv(hash, ctx);
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b + 7) / 8);
if (nessie_hash_quick)
if (nessie_hash_quick) {
return;
}
for (i = 1; i < 100000L; ++i) { /* this assumes BLOCKSIZE >= HASHSIZE */
nessie_hash_ctx.hash_init(ctx);
nessie_hash_ctx.hash_last(ctx, hash, nessie_hash_ctx.hashsize_b);
......@@ -201,57 +185,77 @@ static void tv4_hash(void)
void nessie_hash_run(void)
{
static const char test1_1_val[] FLASH = "";
static const char test1_1_str[] FLASH = "\"\" (empty string)";
static const char test1_2_val[] FLASH = "a";
static const char test1_2_str[] FLASH = "\"a\"";
static const char test1_3_val[] FLASH = "abc";
static const char test1_3_str[] FLASH = "\"abc\"";
static const char test1_4_val[] FLASH = "message digest";
static const char test1_4_str[] FLASH = "\"message digest\"";
static const char test1_5_val[] FLASH = "abcdefghijklmnopqrstuvwxyz";
static const char test1_5_str[] FLASH = "\"abcdefghijklmnopqrstuvwxyz\"";
static const char test1_6_val[] FLASH =
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
static const char test1_6_str[] FLASH =
"\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\"";
static const char test1_7_val[] FLASH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789";
static const char test1_7_str[] FLASH = "\"A...Za...z0...9\"";
static const char test1_8_val[] FLASH =
"1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890";
static const char test1_8_str[] FLASH = "8 times \"1234567890\"";
static const char *const challange1[] FLASH = {
test1_1_val, test1_1_str, test1_2_val, test1_2_str,
test1_3_val, test1_3_str, test1_4_val, test1_4_str,
test1_5_val, test1_5_str, test1_6_val, test1_6_str,
test1_7_val, test1_7_str, test1_8_val, test1_8_str};
uint16_t i;
uint8_t set;
nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b,
0, 0);
/* test set 1 */
char *challange_dbz =
"\0"
"\"\" (empty string)\0"
"a\0"
"\"a\"\0"
"abc\0"
"\"abc\"\0"
"message digest\0"
"\"message digest\"\0"
"abcdefghijklmnopqrstuvwxyz\0"
"\"abcdefghijklmnopqrstuvwxyz\"\0"
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\0"
"\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\"\0"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789\0"
"\"A...Za...z0...9\"\0"
"1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890\0"
"8 times \"1234567890\"\0";
const char *challange[16];
set = 1;
nessie_print_setheader(set);
dbz_splitup(challange_dbz, challange);
for (i = 0; i < 8; ++i) {
nessie_print_set_vector(set, i);
ascii_hash(challange[2 * i], challange[2 * i + 1]);
ascii_hash_F(flash_read_ptr(&challange1[2 * i]),
flash_read_ptr(&challange1[2 * i + 1]));
}
nessie_print_set_vector(set, i);
if (!nessie_hash_quick)
amillion_hash();
/* test set 2 */
set = 2;
nessie_print_setheader(set);
puts_F(FSTR("Message digests of strings of 0-bits and variable length:"));
for (i = 0; i < 1024; ++i) {
nessie_print_set_vector(set, i);
zero_hash(i);
}
/* test set 3 */
set = 3;
nessie_print_setheader(set);
puts_F(FSTR("Message digests of all 512-bit strings S containing a single 1-bit:"));
for (i = 0; i < 512; ++i) {
nessie_print_set_vector(set, i);
one_in512_hash(i);
}
/* test set 4 */
set = 4;
nessie_print_setheader(set);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment