From 24bd5bd185ff4264c80389a40149a7e8ca7baa37 Mon Sep 17 00:00:00 2001
From: Mirek Kratochvil <exa.exa@gmail.com>
Date: Wed, 1 May 2013 16:25:37 +0200
Subject: [PATCH] algos_sig: new support for fmtseq192

It's quite rational to have such algorithm. 256-bit security is usually
an overkill, and this has two times smaller signatures (around 9.5kB) is
_so_ much faster. Use it.
---
 src/algo_suite.cpp | 19 +++++++++++--------
 src/algos_sig.cpp  | 36 ++++++++++++++++++++++++++++++++++++
 src/algos_sig.h    | 22 ++++++++++++++++++++++
 3 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/src/algo_suite.cpp b/src/algo_suite.cpp
index a74e030..02ea6fc 100644
--- a/src/algo_suite.cpp
+++ b/src/algo_suite.cpp
@@ -24,15 +24,18 @@
 void fill_algorithm_suite (algorithm_suite&s)
 {
 
-	static algo_mceqd128 mce1;
-	mce1.register_into_suite (s);
+	static algo_mceqd128 mce128;
+	mce128.register_into_suite (s);
 
-	static algo_mceqd256 mce2;
-	mce2.register_into_suite (s);
+	static algo_mceqd256 mce256;
+	mce256.register_into_suite (s);
 
-	static algo_fmtseq128 fmt1;
-	fmt1.register_into_suite (s);
+	static algo_fmtseq128 fmt128;
+	fmt128.register_into_suite (s);
 
-	static algo_fmtseq256 fmt2;
-	fmt2.register_into_suite (s);
+	static algo_fmtseq192 fmt192;
+	fmt192.register_into_suite (s);
+
+	static algo_fmtseq256 fmt256;
+	fmt256.register_into_suite (s);
 }
diff --git a/src/algos_sig.cpp b/src/algos_sig.cpp
index f017555..41ba3c6 100644
--- a/src/algos_sig.cpp
+++ b/src/algos_sig.cpp
@@ -21,6 +21,7 @@
 #include "fmtseq.h"
 #include "sha_hash.h"
 #include "rmd_hash.h"
+#include "tiger_hash.h"
 #include "arcfour.h"
 
 /*
@@ -184,6 +185,26 @@ int algo_fmtseq128::verify (const bvector&sig,
 	       (sig, msg, pubkey);
 }
 
+int algo_fmtseq192::sign (const bvector&msg,
+                          bvector&sig,
+                          sencode**privkey,
+                          bool&dirty,
+                          prng&rng)
+{
+	return fmtseq_generic_sign
+	       <4, 4, 384, sha384hash, tiger192hash>
+	       (msg, sig, privkey, dirty, rng);
+}
+
+int algo_fmtseq192::verify (const bvector&sig,
+                            const bvector&msg,
+                            sencode*pubkey)
+{
+	return fmtseq_generic_verify
+	       <4, 4, 384, sha384hash, tiger192hash>
+	       (sig, msg, pubkey);
+}
+
 int algo_fmtseq256::sign (const bvector&msg,
                           bvector&sig,
                           sencode**privkey,
@@ -219,6 +240,21 @@ int algo_fmtseq128::create_keypair (sencode**pub, sencode**priv, prng&rng)
 	return 0;
 }
 
+int algo_fmtseq192::create_keypair (sencode**pub, sencode**priv, prng&rng)
+{
+	fmtseq::pubkey Pub;
+	fmtseq::privkey Priv;
+
+	tiger192hash hf;
+
+	if (fmtseq::generate (Pub, Priv, rng, hf, 384, 4, 4) )
+		return 1;
+
+	*pub = Pub.serialize();
+	*priv = Priv.serialize();
+	return 0;
+}
+
 int algo_fmtseq256::create_keypair (sencode**pub, sencode**priv, prng&rng)
 {
 	fmtseq::pubkey Pub;
diff --git a/src/algos_sig.h b/src/algos_sig.h
index b6df71d..c696d1e 100644
--- a/src/algos_sig.h
+++ b/src/algos_sig.h
@@ -43,6 +43,28 @@ public:
 	int create_keypair (sencode**pub, sencode**priv, prng&rng);
 };
 
+class algo_fmtseq192 : public algorithm
+{
+public:
+	bool provides_signatures() {
+		return true;
+	}
+
+	bool provides_encryption() {
+		return false;
+	}
+
+	std::string get_alg_id() {
+		return "FMTSEQ192-SHA384-TIGER192";
+	}
+
+	virtual int sign (const bvector&msg, bvector&sig,
+	                  sencode** privkey, bool&dirty, prng&rng);
+	virtual int verify (const bvector&sig, const bvector&msg,
+	                    sencode* pubkey);
+	int create_keypair (sencode**pub, sencode**priv, prng&rng);
+};
+
 class algo_fmtseq256 : public algorithm
 {
 public: