-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.h
52 lines (37 loc) · 1.29 KB
/
crypto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "base/memory/scoped_ptr.h"
#include <string>
#include <openssl/evp.h>
namespace cryptagram {
const int kSaltLen = 8;
const int kIvLen = 32;
class BlockCipher {
public:
BlockCipher();
~BlockCipher();
// Takes a message to be encrypted from |input| along with a human-readable
// |password| and applies the appropriate cryptographic transformations to
// produce an OpenSSL-compatible |output|.
bool Encrypt(const std::string& input, const std::string& password,
std::string* output);
// Takes an OpenSSL-compatible |input| along with a human-readable |password|
// and applies appropriate decryption transformations to produce the
// byte-for-byte |output|.
bool Decrypt(const std::string& input, const std::string& password,
std::string* output);
void PrintSalt() const;
void PrintKey() const;
private:
void InitEncrypt(const std::string& password);
void InitDecrypt(const std::string& input, const std::string& password);
scoped_ptr<EVP_CIPHER_CTX> encrypt_;
scoped_ptr<EVP_CIPHER_CTX> decrypt_;
// Do not have ownership of these pointers.
const EVP_CIPHER* cipher_;
const EVP_MD* digest_;
scoped_array<unsigned char> salt_;
scoped_array<unsigned char> iv_;
scoped_array<unsigned char> key_;
int nrounds_;
};
}