From f835bbe3cc047a18d4a7ac68ca31286106161b9c Mon Sep 17 00:00:00 2001
From: Mirek Kratochvil <exa.exa@gmail.com>
Date: Tue, 25 Dec 2012 15:26:29 +0100
Subject: [PATCH] fmtseq structuralized

---
 src/fmtseq.cpp | 21 +++++++++++++++++++++
 src/fmtseq.h   | 37 +++++++++++++++++++++----------------
 src/hash.h     |  2 +-
 3 files changed, 43 insertions(+), 17 deletions(-)
 create mode 100644 src/fmtseq.cpp

diff --git a/src/fmtseq.cpp b/src/fmtseq.cpp
new file mode 100644
index 0000000..925dec3
--- /dev/null
+++ b/src/fmtseq.cpp
@@ -0,0 +1,21 @@
+
+/*
+ * This file is part of Codecrypt.
+ *
+ * Codecrypt is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Codecrypt 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Codecrypt. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fmtseq.h"
+
+
diff --git a/src/fmtseq.h b/src/fmtseq.h
index 97d478a..2c03201 100644
--- a/src/fmtseq.h
+++ b/src/fmtseq.h
@@ -19,6 +19,14 @@
 #ifndef _fmtseq_h_
 #define _fmtseq_h_
 
+#include <vector>
+#include <map>
+#include "types.h"
+#include "bvector.h"
+#include "sencode.h"
+#include "hash.h"
+#include "prng.h"
+
 /*
  * FMTseq - Merkle signatures with fractal tree traversal, using original
  * Lamport signatures for speed.
@@ -30,24 +38,23 @@ class privkey
 {
 public:
 	std::vector<char> SK; //secret key
-	uint h, l;
+	uint h, l; //l=level count, h=level height (root-leaf path length)
+	//therefore, H = h*l
 	uint sigs_used;
 
-	//FMT cache
-	std::vector<std::map<uint, std::vector<char> > > node_cache;
+	//FMT caches
+	std::vector<std::vector<char> > exist;
+	std::vector<std::vector<char> > desired;
+	std::vector<std::vector<char> > desired_stack;
 
 	int sign (const bvector&, bvector&, hash_func&);
 
 	uint sigs_remaining() {
-		return (1 << h) - sigs_used;
+		return (1 << () ) - sigs_used;
 	}
 
-	uint hash_size (hash_func&) {
-		hf.size();
-	}
-
-	uint signature_size (hash_func&) {
-		//TODO
+	uint hash_size (hash_func&hf) {
+		return hf.size() * 8;
 	}
 
 	sencode* serialize();
@@ -58,14 +65,12 @@ class pubkey
 {
 public:
 	std::vector<char> check; //tree top verification hash
-	uint h;
+	uint H;
 
-	uint hash_size() {
-		return hf.size();
-	}
+	int verify (const bvector&, const bvector&, hash_func&);
 
-	uint signature_size() {
-		//TODO
+	uint hash_size (hash_func&hf) {
+		return hf.size() * 8;
 	}
 
 	sencode* serialize();
diff --git a/src/hash.h b/src/hash.h
index d0a6e16..99af329 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -29,7 +29,7 @@ class hash_func
 {
 public:
 	virtual std::vector<char> operator() (const std::vector<char>&) = 0;
-	virtual uint size();
+	virtual uint size(); //in bytes
 };
 
 #endif