diff --git a/src/algo_suite.cpp b/src/algo_suite.cpp index 58d9f45..77788b8 100644 --- a/src/algo_suite.cpp +++ b/src/algo_suite.cpp @@ -37,5 +37,11 @@ void fill_algorithm_suite (algorithm_suite&s) do_alg (algo_mceqd128cube); do_alg (algo_mceqd192cube); do_alg (algo_mceqd256cube); + do_alg (algo_fmtseq128cube); + do_alg (algo_fmtseq192cube); + do_alg (algo_fmtseq256cube); + do_alg (algo_fmtseq128h20cube); + do_alg (algo_fmtseq192h20cube); + do_alg (algo_fmtseq256h20cube); #undef do_alg } diff --git a/src/algos_sig.cpp b/src/algos_sig.cpp index a1ae9c1..545f49c 100644 --- a/src/algos_sig.cpp +++ b/src/algos_sig.cpp @@ -90,11 +90,11 @@ static void msg_pad (const bvector&in, std::vector&out, size_t minsize) */ template -int fmtseq_generic_sign (const bvector&msg, - bvector&sig, - sencode**privkey, - bool&dirty, - prng&rng) +static int fmtseq_generic_sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) { //load the key fmtseq::privkey Priv; @@ -131,9 +131,9 @@ int fmtseq_generic_sign (const bvector&msg, } template -int fmtseq_generic_verify (const bvector&sig, - const bvector&msg, - sencode*pubkey) +static int fmtseq_generic_verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) { //load the key fmtseq::pubkey Pub; @@ -161,6 +161,23 @@ int fmtseq_generic_verify (const bvector&sig, return 0; } +template +static int fmtseq_create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + fmtseq::pubkey Pub; + fmtseq::privkey Priv; + + treehash hf; + + if (fmtseq::generate (Pub, Priv, rng, hf, hs, h, l) ) + return 1; + + *pub = Pub.serialize(); + *priv = Priv.serialize(); + return 0; +} + + /* * actual instantiations */ @@ -227,47 +244,20 @@ int algo_fmtseq256::verify (const bvector&sig, int algo_fmtseq128::create_keypair (sencode**pub, sencode**priv, prng&rng) { - fmtseq::pubkey Pub; - fmtseq::privkey Priv; - - rmd128hash hf; - - if (fmtseq::generate (Pub, Priv, rng, hf, 256, 4, 4) ) - return 1; - - *pub = Pub.serialize(); - *priv = Priv.serialize(); - return 0; + return fmtseq_create_keypair + (pub, priv, rng); } 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; + return fmtseq_create_keypair + (pub, priv, rng); } int algo_fmtseq256::create_keypair (sencode**pub, sencode**priv, prng&rng) { - fmtseq::pubkey Pub; - fmtseq::privkey Priv; - - sha256hash hf; - - if (fmtseq::generate (Pub, Priv, rng, hf, 512, 4, 4) ) - return 1; - - *pub = Pub.serialize(); - *priv = Priv.serialize(); - return 0; + return fmtseq_create_keypair + (pub, priv, rng); } /* @@ -339,46 +329,184 @@ int algo_fmtseq256h20::verify (const bvector&sig, int algo_fmtseq128h20::create_keypair (sencode**pub, sencode**priv, prng&rng) { - fmtseq::pubkey Pub; - fmtseq::privkey Priv; - - rmd128hash hf; - - if (fmtseq::generate (Pub, Priv, rng, hf, 256, 4, 5) ) - return 1; - - *pub = Pub.serialize(); - *priv = Priv.serialize(); - return 0; + return fmtseq_create_keypair + (pub, priv, rng); } int algo_fmtseq192h20::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, 5) ) - return 1; - - *pub = Pub.serialize(); - *priv = Priv.serialize(); - return 0; + return fmtseq_create_keypair + (pub, priv, rng); } int algo_fmtseq256h20::create_keypair (sencode**pub, sencode**priv, prng&rng) { - fmtseq::pubkey Pub; - fmtseq::privkey Priv; - - sha256hash hf; - - if (fmtseq::generate (Pub, Priv, rng, hf, 512, 4, 5) ) - return 1; - - *pub = Pub.serialize(); - *priv = Priv.serialize(); - return 0; + return fmtseq_create_keypair + (pub, priv, rng); } +/* + * CubeHash variants of everything above. + */ + +#include "cube_hash.h" + +int algo_fmtseq128cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 4, 256, cube256hash, cube128hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq128cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 4, 256, cube256hash, cube128hash> + (sig, msg, pubkey); +} + +int algo_fmtseq192cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 4, 384, cube384hash, cube192hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq192cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 4, 384, cube384hash, cube192hash> + (sig, msg, pubkey); +} + +int algo_fmtseq256cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 4, 512, cube512hash, cube256hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq256cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 4, 512, cube512hash, cube256hash> + (sig, msg, pubkey); +} + +int algo_fmtseq128cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} + +int algo_fmtseq192cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} + +int algo_fmtseq256cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} + +/* + * h=20 variants with cubehash. + */ + +int algo_fmtseq128h20cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 5, 256, cube256hash, cube128hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq128h20cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 5, 256, cube256hash, cube128hash> + (sig, msg, pubkey); +} + +int algo_fmtseq192h20cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 5, 384, cube384hash, cube192hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq192h20cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 5, 384, cube384hash, cube192hash> + (sig, msg, pubkey); +} + +int algo_fmtseq256h20cube::sign (const bvector&msg, + bvector&sig, + sencode**privkey, + bool&dirty, + prng&rng) +{ + return fmtseq_generic_sign + <4, 5, 512, cube512hash, cube256hash> + (msg, sig, privkey, dirty, rng); +} + +int algo_fmtseq256h20cube::verify (const bvector&sig, + const bvector&msg, + sencode*pubkey) +{ + return fmtseq_generic_verify + <4, 5, 512, cube512hash, cube256hash> + (sig, msg, pubkey); +} + +int algo_fmtseq128h20cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} + +int algo_fmtseq192h20cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} + +int algo_fmtseq256h20cube::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + return fmtseq_create_keypair + (pub, priv, rng); +} diff --git a/src/algos_sig.h b/src/algos_sig.h index 42c966a..61aadd9 100644 --- a/src/algos_sig.h +++ b/src/algos_sig.h @@ -153,5 +153,141 @@ public: int create_keypair (sencode**pub, sencode**priv, prng&rng); }; +/* + * Cubehash variants + */ + +class algo_fmtseq128cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ128-CUBE256-CUBE128"; + } + + 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_fmtseq192cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ192-CUBE384-CUBE192"; + } + + 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_fmtseq256cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ256-CUBE512-CUBE256"; + } + + 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_fmtseq128h20cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ128H20-CUBE256-CUBE128"; + } + + 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_fmtseq192h20cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ192H20-CUBE384-CUBE192"; + } + + 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_fmtseq256h20cube : public algorithm +{ +public: + bool provides_signatures() { + return true; + } + + bool provides_encryption() { + return false; + } + + std::string get_alg_id() { + return "FMTSEQ256H20-CUBE512-CUBE256"; + } + + 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); +}; + #endif