History

add cryptopp (https://www.cryptopp.com/)

Christoph Weiss committed 10 years ago

Commit 8e895981 parent 19d0acd4 files · +105 −0Browse files

Showing the changes to src/cryptopp-test.cpp (1 of 4 files). Show all

Unified · Split

src/cryptopp-test.cpp+46−0
@@ -0,0 +1,46 @@
1#include <cryptopp/cryptlib.h>
2#include <cryptopp/osrng.h>
3#include <cryptopp/secblock.h>
4#include <cryptopp/sha.h>
5#include <cryptopp/sha3.h>
6#include <cryptopp/base64.h>
7#include <cryptopp/filters.h>
8#include <cryptopp/gcm.h>
9#include <cryptopp/rsa.h>
10#include <cryptopp/pssr.h>
11
12int main() {
13 {
14 CryptoPP::SHA512 sha2;
15 unsigned char digest[CryptoPP::SHA512::DIGESTSIZE];
16 sha2.Final(digest);
17 }
18
19 {
20 std::string data;
21 const CryptoPP::SecByteBlock key;
22 const CryptoPP::SecByteBlock iv;
23
24 CryptoPP::SecByteBlock ret(0, CryptoPP::AES::MAX_KEYLENGTH);
25 CryptoPP::StringSource(data, true, new CryptoPP::HashFilter(*(new CryptoPP::SHA3_512), new CryptoPP::ArraySink(ret, CryptoPP::AES::MAX_KEYLENGTH)));
26 CryptoPP::GCM< CryptoPP::AES, CryptoPP::GCM_64K_Tables >::Encryption pwenc;
27 pwenc.SetKeyWithIV(key.data(), key.size(), iv.data(), iv.size());
28 std::string cipher;
29 CryptoPP::StringSource(data, true, new CryptoPP::AuthenticatedEncryptionFilter(pwenc, new CryptoPP::StringSink(cipher), false, 16));
30 }
31
32 {
33 const CryptoPP::SecByteBlock key;
34 const CryptoPP::SecByteBlock iv;
35 CryptoPP::GCM< CryptoPP::AES, CryptoPP::GCM_64K_Tables >::Decryption pwdec;
36 pwdec.SetKeyWithIV(key.data(), key.size(), iv.data(), iv.size());
37 }
38
39 {
40 CryptoPP::SecByteBlock ret(0, CryptoPP::AES::BLOCKSIZE);
41 std::string str;
42 CryptoPP::StringSource(str, true, new CryptoPP::Base64Decoder(new CryptoPP::ArraySink(ret, CryptoPP::AES::BLOCKSIZE)));
43 }
44
45 return 0;
46}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t