1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-27 09:18:16 +00:00
codecrypt/src/algorithm.h

80 lines
2.1 KiB
C
Raw Normal View History

2013-01-07 21:29:29 +00:00
/*
* This file is part of Codecrypt.
*
2016-04-17 13:47:47 +00:00
* Copyright (C) 2013-2016 Mirek Kratochvil <exa.exa@gmail.com>
*
2013-01-07 21:29:29 +00:00
* 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/>.
*/
#ifndef _ccr_algorithm_h_
#define _ccr_algorithm_h_
#include "algo_suite.h"
2013-01-07 21:29:29 +00:00
#include "bvector.h"
#include "prng.h"
#include "sencode.h"
2013-01-26 21:55:56 +00:00
/*
* virtual interface definition for all cryptographic algorithm instances.
*
* Note that the whole class could be defined static, but we really enjoy
* having the tiny virtual pointers stored in some cool structure along with
* the handy algorithm name.
*/
2013-01-07 21:29:29 +00:00
class algorithm
{
public:
virtual bool provides_signatures() = 0;
virtual bool provides_encryption() = 0;
2013-05-01 14:11:45 +00:00
2013-01-07 21:29:29 +00:00
virtual std::string get_alg_id() = 0;
void register_into_suite (algorithm_suite&s) {
s[this->get_alg_id()] = this;
}
/*
* note that these functions should be ready for different
* plaintext/ciphertext/message lengths, usually padding them somehow.
*/
virtual int encrypt (const bvector&plain, bvector&cipher,
2013-01-16 21:30:03 +00:00
sencode* pubkey, prng&rng) {
return -1;
}
2013-01-07 21:29:29 +00:00
virtual int decrypt (const bvector&cipher, bvector&plain,
2013-01-16 21:30:03 +00:00
sencode* privkey) {
return -1;
}
2013-01-07 21:29:29 +00:00
virtual int sign (const bvector&msg, bvector&sig,
2013-01-27 14:02:54 +00:00
sencode** privkey, bool&dirty, prng&rng) {
2013-01-16 21:30:03 +00:00
return -1;
}
2013-01-07 21:29:29 +00:00
virtual int verify (const bvector&sig, const bvector&msg,
2013-01-16 21:30:03 +00:00
sencode* pubkey) {
return -1;
}
2013-01-07 23:13:19 +00:00
2013-01-16 21:30:03 +00:00
virtual int create_keypair (sencode**pub, sencode**priv, prng&rng) {
return -1;
}
2013-01-07 21:29:29 +00:00
};
#endif