diff --git a/src/signatures.h b/src/keyring.cpp similarity index 60% rename from src/signatures.h rename to src/keyring.cpp index 6027f80..102ca91 100644 --- a/src/signatures.h +++ b/src/keyring.cpp @@ -16,8 +16,41 @@ * along with Codecrypt. If not, see . */ -#ifndef _ccr_sigs_h_ -#define _ccr_sigs_h_ +#include "keyring.h" -#endif +bool keyring::disk_sync() +{ + + return false; +} + +sencode* keyring::get_pubkey (const std::string&key_id) +{ + +} + +void keyring::remove_pubkey (const std::string&key_id) +{ + +} + +bool keyring::store_pubkey (const std::string&key_id, sencode*) +{ + +} + +sencode* keyring::get_privkey (const std::string&key_id) +{ + +} + +void keyring::remove_privkey (const std::string&key_id) +{ + +} + +bool keyring::store_privkey (const std::string&key_id, sencode*) +{ + +} diff --git a/src/encryption.h b/src/keyring.h similarity index 61% rename from src/encryption.h rename to src/keyring.h index a536038..0f37fd3 100644 --- a/src/encryption.h +++ b/src/keyring.h @@ -16,9 +16,26 @@ * along with Codecrypt. If not, see . */ -#ifndef _ccr_enc_h_ -#define _ccr_enc_h_ +#ifndef _ccr_keys_h_ +#define _ccr_keys_h_ +#include + +#include "sencode.h" + +class keyring +{ +public: + bool disk_sync(); + + sencode* get_pubkey (const std::string&key_id); + void remove_pubkey (const std::string&key_id); + bool store_pubkey (const std::string&key_id, sencode*); + + sencode* get_privkey (const std::string&key_id); + void remove_privkey (const std::string&key_id); + bool store_privkey (const std::string&key_id, sencode*); +}; #endif diff --git a/src/message.cpp b/src/message.cpp new file mode 100644 index 0000000..b9a6964 --- /dev/null +++ b/src/message.cpp @@ -0,0 +1,93 @@ + +/* + * 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 "message.h" + +#include "mce_qd.h" + +int encrypted_msg::encrypt (const bvector&msg, + const std::string& Alg_id, const std::string& Key_id, + keyring&kr, prng&rng) +{ + key_id = Key_id; + alg_id = Alg_id; + + sencode*pubkey = kr.get_pubkey (key_id); + if (!pubkey) return 1; //PK not found + + if (alg_id == "MCEQD-128") { + } else if (alg_id == "MCEQD-256") { + mce_qd::pubkey pk; + if (!pk.unserialize (pubkey) ) return 3; //Key unreadable + + //TODO fujisaki-okamoto + } else return 2; //unknown algorithm + + return 0; +} + +int encrypted_msg::decrypt (bvector&msg, keyring&kr) +{ + sencode*privkey = kr.get_privkey (key_id); + if (!privkey) return 1; //no key found + + if (alg_id == "MCEQD-128") { + } else if (alg_id == "MCEQD-256") { + mce_qd::privkey sk; + if (!sk.unserialize (privkey) ) return 3; //key unreadable + + //TODO fujisaki-okamoto + } else return 2; //unknown algorithm + + return 0; +} + +int signed_msg::sign (const bvector&msg, + const std::string& Alg_id, const std::string&Key_id, + keyring&kr, prng&rng) +{ + key_id = Key_id; + alg_id = Alg_id; + message = msg; + + sencode*privkey = kr.get_privkey (key_id); + if (!privkey) return 1; + + if (alg_id == "FMTSEQ-S256-128") { + + } else if (alg_id == "FMTSEQ-S256-256") { + + //TODO produce a reasonable signature + } else return 2; //unknown algorithm + +} + +int signed_msg::verify (keyring&kr) +{ + sencode*pubkey = kr.get_pubkey (key_id); + if (!pubkey) return 1; + if (alg_id == "FMTSEQ-S256-128") { + + //TODO check it + } else if (alg_id == "FMTSEQ-S256-256") { + + } else return 2; //unknown algorithm + + return 0; +} + diff --git a/src/message.h b/src/message.h index e9617fa..81edf6d 100644 --- a/src/message.h +++ b/src/message.h @@ -19,5 +19,44 @@ #ifndef _ccr_msg_h_ #define _ccr_msg_h_ +#include +#include "bvector.h" +#include "sencode.h" +#include "keyring.h" +#include "prng.h" + +class encrypted_msg +{ +public: + bvector message; + std::string alg_id, key_id; + + int decrypt (bvector&, keyring&); + int encrypt (const bvector& msg, + const std::string& alg_id, + const std::string& key_id, + keyring&, prng&); + + + sencode* serialize(); + bool unserialize (sencode*); +}; + +class signed_msg +{ +public: + bvector message, signature; + std::string alg_id, key_id; + + int verify (keyring&); + int sign (const bvector&msg, + const std::string&alg_id, + const std::string&key_id, + keyring&, prng&); + + sencode* serialize(); + bool unserialize (sencode*); +}; + #endif