diff --git a/src/algorithm.h b/src/algorithm.h index ae0dc89..96e3a06 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -45,19 +45,28 @@ public: * plaintext/ciphertext/message lengths, usually padding them somehow. */ virtual int encrypt (const bvector&plain, bvector&cipher, - sencode* pubkey, prng&rng) = 0; + sencode* pubkey, prng&rng) { + return -1; + } virtual int decrypt (const bvector&cipher, bvector&plain, - sencode* privkey) = 0; + sencode* privkey) { + return -1; + } virtual int sign (const bvector&msg, bvector&sig, - sencode* privkey, bool&dirty, - prng&rng) = 0; + sencode* privkey, bool&dirty, prng&rng) { + return -1; + } virtual int verify (const bvector&sig, const bvector&msg, - sencode* pubkey) = 0; + sencode* pubkey) { + return -1; + } - virtual int create_keypair (sencode**pub, sencode**priv, prng&rng) = 0; + virtual int create_keypair (sencode**pub, sencode**priv, prng&rng) { + return -1; + } }; #endif diff --git a/src/algos_enc.cpp b/src/algos_enc.cpp new file mode 100644 index 0000000..ff62211 --- /dev/null +++ b/src/algos_enc.cpp @@ -0,0 +1,49 @@ + +/* + * 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 . + */ + +#include "algos_enc.h" + +#include "mce_qd.h" + +int algo_mceqd128::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + mce_qd::pubkey Pub; + mce_qd::privkey Priv; + + if (mce_qd::generate (Pub, Priv, rng, 16, 7, 32, 4) ) + return 1; + + *pub = Pub.serialize(); + *priv = Priv.serialize(); + return 0; +} + +int algo_mceqd256::create_keypair (sencode**pub, sencode**priv, prng&rng) +{ + mce_qd::pubkey Pub; + mce_qd::privkey Priv; + + if (mce_qd::generate (Pub, Priv, rng, 16, 8, 32, 4) ) + return 1; + + *pub = Pub.serialize(); + *priv = Priv.serialize(); + return 0; +} + + diff --git a/src/algos_enc.h b/src/algos_enc.h new file mode 100644 index 0000000..d1a49cb --- /dev/null +++ b/src/algos_enc.h @@ -0,0 +1,69 @@ + +/* + * 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 . + */ + +#ifndef _ccr_enc_algs_h_ +#define _ccr_enc_algs_h_ + +#include "algorithm.h" + +class algo_mceqd128 : public algorithm +{ +public: + bool provides_signatures() { + return false; + } + + bool provides_encryption() { + return true; + } + + std::string get_alg_id() { + return "MCEQD128FO-SHA256-ARCFOUR"; + } + + int encrypt (const bvector&plain, bvector&cipher, + sencode* pubkey, prng&rng); + int decrypt (const bvector&cipher, bvector&plain, + sencode* privkey); + int create_keypair (sencode**pub, sencode**priv, prng&rng); +}; + +class algo_mceqd256 : public algorithm +{ +public: + bool provides_signatures() { + return false; + } + + bool provides_encryption() { + return true; + } + + std::string get_alg_id() { + return "MCEQD256FO-SHA256-ARCFOUR"; + } + + int encrypt (const bvector&plain, bvector&cipher, + sencode* pubkey, prng&rng); + int decrypt (const bvector&cipher, bvector&plain, + sencode* privkey); + int create_keypair (sencode**pub, sencode**priv, prng&rng); +}; + +#endif +