plebble
symmetric_encryption.h
Go to the documentation of this file.
1 /*
2 -------------------------------------------------------------------------------
3  PLEBBLE
4 -------------------------------------------------------------------------------
5  Copyright (C) 2019-2020 KATLAS Technology. (http://katlastechnology.com)
6  Copyright (C) 2017-2020 Marcos Mayorga. (mm@mm-studios.com)
7 
8  This file is part of our Plebble(R) Platform.
9 
10  The code below cannot be copied, used for any purpose other than the one
11  agreed and/or distributed without the express permission of
12  KATLAS Technology.
13 -------------------------------------------------------------------------------
14 
15 
16 */
17 #ifndef USGOV_d849d1a13db50de2445a34619f728b452c00b4067ae57c05409fe800ef621994
18 #define USGOV_d849d1a13db50de2445a34619f728b452c00b4067ae57c05409fe800ef621994
19 
20 #include <iostream>
21 #include <string>
22 #include "ec.h"
23 #include <stdio.h>
24 #include <us/gov/config.h>
25 #include <crypto++/gcm.h>
26 #include <crypto++/aes.h>
27 #include <crypto++/osrng.h>
28 
29 namespace us { namespace gov {
30 namespace crypto {
31 
32  using namespace std;
33  using CryptoPP::AutoSeededRandomPool;
34  using CryptoPP::GCM;
35  using CryptoPP::AES;
36 
38  typedef ec::keys keys;
39  typedef unsigned char byte;
40 // symmetric_encryption(const keys::priv_t&, const keys::pub_t&);
41 // symmetric_encryption(const vector<unsigned char>&);
42  ko init(const keys::priv_t& sk, const keys::pub_t& pub_other);
43 
44  ko encrypt(const vector<unsigned char>& src, vector<unsigned char>& dest);
45  ko decrypt(const unsigned char* p, size_t sz, vector<unsigned char>& dest);
46  ko decrypt(const vector<unsigned char>& ciphertext, vector<unsigned char>& clear);
47  //bool decrypt(const vector<unsigned char>&, vector<unsigned char>&);
48  static int encmsg_ratio(const size_t plaintext_sz);
49  static size_t encmsg_max_sz(const size_t plaintext_sz);
50 
51  static constexpr size_t key_size = 16;
52  static constexpr size_t iv_size = 12;
53  static constexpr int tag_size = 16;
54  AutoSeededRandomPool prng_;
55  byte key_[key_size];
56  byte iv_[iv_size];
57 // unsigned char iv_[iv_size];
58 
59 // void set_iv_from_ciphertext(const vector<unsigned char>&, unsigned char* iv);
60 // void set_iv_from_ciphertext(const unsigned char* p, size_t sz, unsigned char* iv);
61 
62  GCM<AES>::Encryption enc;
63  GCM<AES>::Decryption dec;
64  };
65 
66 }
67 }}
68 #endif
us::gov::crypto::symmetric_encryption::dec
GCM< AES >::Decryption dec
Definition: symmetric_encryption.h:63
us::is_ko
static bool is_ko(const std::string &s)
Definition: ko.h:30
us.ko
Definition: ko.java:20
us
Definition: daemon.h:22
unlikely
#define unlikely(x)
Definition: likely.h:30
us::gov::crypto::symmetric_encryption::init
ko init(const keys::priv_t &sk, const keys::pub_t &pub_other)
likely.h
us::gov::crypto::symmetric_encryption::encmsg_ratio
static int encmsg_ratio(const size_t plaintext_sz)
us::gov::crypto::symmetric_encryption::decrypt
ko decrypt(const unsigned char *p, size_t sz, vector< unsigned char > &dest)
us::gov::crypto::ec::keys::pub_t
Definition: ec.h:44
us::gov::crypto::ec::instance
static ec instance
Definition: ec.h:143
us::gov::crypto::symmetric_encryption::enc
GCM< AES >::Encryption enc
Definition: symmetric_encryption.h:62
us::gov::crypto::ec::generate_shared_key
ko generate_shared_key(unsigned char *, size_t, const keys::priv_t &, const keys::pub_t &)
us::gov::engine::auth::pub_t
peer::daemon::pub_t pub_t
Definition: auth_app.h:53
us::gov::crypto::ec::keys::priv_t
Definition: ec.h:77
us::gov::crypto::symmetric_encryption::prng_
AutoSeededRandomPool prng_
Definition: symmetric_encryption.h:54
us::gov::crypto::symmetric_encryption
Definition: symmetric_encryption.h:37
us::gov::crypto::symmetric_encryption::encrypt
ko encrypt(const vector< unsigned char > &src, vector< unsigned char > &dest)
us::ko
const ko_t * ko
Definition: ko.h:27
c
us::gov::crypto::symmetric_encryption c
Definition: symmetric_encryption.cpp:37
us::ok
static constexpr ko ok
Definition: ko.h:28
us::gov::crypto::symmetric_encryption::encmsg_max_sz
static size_t encmsg_max_sz(const size_t plaintext_sz)
us::gov::crypto::symmetric_encryption::decrypt
ko decrypt(const vector< unsigned char > &ciphertext, vector< unsigned char > &clear)
symmetric_encryption.h
std
Definition: app.h:380
us::gov::crypto::ec::keys
Definition: ec.h:43
config.h
us::gov::crypto
Definition: base58.cpp:19
us::gov::crypto::symmetric_encryption::keys
ec::keys keys
Definition: symmetric_encryption.h:38
us::gov::crypto::symmetric_encryption::byte
unsigned char byte
Definition: symmetric_encryption.h:39
gov.h
ec.h
log
#define log
Definition: gov.h:83