summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/cpp_rsau.cpp
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2012-07-20 16:21:49 +0000
committerKirill Volinsky <mataes2007@gmail.com>2012-07-20 16:21:49 +0000
commitf424a18112032cf61d2871a6b91a5af607c171ae (patch)
tree88fedc4e28941ceecda7026f0b06eba6271f91d5 /plugins/CryptoPP/cpp_rsau.cpp
parentbfe1bd0fc087be44c70904aee0fe4276643d206d (diff)
CryptoPP:
changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1083 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/cpp_rsau.cpp')
-rw-r--r--plugins/CryptoPP/cpp_rsau.cpp258
1 files changed, 0 insertions, 258 deletions
diff --git a/plugins/CryptoPP/cpp_rsau.cpp b/plugins/CryptoPP/cpp_rsau.cpp
deleted file mode 100644
index e9ad825dd0..0000000000
--- a/plugins/CryptoPP/cpp_rsau.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-#include "commonheaders.h"
-
-const string padding = "PADDING!PADDING!PADDING!PADDING!"; // 256 bit
-
-
-string pad256(string& str) {
- string out = str;
- int pad = out.length() % 32;
- if ( pad ) { // надо выровнять на 256 бит
- if ( pad>3 ) {
- out += tlv(0,padding.substr(0,32-3-pad));
- }
- else {
- if ( pad==3 ) out += string("\0\0\0");
- else
- if ( pad==2 ) out += string("\0\0");
- else out += string("\0");
- }
- }
- return out;
-}
-
-
-string& add_delim(string& str, const string& del, int len) {
- string val;
- for ( u_int i=0; i<str.length(); i+=len ) {
- val += str.substr(i,len) + del;
- }
- str = val;
- return str;
-}
-
-
-string& del_delim(string& str, const string& del) {
- string val;
- for ( u_int i=0; i<str.length(); i++ ) {
- if ( del.find(str[i]) == string::npos )
- val += str[i];
- }
- str = val;
- return str;
-}
-
-
-string tlv(int t, const string& v) {
- string b;
- t |= v.length()<<8;
- b.assign((const char*)&t,3);
- b += v;
- return b;
-}
-
-
-string tlv(int t, const char* v) {
- return tlv(t, string(v));
-}
-
-
-string tlv(int t, int v) {
- string s;
- u_int l=(v<=0xFF)?1:((v<=0xFFFF)?2:((v<=0xFFFFFF)?3:4));
- s.assign((char*)&v,l);
- return tlv(t,s);
-}
-
-
-string& un_tlv(string& b, int& t, string& v) {
- string r; v = r;
- if ( b.length() > 3 ) {
- t = 0;
- b.copy((char*)&t,3);
- u_int l = t>>8;
- t &= 0xFF;
- if ( b.length() >= 3+l ) {
- v = b.substr(3,l);
- r = b.substr(3+l);
- }
- }
- if ( !v.length() ) {
- t = -1;
- }
- b = r;
- return b;
-}
-
-
-string& un_tlv(string& b, int& t, int& v) {
- string s;
- un_tlv(b,t,s);
- v = 0;
- s.copy((char*)&v,s.length());
- return b;
-}
-
-
-int str2int(string& s) {
- int v = 0;
- if ( s.length()<=sizeof(int) )
- s.copy((char*)&v,s.length());
- return v;
-}
-
-
-string hash(string& b)
-{
- return ::hash((PBYTE)b.data(),b.length());
-}
-
-
-string hash(PBYTE b, int l)
-{
- BYTE h[RSA_KEYSIZE];
- RSA_CalculateDigest(h, b, l);
- string s; s.assign((char*)&h,RSA_KEYSIZE);
- return s;
-}
-
-
-string hash128(string& b)
-{
- return hash128((PBYTE)b.data(),b.length());
-}
-
-
-string hash128(LPSTR b)
-{
- return hash128((PBYTE)b,strlen(b));
-}
-
-
-string hash128(PBYTE b, int l)
-{
- BYTE h[RIPEMD128::DIGESTSIZE];
- RIPEMD128().CalculateDigest(h, b, l);
- string s; s.assign((char*)&h,sizeof(h));
- return s;
-}
-
-
-string hash256(string& b)
-{
- return hash256((PBYTE)b.data(),b.length());
-}
-
-
-string hash256(LPSTR b)
-{
- return hash256((PBYTE)b,strlen(b));
-}
-
-
-string hash256(PBYTE b, int l)
-{
-// BYTE h[SHA256::DIGESTSIZE];
-// SHA256().CalculateDigest(h, b, l);
- BYTE h[RIPEMD256::DIGESTSIZE];
- RIPEMD256().CalculateDigest(h, b, l);
- string s; s.assign((char*)&h,sizeof(h));
- return s;
-}
-
-
-Integer BinaryToInteger(const string& data)
-{
- StringSource ss(data, true, NULL);
- SecByteBlock result(ss.MaxRetrievable());
- ss.Get(result, result.size());
- return Integer(result, result.size());
-}
-
-
-string IntegerToBinary(const Integer& value)
-{
- SecByteBlock sbb(value.MinEncodedSize());
- value.Encode(sbb, sbb.size());
- string data;
- StringSource(sbb, sbb.size(), true, new StringSink(data));
- return data;
-}
-
-/*
-RandomPool& GlobalRNG()
-{
- static RandomPool randomPool;
- return randomPool;
-}
-*/
-
-AutoSeededRandomPool& GlobalRNG()
-{
- static AutoSeededRandomPool randomPool;
- return randomPool;
-}
-
-
-void GenerateRSAKey(unsigned int keyLength, string& privKey, string& pubKey)
-{
- RSAES_PKCS1v15_Decryptor priv(GlobalRNG(), keyLength);
- StringSink privFile(privKey);
- priv.DEREncode(privFile);
- privFile.MessageEnd();
-
- RSAES_PKCS1v15_Encryptor pub(priv);
- StringSink pubFile(pubKey);
- pub.DEREncode(pubFile);
- pubFile.MessageEnd();
-}
-
-
-string RSAEncryptString(const RSA::PublicKey& pubkey, const string& plaintext)
-{
- RSAES_PKCS1v15_Encryptor pub(pubkey);
-
- string result;
- StringSource(plaintext, true, new PK_EncryptorFilter(GlobalRNG(), pub, new StringSink(result)));
- return result;
-}
-
-
-string RSADecryptString(const RSA::PrivateKey& privkey, const string& ciphertext)
-{
- RSAES_PKCS1v15_Decryptor priv(privkey);
-
- string result;
- try {
- StringSource(ciphertext, true, new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result)));
- }
- catch (...) {
- ;
- }
- return result;
-}
-
-
-string RSASignString(const RSA::PrivateKey& privkey, const string& plaintext)
-{
- RSASSA_PKCS1v15_SHA_Signer priv(privkey);
-
- string result;
- try {
- StringSource(plaintext, true, new SignerFilter(GlobalRNG(), priv, new StringSink(result)));
- }
- catch (...) {
- ;
- }
- return result;
-}
-
-
-BOOL RSAVerifyString(const RSA::PublicKey& pubkey, const string& plaintext, const string& sig)
-{
- RSASSA_PKCS1v15_SHA_Verifier ver(pubkey);
-
- return ver.VerifyMessage((PBYTE)plaintext.data(), plaintext.length(), (PBYTE)sig.data(), sig.length());
-}
-
-
-// EOF