From a5fa5eb95b79e98e260365878fc9338ccba3fba9 Mon Sep 17 00:00:00 2001 From: bg Date: Fri, 7 Oct 2011 18:17:41 +0200 Subject: [PATCH] adding SHA-512 --- hfal/hfal_sha512.c | 49 +++++++++ hfal/hfal_sha512.h | 36 +++++++ mkfiles/sha512_c.mk | 13 +++ sha256/sha256.c | 12 ++- sha256/sha256.h | 3 - sha512/sha512.c | 164 +++++++++++++++++++++++++++++ sha512/sha512.h | 62 +++++++++++ test_src/cli.h | 1 + test_src/main-sha512-test.c | 204 ++++++++++++++++++++++++++++++++++++ test_src/uart_i.c | 9 ++ test_src/uart_lowlevel.c | 8 ++ 11 files changed, 554 insertions(+), 7 deletions(-) create mode 100644 hfal/hfal_sha512.c create mode 100644 hfal/hfal_sha512.h create mode 100644 mkfiles/sha512_c.mk create mode 100644 sha512/sha512.c create mode 100644 sha512/sha512.h create mode 100644 test_src/main-sha512-test.c diff --git a/hfal/hfal_sha512.c b/hfal/hfal_sha512.c new file mode 100644 index 0000000..4d7dd25 --- /dev/null +++ b/hfal/hfal_sha512.c @@ -0,0 +1,49 @@ +/* hfal_sha512.c */ +/* + This file is part of the ARM-Crypto-Lib. + Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * \file hfal_sha512.c + * \email daniel.otte@rub.de + * \author Daniel Otte + * \date 2011-10-07 + * \license GPLv3 or later + * + */ + + +#include +#include "hashfunction_descriptor.h" +#include "sha512.h" + +static const char sha512_str[] = "SHA-512"; + +const hfdesc_t sha512_desc = { + HFDESC_TYPE_HASHFUNCTION, + 0, + sha512_str, + sizeof(sha512_ctx_t), + 1024, + 512, + (hf_init_fpt)sha512_init, + (hf_nextBlock_fpt)sha512_nextBlock, + (hf_lastBlock_fpt)sha512_lastBlock, + (hf_ctx2hash_fpt)sha512_ctx2hash, + (hf_free_fpt)NULL, + (hf_mem_fpt)sha512 +}; + diff --git a/hfal/hfal_sha512.h b/hfal/hfal_sha512.h new file mode 100644 index 0000000..0db9640 --- /dev/null +++ b/hfal/hfal_sha512.h @@ -0,0 +1,36 @@ +/* hfal_sha512.h */ +/* + This file is part of the ARM-Crypto-Lib. + Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * \file hfal_sha256.h + * \email daniel.otte@rub.de + * \author Daniel Otte + * \date 2011-10-07 + * \license GPLv3 or later + * + */ + +#ifndef HFAL_SHA512_H_ +#define HFAL_SHA512_H_ + + +#include "hashfunction_descriptor.h" + +extern const hfdesc_t sha512_desc; + +#endif /* HFAL_SHA512_H_ */ diff --git a/mkfiles/sha512_c.mk b/mkfiles/sha512_c.mk new file mode 100644 index 0000000..6acbe4d --- /dev/null +++ b/mkfiles/sha512_c.mk @@ -0,0 +1,13 @@ +# Makefile for SHA-512 +ALGO_NAME := SHA512_C + +# comment out the following line for removement of SHA-512 from the build process +HASHES += $(ALGO_NAME) + +$(ALGO_NAME)_DIR := sha512/ +$(ALGO_NAME)_INCDIR := hfal/ +$(ALGO_NAME)_OBJ := sha512.o +$(ALGO_NAME)_TESTBIN := main-sha512-test.o $(CLI_STD) $(HFAL_STD) hfal_sha512.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PERFORMANCE_TEST := "performance" + diff --git a/sha256/sha256.c b/sha256/sha256.c index c121466..3e66355 100644 --- a/sha256/sha256.c +++ b/sha256/sha256.c @@ -73,6 +73,10 @@ uint32_t rotr32( uint32_t x, uint8_t n){ return ((x>>n) | (x<<(32-n))); } +static +uint32_t rotl32( uint32_t x, uint8_t n){ + return ((x<>(32-n))); +} /*************************************************************************/ @@ -90,10 +94,10 @@ uint32_t change_endian32(uint32_t x){ #define CH(x,y,z) (((x)&(y)) ^ ((~(x))&(z))) #define MAJ(x,y,z) (((x)&(y)) ^ ((x)&(z)) ^ ((y)&(z))) -#define SIGMA0(x) (rotr32((x),2) ^ rotr32((x),13) ^ rotr32((x),22)) -#define SIGMA1(x) (rotr32((x),6) ^ rotr32((x),11) ^ rotr32((x),25)) -#define SIGMA_a(x) (rotr32((x),7) ^ rotr32((x),18) ^ ((x)>>3)) -#define SIGMA_b(x) (rotr32((x),17) ^ rotr32((x),19) ^ ((x)>>10)) +#define SIGMA0(x) (rotr32((x),2) ^ rotr32((x),13) ^ rotl32((x),10)) +#define SIGMA1(x) (rotr32((x),6) ^ rotr32((x),11) ^ rotl32((x),7)) +#define SIGMA_a(x) (rotr32((x),7) ^ rotl32((x),14) ^ ((x)>>3)) +#define SIGMA_b(x) (rotl32((x),15) ^ rotl32((x),13) ^ ((x)>>10)) const uint32_t k[]={ diff --git a/sha256/sha256.h b/sha256/sha256.h index ea1191e..1a310d7 100644 --- a/sha256/sha256.h +++ b/sha256/sha256.h @@ -27,9 +27,6 @@ #ifndef SHA256_H_ #define SHA256_H_ -#define __LITTLE_ENDIAN__ - - #include /** \def SHA256_HASH_BITS diff --git a/sha512/sha512.c b/sha512/sha512.c new file mode 100644 index 0000000..52776bc --- /dev/null +++ b/sha512/sha512.c @@ -0,0 +1,164 @@ +/* sha512.c */ +/* + This file is part of the ARM-Crypto-Lib. + Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include "sha512.h" + +#include "cli.h" + +static const +uint64_t sha512_init_values[8] = { +0x6a09e667f3bcc908LL, 0xbb67ae8584caa73bLL, 0x3c6ef372fe94f82bLL, 0xa54ff53a5f1d36f1LL, +0x510e527fade682d1LL, 0x9b05688c2b3e6c1fLL, 0x1f83d9abfb41bd6bLL, 0x5be0cd19137e2179LL +}; + +static const +uint64_t sha512_const[80] = { +0x428a2f98d728ae22LL, 0x7137449123ef65cdLL, 0xb5c0fbcfec4d3b2fLL, 0xe9b5dba58189dbbcLL, +0x3956c25bf348b538LL, 0x59f111f1b605d019LL, 0x923f82a4af194f9bLL, 0xab1c5ed5da6d8118LL, +0xd807aa98a3030242LL, 0x12835b0145706fbeLL, 0x243185be4ee4b28cLL, 0x550c7dc3d5ffb4e2LL, +0x72be5d74f27b896fLL, 0x80deb1fe3b1696b1LL, 0x9bdc06a725c71235LL, 0xc19bf174cf692694LL, +0xe49b69c19ef14ad2LL, 0xefbe4786384f25e3LL, 0x0fc19dc68b8cd5b5LL, 0x240ca1cc77ac9c65LL, +0x2de92c6f592b0275LL, 0x4a7484aa6ea6e483LL, 0x5cb0a9dcbd41fbd4LL, 0x76f988da831153b5LL, +0x983e5152ee66dfabLL, 0xa831c66d2db43210LL, 0xb00327c898fb213fLL, 0xbf597fc7beef0ee4LL, +0xc6e00bf33da88fc2LL, 0xd5a79147930aa725LL, 0x06ca6351e003826fLL, 0x142929670a0e6e70LL, +0x27b70a8546d22ffcLL, 0x2e1b21385c26c926LL, 0x4d2c6dfc5ac42aedLL, 0x53380d139d95b3dfLL, +0x650a73548baf63deLL, 0x766a0abb3c77b2a8LL, 0x81c2c92e47edaee6LL, 0x92722c851482353bLL, +0xa2bfe8a14cf10364LL, 0xa81a664bbc423001LL, 0xc24b8b70d0f89791LL, 0xc76c51a30654be30LL, +0xd192e819d6ef5218LL, 0xd69906245565a910LL, 0xf40e35855771202aLL, 0x106aa07032bbd1b8LL, +0x19a4c116b8d2d0c8LL, 0x1e376c085141ab53LL, 0x2748774cdf8eeb99LL, 0x34b0bcb5e19b48a8LL, +0x391c0cb3c5c95a63LL, 0x4ed8aa4ae3418acbLL, 0x5b9cca4f7763e373LL, 0x682e6ff3d6b2b8a3LL, +0x748f82ee5defb2fcLL, 0x78a5636f43172f60LL, 0x84c87814a1f0ab72LL, 0x8cc702081a6439ecLL, +0x90befffa23631e28LL, 0xa4506cebde82bde9LL, 0xbef9a3f7b2c67915LL, 0xc67178f2e372532bLL, +0xca273eceea26619cLL, 0xd186b8c721c0c207LL, 0xeada7dd6cde0eb1eLL, 0xf57d4f7fee6ed178LL, +0x06f067aa72176fbaLL, 0x0a637dc5a2c898a6LL, 0x113f9804bef90daeLL, 0x1b710b35131c471bLL, +0x28db77f523047d84LL, 0x32caab7b40c72493LL, 0x3c9ebe0a15c9bebcLL, 0x431d67c49c100d4cLL, +0x4cc5d4becb3e42b6LL, 0x597f299cfc657e2aLL, 0x5fcb6fab3ad6faecLL, 0x6c44198c4a475817LL +}; + + +static const +uint64_t change_endian64(uint64_t x){ + uint64_t r=0; + uint8_t i=8; + do{ + r <<= 8; + r |= 0xff&x; + x >>=8; + }while(--i); + return r; +} + +static const +uint64_t rotr64(uint64_t x, uint8_t n){ + return (x>>n)|(x<<(64-n)); +} + +static const +uint64_t rotl64(uint64_t x, uint8_t n){ + return (x<>(64-n)); +} + +void sha512_init(sha512_ctx_t* ctx){ + ctx->length = 0; + memcpy(ctx->h, sha512_init_values, 8*8); +} + +void sha512_ctx2hash(void* dest, const sha512_ctx_t* ctx){ + uint8_t i=8; + do{ + *((uint64_t*)dest) = change_endian64(ctx->h[8-i]); + dest = (uint8_t*)dest + 8; + }while(--i); +} + +#define CH(x,y,z) (((x)&(y))^((~(x))&(z))) +#define MAJ(x,y,z) (((x)&(y))^((x)&(z))^((y)&(z))) +#define SIGMA_0(x) (rotr64((x), 28) ^ rotl64((x), 30) ^ rotl64((x), 25)) +#define SIGMA_1(x) (rotr64((x), 14) ^ rotr64((x), 18) ^ rotl64((x), 23)) +#define SIGMA_a(x) (rotr64((x), 1) ^ rotr64((x), 8) ^ ((x)>>7)) +#define SIGMA_b(x) (rotr64((x), 19) ^ rotl64((x), 3) ^ ((x)>>6)) + +void sha512_nextBlock(sha512_ctx_t* ctx, const void* block){ + uint64_t w[16], wx; + uint64_t a[8]; + uint64_t t1, t2; + const uint64_t *k=sha512_const; + uint8_t i; + i=16; + do{ + w[16-i] = change_endian64(*((const uint64_t*)block)); + block = (uint8_t*)block + 8; + }while(--i); + memcpy(a, ctx->h, 8*8); + for(i=0; i<80; ++i){ + if(i<16){ + wx=w[i]; + }else{ + wx = SIGMA_b(w[14]) + w[9] + SIGMA_a(w[1]) + w[0]; + memmove(&(w[0]), &(w[1]), 15*8); + w[15] = wx; + } + t1 = a[7] + SIGMA_1(a[4]) + CH(a[4], a[5], a[6]) + *k++ + wx; + t2 = SIGMA_0(a[0]) + MAJ(a[0], a[1], a[2]); + memmove(&(a[1]), &(a[0]), 7*8); + a[0] = t1 + t2; + a[4] += t1; + } + i=7; + do{ + ctx->h[i] += a[i]; + }while(i--); + ctx->length += 1; +} + +void sha512_lastBlock(sha512_ctx_t* ctx, const void* block, uint16_t length_b){ + while(length_b >= 1024){ + sha512_nextBlock(ctx, block); + block = (uint8_t*)block + 1024/8; + length_b -= 1024; + } + uint8_t buffer[1024/8]; + uint64_t len; + len = ((uint64_t)ctx->length)*1024LL + length_b; + len = change_endian64(len); + memset(buffer, 0, 1024/8); + memcpy(buffer, block, (length_b+7)/8); + buffer[length_b/8] |= 0x80>>(length_b%8); + if(length_b>1024-128-1){ + /* length goes into the next block */ + sha512_nextBlock(ctx, buffer); + memset(buffer, 0, 120); + } + memcpy(&(buffer[128-8]), &len, 8); + sha512_nextBlock(ctx, buffer); +} + +void sha512(void* dest, const void* msg, uint32_t length_b){ + sha512_ctx_t ctx; + sha512_init(&ctx); + while(length_b >= 1024){ + sha512_nextBlock(&ctx, msg); + msg = (uint8_t*)msg + 1024/8; + length_b -= 1024; + } + sha512_lastBlock(&ctx, msg, length_b); + sha512_ctx2hash(dest, &ctx); +} diff --git a/sha512/sha512.h b/sha512/sha512.h new file mode 100644 index 0000000..d067891 --- /dev/null +++ b/sha512/sha512.h @@ -0,0 +1,62 @@ +/* sha512.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef SHA512_H_ +#define SHA512_H_ + +#define __LITTLE_ENDIAN__ + + +#include + +/** \def SHA256_HASH_BITS + * defines the size of a SHA-256 hash value in bits + */ + +/** \def SHA256_HASH_BYTES + * defines the size of a SHA-256 hash value in bytes + */ + +/** \def SHA256_BLOCK_BITS + * defines the size of a SHA-256 input block in bits + */ + +/** \def SHA256_BLOCK_BYTES + * defines the size of a SHA-256 input block in bytes + */ + +#define SHA512_HASH_BITS 512 +#define SHA512_HASH_BYTES (SHA512_HASH_BITS/8) +#define SHA512_BLOCK_BITS 1024 +#define SHA5122_BLOCK_BYTES (SHA512_BLOCK_BITS/8) + +typedef struct { + uint64_t h[8]; + uint32_t length; +} sha512_ctx_t; + + +void sha512_init(sha512_ctx_t *ctx); +void sha512_nextBlock (sha512_ctx_t* ctx, const void* block); +void sha512_lastBlock(sha512_ctx_t* ctx, const void* block, uint16_t length_b); +void sha512_ctx2hash(void* dest, const sha512_ctx_t* ctx); +void sha512(void* dest, const void* msg, uint32_t length_b); + + +#endif /* SHA512_H_ */ diff --git a/test_src/cli.h b/test_src/cli.h index f4e615f..26c725b 100644 --- a/test_src/cli.h +++ b/test_src/cli.h @@ -62,6 +62,7 @@ void cli_hexdump(const void* data, uint32_t length); void cli_hexdump_rev(const void* data, uint32_t length); void cli_hexdump2(const void* data, uint32_t length); void cli_hexdump_block(const void* data, uint32_t length, uint8_t indent, uint8_t width); +void cli_hexdump_byte(uint8_t byte); void echo_ctrl(char* s); int8_t cmd_interface(const cmdlist_entry_t* cmd_desc); diff --git a/test_src/main-sha512-test.c b/test_src/main-sha512-test.c new file mode 100644 index 0000000..df33fba --- /dev/null +++ b/test_src/main-sha512-test.c @@ -0,0 +1,204 @@ +/* main-sha512-test.c */ +/* + This file is part of the ARM-Crypto-Lib. + Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * SHA-512 test-suit + * +*/ + +#include "main-test-common.h" +#include "uart_lowlevel.h" + +#include "shavs.h" +#include "nessie_hash_test.h" +#include "performance_test.h" +#include "hfal-nessie.h" +#include "hfal-performance.h" +#include "hfal-test.h" + +#include "sha512.h" +#include "hfal_sha512.h" + +const char* algo_name = "SHA-512"; + +const hfdesc_t* algolist[] = { + (hfdesc_t*)&sha512_desc, + NULL +}; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ + +void testrun_nessie_sha512(void){ + hfal_nessie_multiple(algolist); +} + +void testrun_performance_sha512(void){ + hfal_performance_multiple(algolist); +} + +void simple_test(void){ + const char *msg = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + + uint8_t hash[64]; + sha512_ctx_t ctx; + cli_putstr("\r\nDBG: init ..."); uart_flush(0); + sha512_init(&ctx); + cli_putstr("\r\nDBG: init done"); uart_flush(0); + sha512_lastBlock(&ctx, msg, 3*8); + cli_putstr("\r\nDBG: lastBlock done"); uart_flush(0); + sha512_ctx2hash(hash, &ctx); + cli_putstr("\r\n hash = "); + cli_hexdump(hash, 64); + + + cli_putstr("\r\nDBG: init ..."); uart_flush(0); + sha512_init(&ctx); + cli_putstr("\r\nDBG: init done"); uart_flush(0); + sha512_lastBlock(&ctx, msg, 896); + cli_putstr("\r\nDBG: lastBlock done"); uart_flush(0); + sha512_ctx2hash(hash, &ctx); + cli_putstr("\r\n hash = "); + cli_hexdump(hash, 64); + + uint32_t c=0; + uint8_t buffer[128]; + memset(buffer, 'a', 128); + cli_putstr("\r\nDBG: init ..."); uart_flush(0); + sha512_init(&ctx); + cli_putstr("\r\nDBG: init done"); uart_flush(0); + do{ + sha512_nextBlock(&ctx, buffer); + c += 128; + }while(c+128<1000000L); + sha512_lastBlock(&ctx, buffer, (1000000-c)*8); + cli_putstr("\r\nDBG: lastBlock done"); uart_flush(0); + sha512_ctx2hash(hash, &ctx); + cli_putstr("\r\n hash = "); + cli_hexdump(hash, 64); + + +} + +/* +void test_monte(void){ + uint8_t data1[] = { + 0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39, + 0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3, + 0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99, + 0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7, + 0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39, + 0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3, + 0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99, + 0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7, + 0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39, + 0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3, + 0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99, + 0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7 }; + + uint8_t data2[] = { + 0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39, + 0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3, + 0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99, + 0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7, + 0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39, + 0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3, + 0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99, + 0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7, + 0xFD, 0xDF, 0x1B, 0x37, 0xDD, 0x34, 0xB3, 0xB2, + 0x01, 0xD4, 0x3C, 0x57, 0xBC, 0xDE, 0x11, 0x58, + 0x38, 0xF0, 0xDF, 0x70, 0x1D, 0xA9, 0x3C, 0x3B, + 0xF2, 0xC9, 0xC8, 0x68, 0x96, 0xE7, 0xE6, 0xC7 }; + uint8_t hash[SHA256_HASH_BYTES]; + sha256((sha256_hash_t*)hash, data1, 3*32*8); + cli_putstr("\r\n hash(data1) = "); + cli_hexdump(hash, 32); + sha256((sha256_hash_t*)hash, data2, 3*32*8); + cli_putstr("\r\n hash(data2) = "); + cli_hexdump(hash, 32); +} + +void test_monte2(void){ + uint8_t data[] = { + 0x6c, 0xd4, 0xc0, 0xc5, 0xcb, 0x2c, 0xa2, 0xa0, + 0xf1, 0xd1, 0xae, 0xce, 0xba, 0xc0, 0x3b, 0x52, + 0xe6, 0x4e, 0xa0, 0x3d, 0x1a, 0x16, 0x54, 0x37, + 0x29, 0x36, 0x54, 0x5b, 0x92, 0xbb, 0xc5, 0x48, + 0x4a, 0x59, 0xdb, 0x74, 0xbb, 0x60, 0xf9, 0xc4, + 0x0c, 0xeb, 0x1a, 0x5a, 0xa3, 0x5a, 0x6f, 0xaf, + 0xe8, 0x03, 0x49, 0xe1, 0x4c, 0x25, 0x3a, 0x4e, + 0x8b, 0x1d, 0x77, 0x61, 0x2d, 0xdd, 0x81, 0xac, + 0xe9, 0x26, 0xae, 0x8b, 0x0a, 0xf6, 0xe5, 0x31, + 0x76, 0xdb, 0xff, 0xcc, 0x2a, 0x6b, 0x88, 0xc6, + 0xbd, 0x76, 0x5f, 0x93, 0x9d, 0x3d, 0x17, 0x8a, + 0x9b, 0xde, 0x9e, 0xf3, 0xaa, 0x13, 0x1c, 0x61, + 0xe3, 0x1c, 0x1e, 0x42, 0xcd, 0xfa, 0xf4, 0xb4, + 0xdc, 0xde, 0x57, 0x9a, 0x37, 0xe1, 0x50, 0xef, + 0xbe, 0xf5, 0x55, 0x5b, 0x4c, 0x1c, 0xb4, 0x04, + 0x39, 0xd8, 0x35, 0xa7, 0x24, 0xe2, 0xfa, 0xe7 }; + + uint8_t hash[SHA256_HASH_BYTES]; + sha256((sha256_hash_t*)hash, data, 1024); + cli_putstr("\r\n hash(data) = "); + cli_hexdump(hash, 32); +} +*/ +/***************************************************************************** + * main * + *****************************************************************************/ + +const char nessie_str[] = "nessie"; +const char test_str[] = "test"; +//const char monte_str[] = "monte"; +//const char monte2_str[] = "monte2"; +const char performance_str[] = "performance"; +const char echo_str[] = "echo"; +const char shavs_list_str[] = "shavs_list"; +const char shavs_set_str[] = "shavs_set"; +const char shavs_test1_str[] = "shavs_test1"; +const char shavs_test2_str[] = "shavs_test2"; +const char shavs_test3_str[] = "shavs_test3"; +const char dump_str[] = "dump"; + +const cmdlist_entry_t cmdlist[] = { + { nessie_str, NULL, testrun_nessie_sha512 }, + { test_str, NULL, simple_test }, +// { monte_str, NULL, test_monte }, +// { monte2_str, NULL, test_monte2 }, + { performance_str, NULL, testrun_performance_sha512 }, + { echo_str, (void*)1, (void_fpt)echo_ctrl }, + { shavs_list_str, NULL, shavs_listalgos }, + { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo }, + { shavs_test1_str, NULL, shavs_test1 }, + { shavs_test2_str, NULL, shavs_test2 }, + { shavs_test3_str, NULL, shavs_test3 }, + { dump_str, (void*)1, (void_fpt)dump }, + { NULL, NULL, NULL } +}; + +int main(void) { + main_setup(); + + for(;;){ + welcome_msg(algo_name); + cmd_interface(cmdlist); + } + +} diff --git a/test_src/uart_i.c b/test_src/uart_i.c index 9fb5a89..1eb421e 100644 --- a/test_src/uart_i.c +++ b/test_src/uart_i.c @@ -266,3 +266,12 @@ uint32_t uart_dataavail(uint8_t uartno){ } return(HW_REG(uart_base[uartno]+UARTFR_OFFSET)&_BV(UART_RXFE))?0:1; } + + +void uart_flush(uint8_t uartno){ + if(uartno>UART_MAX){ + return; + } + while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0) + ; +} diff --git a/test_src/uart_lowlevel.c b/test_src/uart_lowlevel.c index 85c4d90..c0ea703 100644 --- a/test_src/uart_lowlevel.c +++ b/test_src/uart_lowlevel.c @@ -180,3 +180,11 @@ uint32_t uart_dataavail(uint8_t uartno){ /* wait while the FIFO is empty */ return(HW_REG(uart_base[uartno]+UARTFR_OFFSET)&_BV(UART_RXFE))?0:1; } + +void uart_flush(uint8_t uartno){ + if(uartno>UART_MAX){ + return; + } + while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0) + ; +} -- 2.39.5