From cb4a46e7fbe62d788e66ed6121c717a2d22a4d7c Mon Sep 17 00:00:00 2001 From: watcherhd Date: Thu, 21 Apr 2011 14:14:52 +0000 Subject: svn.miranda.im is moving to a new home! git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- cryptopp/cpp_rsau.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 cryptopp/cpp_rsau.h (limited to 'cryptopp/cpp_rsau.h') diff --git a/cryptopp/cpp_rsau.h b/cryptopp/cpp_rsau.h new file mode 100644 index 0000000..adb017c --- /dev/null +++ b/cryptopp/cpp_rsau.h @@ -0,0 +1,101 @@ +#ifndef __CPP_RSAU_H__ +#define __CPP_RSAU_H__ + +class TLV { +private: + map data; + +public: + TLV(); + TLV(const string& b) { decode(b); }; + + string encode() { + map::const_iterator i; + string b; + for( i=data.begin(); i!=data.end(); ++i ) { + b += tlv(i->first,i->second); + } + return b; + }; + void decode(const string& b) { + u_char t; + string v; + string r = b; + while( r.length() ) { + t = un_tlv(r,v); + if( t==-1 ) { + break; + } + data[t] = v; + } + }; + + u_int count() { return data.size(); }; + bool exist(u_char t) { return (data.find(t) != data.end()); }; + string get(u_char t) { return data[t]; }; + void put(u_char t, string& v) { data[t]=v; }; + +private: + string tlv(u_int t, const string& v) { + string b; + t |= v.length()<<8; + b.assign((const char*)&t,3); + b += v; + return b; + }; + u_char un_tlv(string& b, string& v) { + string r; v = r; + u_int t = 0; + if( b.length() > 3 ) { + 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() ) { + return -1; + } + b = r; + return t; + }; +}; + +string pad256(string&); + +string& add_delim(string&,const string&,int); +string& del_delim(string&,const string&); + +string tlv(int,const string&); +string tlv(int,const char*); +string tlv(int,int); +string& un_tlv(string&,int&,string&); +string& un_tlv(string&,int&,int&); + +int str2int(string&); + +string hash(string&); +string hash(PBYTE,int); + +string hash128(string&); +string hash128(LPSTR); +string hash128(PBYTE,int); + +string hash256(string&); +string hash256(LPSTR); +string hash256(PBYTE,int); + +Integer BinaryToInteger(const string&); +string IntegerToBinary(const Integer&); + +AutoSeededRandomPool& GlobalRNG(); + +void GenerateRSAKey(unsigned int,string&,string&); +string RSAEncryptString(const RSA::PublicKey&,const string&); +string RSADecryptString(const RSA::PrivateKey&,const string&); +string RSASignString(const RSA::PrivateKey&,const string&); +BOOL RSAVerifyString(const RSA::PublicKey&,const string&,const string&); + +#endif -- cgit v1.2.3