diff --git a/config.h b/config.h
index 60aaf4c..851388f 100644
--- a/config.h
+++ b/config.h
@@ -30,9 +30,13 @@
/* uart.[ch] defines */
#define UART_INTERRUPT 1
#define UART_BAUD_RATE 38400
-#define UART_RXBUFSIZE 16
-#define UART_TXBUFSIZE 16
+#define UART_RXBUFSIZE 64
+#define UART_TXBUFSIZE 64
#define UART_LINE_BUFFER_SIZE 40
+#define UART_XON_XOFF
+#define UART_XON_XOFF_THRESHOLD_1 (UART_RXBUFSIZE - 24)
+#define UART_XON_XOFF_THRESHOLD_2 (UART_RXBUFSIZE - 30)
+
#undef UART_LEDS
/*
#define UART_HWFLOWCONTROL
diff --git a/hfal_skein1024.c b/hfal_skein1024.c
new file mode 100644
index 0000000..485bed5
--- /dev/null
+++ b/hfal_skein1024.c
@@ -0,0 +1,162 @@
+/* hfal_skein1024.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein1024.c
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#include
+#include
+#include "hashfunction_descriptor.h"
+#include "skein.h"
+
+
+static const char skein1024_128_str[] PROGMEM = "Skein-1024-128";
+static const char skein1024_160_str[] PROGMEM = "Skein-1024-160";
+static const char skein1024_224_str[] PROGMEM = "Skein-1024-224";
+static const char skein1024_256_str[] PROGMEM = "Skein-1024-256";
+static const char skein1024_384_str[] PROGMEM = "Skein-1024-384";
+static const char skein1024_512_str[] PROGMEM = "Skein-1024-512";
+static const char skein1024_1024_str[] PROGMEM = "Skein-1024-1024";
+
+void skein1024_128_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 128);
+}
+void skein1024_160_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 160);
+}
+void skein1024_224_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 224);
+}
+void skein1024_256_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 256);
+}
+void skein1024_384_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 384);
+}
+void skein1024_512_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 512);
+}
+void skein1024_1024_init(skein1024_ctx_t* ctx){
+ skein1024_init(ctx, 1024);
+}
+
+const hfdesc_t skein1024_128_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_128_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 128,
+ (hf_init_fpt)skein1024_128_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_160_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_160_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 160,
+ (hf_init_fpt)skein1024_160_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_224_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_224_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 224,
+ (hf_init_fpt)skein1024_224_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_256_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_256_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 256,
+ (hf_init_fpt)skein1024_256_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_384_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_384_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 384,
+ (hf_init_fpt)skein1024_384_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_512_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_512_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 512,
+ (hf_init_fpt)skein1024_512_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein1024_1024_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein1024_1024_str,
+ sizeof(skein1024_ctx_t),
+ SKEIN1024_BLOCKSIZE,
+ 1024,
+ (hf_init_fpt)skein1024_1024_init,
+ (hf_nextBlock_fpt)skein1024_nextBlock,
+ (hf_lastBlock_fpt)skein1024_lastBlock,
+ (hf_ctx2hash_fpt)skein1024_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+
diff --git a/hfal_skein1024.h b/hfal_skein1024.h
new file mode 100644
index 0000000..e2ce083
--- /dev/null
+++ b/hfal_skein1024.h
@@ -0,0 +1,42 @@
+/* hfal_skein1024.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein1024.h
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#ifndef HFAL_SKEIN1024_H_
+#define HFAL_SKEIN1024_H_
+
+#include
+#include "hashfunction_descriptor.h"
+
+extern const hfdesc_t skein1024_128_desc;
+extern const hfdesc_t skein1024_160_desc;
+extern const hfdesc_t skein1024_224_desc;
+extern const hfdesc_t skein1024_256_desc;
+extern const hfdesc_t skein1024_384_desc;
+extern const hfdesc_t skein1024_512_desc;
+extern const hfdesc_t skein1024_1024_desc;
+
+#endif /* HFAL_SHA1024_H_ */
diff --git a/hfal_skein256.c b/hfal_skein256.c
new file mode 100644
index 0000000..c647e1e
--- /dev/null
+++ b/hfal_skein256.c
@@ -0,0 +1,143 @@
+/* hfal_skein256.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein256.c
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#include
+#include
+#include "hashfunction_descriptor.h"
+#include "skein.h"
+
+
+static const char skein256_128_str[] PROGMEM = "Skein-256-128";
+static const char skein256_160_str[] PROGMEM = "Skein-256-160";
+static const char skein256_224_str[] PROGMEM = "Skein-256-224";
+static const char skein256_256_str[] PROGMEM = "Skein-256-256";
+static const char skein256_384_str[] PROGMEM = "Skein-256-384";
+static const char skein256_512_str[] PROGMEM = "Skein-256-512";
+
+void skein256_128_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 128);
+}
+void skein256_160_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 160);
+}
+void skein256_224_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 224);
+}
+void skein256_256_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 256);
+}
+void skein256_384_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 384);
+}
+void skein256_512_init(skein256_ctx_t* ctx){
+ skein256_init(ctx, 512);
+}
+
+const hfdesc_t skein256_128_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_128_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 128,
+ (hf_init_fpt)skein256_128_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein256_160_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_160_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 160,
+ (hf_init_fpt)skein256_160_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein256_224_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_224_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 224,
+ (hf_init_fpt)skein256_224_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein256_256_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_256_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 256,
+ (hf_init_fpt)skein256_256_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein256_384_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_384_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 384,
+ (hf_init_fpt)skein256_384_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein256_512_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein256_512_str,
+ sizeof(skein256_ctx_t),
+ SKEIN256_BLOCKSIZE,
+ 512,
+ (hf_init_fpt)skein256_512_init,
+ (hf_nextBlock_fpt)skein256_nextBlock,
+ (hf_lastBlock_fpt)skein256_lastBlock,
+ (hf_ctx2hash_fpt)skein256_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
diff --git a/hfal_skein256.h b/hfal_skein256.h
new file mode 100644
index 0000000..1b0e34b
--- /dev/null
+++ b/hfal_skein256.h
@@ -0,0 +1,41 @@
+/* hfal_skein256.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein256.h
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#ifndef HFAL_SKEIN256_H_
+#define HFAL_SKEIN256_H_
+
+#include
+#include "hashfunction_descriptor.h"
+
+extern const hfdesc_t skein256_128_desc;
+extern const hfdesc_t skein256_160_desc;
+extern const hfdesc_t skein256_224_desc;
+extern const hfdesc_t skein256_256_desc;
+extern const hfdesc_t skein256_384_desc;
+extern const hfdesc_t skein256_512_desc;
+
+#endif /* HFAL_SHA256_H_ */
diff --git a/hfal_skein512.c b/hfal_skein512.c
new file mode 100644
index 0000000..f78bc6f
--- /dev/null
+++ b/hfal_skein512.c
@@ -0,0 +1,162 @@
+/* hfal_skein512.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein512.c
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#include
+#include
+#include "hashfunction_descriptor.h"
+#include "skein.h"
+
+
+static const char skein512_128_str[] PROGMEM = "Skein-512-128";
+static const char skein512_160_str[] PROGMEM = "Skein-512-160";
+static const char skein512_224_str[] PROGMEM = "Skein-512-224";
+static const char skein512_256_str[] PROGMEM = "Skein-512-256";
+static const char skein512_384_str[] PROGMEM = "Skein-512-384";
+static const char skein512_512_str[] PROGMEM = "Skein-512-512";
+static const char skein512_1024_str[] PROGMEM = "Skein-512-1024";
+
+void skein512_128_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 128);
+}
+void skein512_160_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 160);
+}
+void skein512_224_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 224);
+}
+void skein512_256_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 256);
+}
+void skein512_384_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 384);
+}
+void skein512_512_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 512);
+}
+void skein512_1024_init(skein512_ctx_t* ctx){
+ skein512_init(ctx, 1024);
+}
+
+const hfdesc_t skein512_128_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_128_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 128,
+ (hf_init_fpt)skein512_128_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_160_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_160_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 160,
+ (hf_init_fpt)skein512_160_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_224_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_224_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 224,
+ (hf_init_fpt)skein512_224_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_256_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_256_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 256,
+ (hf_init_fpt)skein512_256_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_384_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_384_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 384,
+ (hf_init_fpt)skein512_384_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_512_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_512_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 512,
+ (hf_init_fpt)skein512_512_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+const hfdesc_t skein512_1024_desc PROGMEM = {
+ HFDESC_TYPE_HASHFUNCTION,
+ 0,
+ skein512_1024_str,
+ sizeof(skein512_ctx_t),
+ SKEIN512_BLOCKSIZE,
+ 1024,
+ (hf_init_fpt)skein512_1024_init,
+ (hf_nextBlock_fpt)skein512_nextBlock,
+ (hf_lastBlock_fpt)skein512_lastBlock,
+ (hf_ctx2hash_fpt)skein512_ctx2hash,
+ (hf_free_fpt)NULL,
+ (hf_mem_fpt)NULL
+};
+
diff --git a/hfal_skein512.h b/hfal_skein512.h
new file mode 100644
index 0000000..52fe48f
--- /dev/null
+++ b/hfal_skein512.h
@@ -0,0 +1,42 @@
+/* hfal_skein512.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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_skein512.h
+ * \email daniel.otte@rub.de
+ * \author Daniel Otte
+ * \date 2009-03-13
+ * \license GPLv3 or later
+ *
+ */
+
+#ifndef HFAL_SKEIN512_H_
+#define HFAL_SKEIN512_H_
+
+#include
+#include "hashfunction_descriptor.h"
+
+extern const hfdesc_t skein512_128_desc;
+extern const hfdesc_t skein512_160_desc;
+extern const hfdesc_t skein512_224_desc;
+extern const hfdesc_t skein512_256_desc;
+extern const hfdesc_t skein512_384_desc;
+extern const hfdesc_t skein512_512_desc;
+extern const hfdesc_t skein512_1024_desc;
+
+#endif /* HFAL_SHA512_H_ */
diff --git a/host/shavs_test.rb b/host/shavs_test.rb
index 3983b50..7670543 100644
--- a/host/shavs_test.rb
+++ b/host/shavs_test.rb
@@ -18,7 +18,7 @@
along with this program. If not, see .
=end
-
+$debug = false
require 'serialport'
@@ -29,7 +29,7 @@ def init_system
# print("DBG 0.0: ")
# print(line)
# sleep 1
- $sp.print("shavs_set a \r")
+ $sp.print("shavs_set #{$algo_select} \r")
# line = $sp.readlines()
# print("DBG 0.1: ")
# print(line)
@@ -44,7 +44,7 @@ def get_md
begin
line = $sp.gets()
line = "" if line==nil
-# puts("DBG g: "+line)
+ puts("DBG g: "+line) if $debug
end while not /[\s]*MD[\s]*=.*/.match(line)
return line
end
@@ -59,7 +59,7 @@ def run_test(filename)
begin
lb=file.gets()
end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
-# puts("DBG sending: "+lb);
+ puts("DBG sending: "+lb) if $debug
return if file.eof
$sp.print(lb.strip)
$sp.print("\r")
@@ -67,7 +67,7 @@ def run_test(filename)
lb=file.gets()
end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
return if file.eof
-# puts("DBG sending: "+lb);
+ puts("DBG sending: "+lb) if $debug
$sp.print(lb.strip)
avr_md = get_md()
begin
@@ -84,9 +84,9 @@ def run_test(filename)
end
-if ARGV.size < 5
+if ARGV.size < 6
STDERR.print <ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
}
-void skein1024_nextBlock(skein1024_ctx_t* ctx, void* block){
+void skein1024_nextBlock(skein1024_ctx_t* ctx, const void* block){
ubi1024_nextBlock(&(ctx->ubictx), block);
}
-void skein1024_lastBlock(skein1024_ctx_t* ctx, void* block, uint16_t length_b){
+void skein1024_lastBlock(skein1024_ctx_t* ctx, const void* block, uint16_t length_b){
ubi1024_lastBlock(&(ctx->ubictx), block, length_b);
}
@@ -64,13 +64,13 @@ void skein1024_ctx2hash(void* dest, skein1024_ctx_t* ctx){
ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
outsize_b = ctx->outsize_b;
- while(outsize_b){
+ while(1){
memcpy(&uctx, &(ctx->ubictx), sizeof(ubi1024_ctx_t));
ubi1024_lastBlock(&uctx, &counter, 64);
ubi1024_ctx2hash(outbuffer, &uctx);
- if(outsize_b<=UBI1024_BLOCKSIZE_B){
+ if(outsize_b<=UBI1024_BLOCKSIZE){
memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
- outsize_b=0;
+ break;
}else{
memcpy(dest, outbuffer, UBI1024_BLOCKSIZE_B);
dest = (uint8_t*)dest + UBI1024_BLOCKSIZE_B;
@@ -80,3 +80,14 @@ void skein1024_ctx2hash(void* dest, skein1024_ctx_t* ctx){
}
}
+void skein1024(void* dest, uint16_t outlength_b, const void* msg, uint32_t length_b){
+ skein1024_ctx_t ctx;
+ skein1024_init(&ctx, outlength_b);
+ while(length_b>SKEIN1024_BLOCKSIZE){
+ skein1024_nextBlock(&ctx, msg);
+ msg = (uint8_t*)msg + SKEIN1024_BLOCKSIZE_B;
+ length_b -= SKEIN1024_BLOCKSIZE;
+ }
+ skein1024_lastBlock(&ctx, msg, length_b);
+ skein1024_ctx2hash(dest, &ctx);
+}
diff --git a/skein256.c b/skein256.c
index f397415..dfe6ef3 100644
--- a/skein256.c
+++ b/skein256.c
@@ -29,6 +29,7 @@
#include "ubi.h"
#include "skein.h"
+#include "cli.h"
void skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b){
skein_config_t conf;
@@ -47,11 +48,11 @@ void skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b){
ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
}
-void skein256_nextBlock(skein256_ctx_t* ctx, void* block){
+void skein256_nextBlock(skein256_ctx_t* ctx, const void* block){
ubi256_nextBlock(&(ctx->ubictx), block);
}
-void skein256_lastBlock(skein256_ctx_t* ctx, void* block, uint16_t length_b){
+void skein256_lastBlock(skein256_ctx_t* ctx, const void* block, uint16_t length_b){
ubi256_lastBlock(&(ctx->ubictx), block, length_b);
}
@@ -64,13 +65,13 @@ void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx){
ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
outsize_b = ctx->outsize_b;
- while(outsize_b){
+ while(1){
memcpy(&uctx, &(ctx->ubictx), sizeof(ubi256_ctx_t));
ubi256_lastBlock(&uctx, &counter, 64);
ubi256_ctx2hash(outbuffer, &uctx);
- if(outsize_b<=UBI256_BLOCKSIZE_B){
- memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
- outsize_b=0;
+ if(outsize_b<=UBI256_BLOCKSIZE){
+ memcpy(dest, outbuffer, (outsize_b+7)/8);
+ break;
}else{
memcpy(dest, outbuffer, UBI256_BLOCKSIZE_B);
dest = (uint8_t*)dest + UBI256_BLOCKSIZE_B;
@@ -80,4 +81,14 @@ void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx){
}
}
-
+void skein256(void* dest, uint16_t outlength_b,const void* msg, uint32_t length_b){
+ skein256_ctx_t ctx;
+ skein256_init(&ctx, outlength_b);
+ while(length_b>SKEIN256_BLOCKSIZE){
+ skein256_nextBlock(&ctx, msg);
+ msg = (uint8_t*)msg + SKEIN256_BLOCKSIZE_B;
+ length_b -= SKEIN256_BLOCKSIZE;
+ }
+ skein256_lastBlock(&ctx, msg, length_b);
+ skein256_ctx2hash(dest, &ctx);
+}
diff --git a/skein512.c b/skein512.c
index 8603575..2558f34 100644
--- a/skein512.c
+++ b/skein512.c
@@ -47,11 +47,11 @@ void skein512_init(skein512_ctx_t* ctx, uint16_t outsize_b){
ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
}
-void skein512_nextBlock(skein512_ctx_t* ctx, void* block){
+void skein512_nextBlock(skein512_ctx_t* ctx, const void* block){
ubi512_nextBlock(&(ctx->ubictx), block);
}
-void skein512_lastBlock(skein512_ctx_t* ctx, void* block, uint16_t length_b){
+void skein512_lastBlock(skein512_ctx_t* ctx, const void* block, uint16_t length_b){
ubi512_lastBlock(&(ctx->ubictx), block, length_b);
}
@@ -64,13 +64,13 @@ void skein512_ctx2hash(void* dest, skein512_ctx_t* ctx){
ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
outsize_b = ctx->outsize_b;
- while(outsize_b){
+ while(1){
memcpy(&uctx, &(ctx->ubictx), sizeof(ubi512_ctx_t));
ubi512_lastBlock(&uctx, &counter, 64);
ubi512_ctx2hash(outbuffer, &uctx);
- if(outsize_b<=UBI512_BLOCKSIZE_B){
+ if(outsize_b<=UBI512_BLOCKSIZE){
memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
- outsize_b=0;
+ break;
}else{
memcpy(dest, outbuffer, UBI512_BLOCKSIZE_B);
dest = (uint8_t*)dest + UBI512_BLOCKSIZE_B;
@@ -80,3 +80,15 @@ void skein512_ctx2hash(void* dest, skein512_ctx_t* ctx){
}
}
+void skein512(void* dest, uint16_t outlength_b,const void* msg, uint32_t length_b){
+ skein512_ctx_t ctx;
+ skein512_init(&ctx, outlength_b);
+ while(length_b>SKEIN512_BLOCKSIZE){
+ skein512_nextBlock(&ctx, msg);
+ msg = (uint8_t*)msg + SKEIN512_BLOCKSIZE_B;
+ length_b -= SKEIN512_BLOCKSIZE;
+ }
+ skein512_lastBlock(&ctx, msg, length_b);
+ skein512_ctx2hash(dest, &ctx);
+}
+
diff --git a/test_src/main-skein-test.c b/test_src/main-skein-test.c
index 7faaa68..aa68950 100644
--- a/test_src/main-skein-test.c
+++ b/test_src/main-skein-test.c
@@ -27,7 +27,11 @@
#include "debug.h"
#include "skein.h"
+#include "hfal_skein256.h"
+#include "hfal_skein512.h"
+#include "hfal_skein1024.h"
#include "cli.h"
+#include "shavs.h"
#include "performance_test.h"
#include
@@ -43,33 +47,23 @@ void testrun_stdtest_skein256(uint16_t outsize_b){
uint8_t message[64];
uint8_t hash[(outsize_b+7)/8];
uint8_t i;
- skein256_ctx_t ctx;
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
for(i=0; i<64; ++i)
message[i] = 0xFF-i;
cli_putstr_P(PSTR("\r\nmessage: "));
- cli_hexdump(message, 1);
- skein256_init(&ctx, outsize_b);
- skein256_lastBlock(&ctx, message, 8);
- skein256_ctx2hash(hash, &ctx);
+ skein256(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(message, 32, 4, 16);
- skein256_init(&ctx, outsize_b);
- skein256_lastBlock(&ctx, message, 32*8);
- skein256_ctx2hash(hash, &ctx);
+ skein256(hash, outsize_b, message, 32*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(message, 64, 4, 16);
- skein256_init(&ctx, outsize_b);
- skein256_lastBlock(&ctx, message, 64*8);
- skein256_ctx2hash(hash, &ctx);
+ skein256(hash, outsize_b, message, 64*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
}
@@ -78,7 +72,6 @@ void testrun_stdtest_skein512(uint16_t outsize_b){
uint8_t message[128];
uint8_t hash[(outsize_b+7)/8];
uint8_t i;
- skein512_ctx_t ctx;
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
for(i=0; i<128; ++i)
@@ -86,25 +79,17 @@ void testrun_stdtest_skein512(uint16_t outsize_b){
cli_putstr_P(PSTR("\r\nmessage: "));
cli_hexdump(message, 1);
- skein512_init(&ctx, outsize_b);
- skein512_lastBlock(&ctx, message, 8);
- skein512_ctx2hash(hash, &ctx);
+ skein512(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(message, 64, 4, 16);
- skein512_init(&ctx, outsize_b);
- skein512_lastBlock(&ctx, message, 64*8);
- skein512_ctx2hash(hash, &ctx);
+ skein512(hash, outsize_b, message, 64*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(message, 128, 4, 16);
- skein512_init(&ctx, outsize_b);
- skein512_lastBlock(&ctx, message, 128*8);
- skein512_ctx2hash(hash, &ctx);
+ skein512(hash, outsize_b, message, 128*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
}
@@ -113,7 +98,6 @@ void testrun_stdtest_skein1024(uint16_t outsize_b){
uint8_t message[256];
uint8_t hash[(outsize_b+7)/8];
uint16_t i;
- skein1024_ctx_t ctx;
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
for(i=0; i<256; ++i)
@@ -121,25 +105,18 @@ void testrun_stdtest_skein1024(uint16_t outsize_b){
cli_putstr_P(PSTR("\r\nmessage: "));
cli_hexdump(message, 1);
- skein1024_init(&ctx, outsize_b);
- skein1024_lastBlock(&ctx, message, 8);
- skein1024_ctx2hash(hash, &ctx);
+ skein1024(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(message, 128, 4, 16);
- skein1024_init(&ctx, outsize_b);
- skein1024_lastBlock(&ctx, message, 128*8);
- skein1024_ctx2hash(hash, &ctx);
+ skein1024(hash, outsize_b, message, 128*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 256, 4, 16);
- skein1024_init(&ctx, outsize_b);
- skein1024_lastBlock(&ctx, message, 256*8);
- skein1024_ctx2hash(hash, &ctx);
+ skein1024(hash, outsize_b, message, 256*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
}
@@ -149,127 +126,96 @@ void testrun_stdtest_skein(void){
testrun_stdtest_skein512(512);
testrun_stdtest_skein1024(1024);
}
-/*
-void testrun_performance_threefish256(void){
- uint64_t t;
- char str[16];
- uint8_t key[THREEFISH256_BLOCKSIZE_B];
- uint8_t data[THREEFISH256_BLOCKSIZE_B];
- uint8_t tweak[16];
- threefish256_ctx_t ctx;
+
+void zeromsg_test_skein(uint16_t outsize_b){
+ char str[8];
+ uint8_t hash[(outsize_b+7)/8];
- cli_putstr_P(PSTR("\r\nThreefish-256 performance:"));
+ skein256(hash, outsize_b, NULL, 0);
+ cli_putstr_P(PSTR("\r\nskein256-"));
+ utoa(outsize_b, str, 10);
+ cli_putstr(str);
+ cli_putstr_P(PSTR(" :"));
+ cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
- calibrateTimer();
- print_overhead();
+ skein512(hash, outsize_b, NULL, 0);
+ cli_putstr_P(PSTR("\r\nskein512-"));
+ utoa(outsize_b, str, 10);
+ cli_putstr(str);
+ cli_putstr_P(PSTR(" :"));
+ cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-// memset(key, 0, THREEFISH256_BLOCKSIZE_B);
-// memset(tweak, 0, 16);
-
- startTimer(1);
- threefish256_init(key, tweak, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- threefish256_enc(data, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tencrypt time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- cli_putstr_P(PSTR("\r\n"));
+ skein1024(hash, outsize_b, NULL, 0);
+ cli_putstr_P(PSTR("\r\nskein1024-"));
+ utoa(outsize_b, str, 10);
+ cli_putstr(str);
+ cli_putstr_P(PSTR(" :"));
+ cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
}
-void testrun_performance_threefish512(void){
- uint64_t t;
- char str[16];
- uint8_t key[THREEFISH512_BLOCKSIZE_B];
- uint8_t data[THREEFISH512_BLOCKSIZE_B];
- uint8_t tweak[16];
- threefish512_ctx_t ctx;
-
- cli_putstr_P(PSTR("\r\nThreefish-512 performance:"));
-
- calibrateTimer();
- print_overhead();
-
-// memset(key, 0, THREEFISH512_BLOCKSIZE_B);
-// memset(tweak, 0, 16);
-
- startTimer(1);
- threefish512_init(key, tweak, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- threefish512_enc(data, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tencrypt time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- cli_putstr_P(PSTR("\r\n"));
+void zeromsg_test_common(char* p){
+ uint8_t i;
+ uint16_t s=0;
+ uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
+ if(p){
+ s = strtoul(p, NULL, 0);
+ }
+ if(s){
+ zeromsg_test_skein(s);
+ }else{
+ for(i=0; i<7; ++i)
+ zeromsg_test_skein(sizes[i]);
+ }
}
-void testrun_performance_threefish1024(void){
- uint64_t t;
- char str[16];
- uint8_t key[THREEFISH1024_BLOCKSIZE_B];
- uint8_t data[THREEFISH1024_BLOCKSIZE_B];
- uint8_t tweak[16];
- threefish1024_ctx_t ctx;
-
- cli_putstr_P(PSTR("\r\nThreefish-1024 performance:"));
-
- calibrateTimer();
- print_overhead();
-
-// memset(key, 0, THREEFISH1024_BLOCKSIZE_B);
-// memset(tweak, 0, 16);
-
- startTimer(1);
- threefish1024_init(key, tweak, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- threefish1024_enc(data, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tencrypt time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- cli_putstr_P(PSTR("\r\n"));
-}
-
-void testrun_performance_threefish(void){
- testrun_performance_threefish256();
- testrun_performance_threefish512();
- testrun_performance_threefish1024();
-}
-*/
/*****************************************************************************
* main *
*****************************************************************************/
+const hfdesc_t* algolist[] PROGMEM = {
+ (hfdesc_t*)&skein256_128_desc,
+ (hfdesc_t*)&skein256_160_desc,
+ (hfdesc_t*)&skein256_224_desc,
+ (hfdesc_t*)&skein256_256_desc,
+ (hfdesc_t*)&skein256_384_desc,
+ (hfdesc_t*)&skein256_512_desc,
+
+ (hfdesc_t*)&skein512_128_desc,
+ (hfdesc_t*)&skein512_160_desc,
+ (hfdesc_t*)&skein512_224_desc,
+ (hfdesc_t*)&skein512_256_desc,
+ (hfdesc_t*)&skein512_384_desc,
+ (hfdesc_t*)&skein512_512_desc,
+ (hfdesc_t*)&skein512_1024_desc,
+
+ (hfdesc_t*)&skein1024_128_desc,
+ (hfdesc_t*)&skein1024_160_desc,
+ (hfdesc_t*)&skein1024_224_desc,
+ (hfdesc_t*)&skein1024_256_desc,
+ (hfdesc_t*)&skein1024_384_desc,
+ (hfdesc_t*)&skein1024_512_desc,
+ (hfdesc_t*)&skein1024_1024_desc,
+ NULL
+};
+
const char nessie_str[] PROGMEM = "nessie";
const char test_str[] PROGMEM = "test";
+const char ztest_str[] PROGMEM = "zerotest";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
+const char shavs_list_str[] PROGMEM = "shavs_list";
+const char shavs_set_str[] PROGMEM = "shavs_set";
+const char shavs_test1_str[] PROGMEM = "shavs_test1";
cmdlist_entry_t cmdlist[] PROGMEM = {
// { nessie_str, NULL, testrun_nessie_noekeon},
- { test_str, NULL, testrun_stdtest_skein},
-// { performance_str, NULL, testrun_performance_threefish},
- { echo_str, (void*)1, (void_fpt)echo_ctrl},
- { NULL, NULL, NULL}
+ { test_str, NULL, testrun_stdtest_skein},
+ { ztest_str, (void*)1, (void_fpt)zeromsg_test_common},
+ { shavs_list_str, NULL, shavs_listalgos},
+ { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
+ { shavs_test1_str, NULL, shavs_test1},
+ { echo_str, (void*)1, (void_fpt)echo_ctrl},
+ { NULL, NULL, NULL}
};
int main (void){
@@ -277,6 +223,8 @@ int main (void){
cli_rx = uart_getc;
cli_tx = uart_putc;
+ shavs_algolist=(hfdesc_t**)algolist;
+ shavs_algo=(hfdesc_t*)&skein256_256_desc;
for(;;){
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
cli_putstr(algo_name);
diff --git a/test_src/shavs.c b/test_src/shavs.c
index c651861..48d9133 100644
--- a/test_src/shavs.c
+++ b/test_src/shavs.c
@@ -88,6 +88,7 @@ void shavs_setalgo(char* param){
static uint16_t buffer_idx=0;
static uint8_t in_byte=0;
+static uint16_t blocks=0;
static uint8_t* buffer;
static uint16_t buffersize_B;
static hfgen_ctx_t ctx;
@@ -95,6 +96,12 @@ static hfgen_ctx_t ctx;
static
uint8_t buffer_add(char c){
uint8_t v,t;
+ if(buffer_idx==buffersize_B){
+ hfal_hash_nextBlock(&ctx, buffer);
+ ++blocks;
+ buffer_idx=0;
+ in_byte=0;
+ }
if(c>='0' && c<='9'){
v=c-'0';
}else{
@@ -106,13 +113,7 @@ uint8_t buffer_add(char c){
}else{
return 1;
}
- }
-
- }
- if(buffer_idx==buffersize_B){
- hfal_hash_nextBlock(&ctx, buffer);
- buffer_idx=0;
- in_byte=0;
+ }
}
t=buffer[buffer_idx];
@@ -133,8 +134,8 @@ void shavs_test1(void){
char* len2;
uint32_t length=0;
uint8_t len_set=0;
- if(!shavs_algo){
- cli_putstr_P(PSTR("\r\nERROR: select algorithm first!"));
+ if(!shavs_algo){
+ cli_putstr_P(PSTR("\r\nERROR: select algorithm first!"));
return;
}
@@ -142,6 +143,7 @@ void shavs_test1(void){
buffer = malloc(buffersize_B);
for(;;){
+ blocks = 0;
do{
cli_putstr_P(PSTR("\r\n"));
cli_getsn(lenstr, 20);
@@ -156,11 +158,12 @@ void shavs_test1(void){
}
} else {
if(!strncasecmp_P(len2, PSTR("EXIT"), 4)){
+ free(buffer);
return;
}
}
}while(!len_set);
- volatile int16_t expect_input;
+ volatile int32_t expect_input;
char c;
if(length==0){
@@ -172,7 +175,7 @@ void shavs_test1(void){
buffer_idx = 0;
in_byte=0;
len_set = 0;
-
+
hfal_hash_init(shavs_algo, &ctx);
cli_putstr_P(PSTR("\r\n"));
while((c=cli_getc_cecho())!='M' && c!='m'){
@@ -180,20 +183,24 @@ void shavs_test1(void){
cli_putstr_P(PSTR("\r\nERROR: wrong input (1) [0x"));
cli_hexdump(&c, 1);
cli_putstr_P(PSTR("]!\r\n"));
+ free(buffer);
return;
}
}
if((c=cli_getc_cecho())!='s' && c!='S'){
cli_putstr_P(PSTR("\r\nERROR: wrong input (2)!\r\n"));
+ free(buffer);
return;
}
if((c=cli_getc_cecho())!='g' && c!='G'){
cli_putstr_P(PSTR("\r\nERROR: wrong input (3)!\r\n"));
+ free(buffer);
return;
}
while((c=cli_getc_cecho())!='='){
if(!isblank(c)){
cli_putstr_P(PSTR("\r\nERROR: wrong input (4)!\r\n"));
+ free(buffer);
return;
}
}
@@ -202,27 +209,25 @@ void shavs_test1(void){
while(expect_input>0){
c=cli_getc_cecho();
if(buffer_add(c)==0){
- --expect_input;
+ --expect_input;
}else{
if(!isblank((uint16_t)c)){
cli_putstr_P(PSTR("\r\nERROR: wrong input (5) ("));
cli_putc(c);
cli_putstr_P(PSTR(")!\r\n"));
+ free(buffer);
return;
}
}
}
-
uint8_t diggest[pgm_read_word(shavs_algo->hashsize_b)/8];
- if(length && length%(buffersize_B*8)==0)
- hfal_hash_nextBlock(&ctx, buffer);
- hfal_hash_lastBlock(&ctx, buffer, length%(buffersize_B*8));
+ hfal_hash_lastBlock(&ctx, buffer, length-blocks*(buffersize_B*8));
hfal_hash_ctx2hash(diggest, &ctx);
hfal_hash_free(&ctx);
cli_putstr_P(PSTR("\r\n MD = "));
cli_hexdump(diggest, pgm_read_word(&(shavs_algo->hashsize_b))/8);
}
-
+ free(buffer);
}
diff --git a/ubi.h b/ubi.h
index 582a54e..1471881 100644
--- a/ubi.h
+++ b/ubi.h
@@ -63,20 +63,20 @@ typedef struct{
uint8_t g[128];
}ubi1024_ctx_t;
-void ubi256_init(ubi256_ctx_t* ctx, void* g, uint8_t type);
-void ubi256_nextBlock(ubi256_ctx_t* ctx, void* block);
-void ubi256_lastBlock(ubi256_ctx_t* ctx, void* block, uint16_t length_b);
-void ubi256_ctx2hash(void* dest, ubi256_ctx_t* ctx);
+void ubi256_init(ubi256_ctx_t* ctx, const void* g, uint8_t type);
+void ubi256_nextBlock(ubi256_ctx_t* ctx, const void* block);
+void ubi256_lastBlock(ubi256_ctx_t* ctx, const void* block, uint16_t length_b);
+void ubi256_ctx2hash(void* dest, const ubi256_ctx_t* ctx);
-void ubi512_init(ubi512_ctx_t* ctx, void* g, uint8_t type);
-void ubi512_nextBlock(ubi512_ctx_t* ctx, void* block);
-void ubi512_lastBlock(ubi512_ctx_t* ctx, void* block, uint16_t length_b);
-void ubi512_ctx2hash(void* dest, ubi512_ctx_t* ctx);
+void ubi512_init(ubi512_ctx_t* ctx, const void* g, uint8_t type);
+void ubi512_nextBlock(ubi512_ctx_t* ctx, const void* block);
+void ubi512_lastBlock(ubi512_ctx_t* ctx, const void* block, uint16_t length_b);
+void ubi512_ctx2hash(void* dest, const ubi512_ctx_t* ctx);
-void ubi1024_init(ubi1024_ctx_t* ctx, void* g, uint8_t type);
-void ubi1024_nextBlock(ubi1024_ctx_t* ctx, void* block);
-void ubi1024_lastBlock(ubi1024_ctx_t* ctx, void* block, uint16_t length_b);
-void ubi1024_ctx2hash(void* dest, ubi1024_ctx_t* ctx);
+void ubi1024_init(ubi1024_ctx_t* ctx, const void* g, uint8_t type);
+void ubi1024_nextBlock(ubi1024_ctx_t* ctx, const void* block);
+void ubi1024_lastBlock(ubi1024_ctx_t* ctx, const void* block, uint16_t length_b);
+void ubi1024_ctx2hash(void* dest, const ubi1024_ctx_t* ctx);
typedef struct{
char schema[4];
diff --git a/ubi1024.c b/ubi1024.c
index 6287e68..ae17cb3 100644
--- a/ubi1024.c
+++ b/ubi1024.c
@@ -30,13 +30,13 @@
#include "memxor.h"
#include "ubi.h"
-void ubi1024_init(ubi1024_ctx_t* ctx, void* g, uint8_t type){
+void ubi1024_init(ubi1024_ctx_t* ctx, const void* g, uint8_t type){
memset(ctx->tweak, 0, 15);
ctx->tweak[15] = 0x40+type;
memcpy(ctx->g, g, UBI1024_BLOCKSIZE_B);
}
-void ubi1024_nextBlock(ubi1024_ctx_t* ctx, void* block){
+void ubi1024_nextBlock(ubi1024_ctx_t* ctx, const void* block){
threefish1024_ctx_t tfctx;
((uint64_t*)(ctx->tweak))[0] += UBI1024_BLOCKSIZE_B;
threefish1024_init(ctx->g, ctx->tweak, &tfctx);
@@ -47,7 +47,7 @@ void ubi1024_nextBlock(ubi1024_ctx_t* ctx, void* block){
}
-void ubi1024_lastBlock(ubi1024_ctx_t* ctx, void* block, uint16_t length_b){
+void ubi1024_lastBlock(ubi1024_ctx_t* ctx, const void* block, uint16_t length_b){
threefish1024_ctx_t tfctx;
while(length_b>UBI1024_BLOCKSIZE){
ubi1024_nextBlock(ctx, block);
@@ -65,9 +65,12 @@ void ubi1024_lastBlock(ubi1024_ctx_t* ctx, void* block, uint16_t length_b){
ctx->g[(length_b+7)/8-1] |= 0x80>>(length_b&7);
threefish1024_enc(ctx->g, &tfctx);
memxor(ctx->g, block, (length_b+7)/8);
+ if(length_b & 0x07){
+ ctx->g[((length_b+7)/8)-1] ^= 0x80>>(length_b&7);
+ }
}
-void ubi1024_ctx2hash(void* dest, ubi1024_ctx_t* ctx){
+void ubi1024_ctx2hash(void* dest, const ubi1024_ctx_t* ctx){
memcpy(dest, ctx->g, UBI1024_BLOCKSIZE_B);
}
diff --git a/ubi256.c b/ubi256.c
index 8adfda8..09eb1e9 100644
--- a/ubi256.c
+++ b/ubi256.c
@@ -30,13 +30,13 @@
#include "memxor.h"
#include "ubi.h"
-void ubi256_init(ubi256_ctx_t* ctx, void* g, uint8_t type){
+void ubi256_init(ubi256_ctx_t* ctx, const void* g, uint8_t type){
memset(ctx->tweak, 0, 15);
ctx->tweak[15] = 0x40+type;
memcpy(ctx->g, g, 32);
}
-void ubi256_nextBlock(ubi256_ctx_t* ctx, void* block){
+void ubi256_nextBlock(ubi256_ctx_t* ctx, const void* block){
threefish256_ctx_t tfctx;
((uint64_t*)(ctx->tweak))[0] += UBI256_BLOCKSIZE_B;
threefish256_init(ctx->g, ctx->tweak, &tfctx);
@@ -47,7 +47,7 @@ void ubi256_nextBlock(ubi256_ctx_t* ctx, void* block){
}
-void ubi256_lastBlock(ubi256_ctx_t* ctx, void* block, uint16_t length_b){
+void ubi256_lastBlock(ubi256_ctx_t* ctx, const void* block, uint16_t length_b){
threefish256_ctx_t tfctx;
while(length_b>UBI256_BLOCKSIZE){
ubi256_nextBlock(ctx, block);
@@ -56,18 +56,25 @@ void ubi256_lastBlock(ubi256_ctx_t* ctx, void* block, uint16_t length_b){
}
ctx->tweak[15] |= 0x80;
((uint64_t*)(ctx->tweak))[0] += (length_b+7)/8;
- if(length_b & 0x07)
+ if(length_b & 0x07){
ctx->tweak[14] |= 0x80;
+ }
threefish256_init(ctx->g, ctx->tweak, &tfctx);
memset(ctx->g, 0, UBI256_BLOCKSIZE_B);
memcpy(ctx->g, block, (length_b+7)/8);
- if(length_b & 0x07)
- ctx->g[(length_b+7)/8-1] |= 0x80>>(length_b&7);
+ if(length_b & 0x07){
+ ctx->g[((length_b+7)/8)-1] |= 0x80>>(length_b&7);
+ ctx->g[((length_b+7)/8)-1] &= ~((0x80>>(length_b&7))-1);
+ }
threefish256_enc(ctx->g, &tfctx);
memxor(ctx->g, block, (length_b+7)/8);
+ if(length_b & 0x07){
+ ctx->g[((length_b+7)/8)-1] ^= 0x80>>(length_b&7);
+ }
+
}
-void ubi256_ctx2hash(void* dest, ubi256_ctx_t* ctx){
+void ubi256_ctx2hash(void* dest, const ubi256_ctx_t* ctx){
memcpy(dest, ctx->g, UBI256_BLOCKSIZE_B);
}
diff --git a/ubi512.c b/ubi512.c
index c5e6f51..d6bab2d 100644
--- a/ubi512.c
+++ b/ubi512.c
@@ -30,13 +30,13 @@
#include "memxor.h"
#include "ubi.h"
-void ubi512_init(ubi512_ctx_t* ctx, void* g, uint8_t type){
+void ubi512_init(ubi512_ctx_t* ctx, const void* g, uint8_t type){
memset(ctx->tweak, 0, 15);
ctx->tweak[15] = 0x40+type;
memcpy(ctx->g, g, UBI512_BLOCKSIZE_B);
}
-void ubi512_nextBlock(ubi512_ctx_t* ctx, void* block){
+void ubi512_nextBlock(ubi512_ctx_t* ctx, const void* block){
threefish512_ctx_t tfctx;
((uint64_t*)(ctx->tweak))[0] += UBI512_BLOCKSIZE_B;
threefish512_init(ctx->g, ctx->tweak, &tfctx);
@@ -47,7 +47,7 @@ void ubi512_nextBlock(ubi512_ctx_t* ctx, void* block){
}
-void ubi512_lastBlock(ubi512_ctx_t* ctx, void* block, uint16_t length_b){
+void ubi512_lastBlock(ubi512_ctx_t* ctx, const void* block, uint16_t length_b){
threefish512_ctx_t tfctx;
while(length_b>UBI512_BLOCKSIZE){
ubi512_nextBlock(ctx, block);
@@ -65,9 +65,12 @@ void ubi512_lastBlock(ubi512_ctx_t* ctx, void* block, uint16_t length_b){
ctx->g[(length_b+7)/8-1] |= 0x80>>(length_b&7);
threefish512_enc(ctx->g, &tfctx);
memxor(ctx->g, block, (length_b+7)/8);
+ if(length_b & 0x07){
+ ctx->g[((length_b+7)/8)-1] ^= 0x80>>(length_b&7);
+ }
}
-void ubi512_ctx2hash(void* dest, ubi512_ctx_t* ctx){
+void ubi512_ctx2hash(void* dest, const ubi512_ctx_t* ctx){
memcpy(dest, ctx->g, UBI512_BLOCKSIZE_B);
}