6 // VLONG.HPP ---------------------------------
\r
8 class vlong // very long integer - can be used like long
\r
11 // Standard arithmetic operators
\r
12 friend vlong operator +( const vlong& x, const vlong& y );
\r
13 friend vlong operator -( const vlong& x, const vlong& y );
\r
14 friend vlong operator *( const vlong& x, const vlong& y );
\r
15 friend vlong operator /( const vlong& x, const vlong& y );
\r
16 friend vlong operator %( const vlong& x, const vlong& y );
\r
17 vlong& operator +=( const vlong& x );
\r
18 vlong& operator -=( const vlong& x );
\r
20 // Standard comparison operators
\r
21 friend inline int operator !=( const vlong& x, const vlong& y ){ return x.cf( y ) != 0; }
\r
22 friend inline int operator ==( const vlong& x, const vlong& y ){ return x.cf( y ) == 0; }
\r
23 friend inline int operator >=( const vlong& x, const vlong& y ){ return x.cf( y ) >= 0; }
\r
24 friend inline int operator <=( const vlong& x, const vlong& y ){ return x.cf( y ) <= 0; }
\r
25 friend inline int operator > ( const vlong& x, const vlong& y ){ return x.cf( y ) > 0; }
\r
26 friend inline int operator < ( const vlong& x, const vlong& y ){ return x.cf( y ) < 0; }
\r
28 // Construction and conversion operations
\r
29 vlong ( unsigned x=0 );
\r
30 vlong ( const vlong& x ); // copy constructor
\r
32 operator unsigned ();
\r
33 vlong& operator =(const vlong& x);
\r
35 void load( unsigned * a, unsigned n ); // load value, a[0] is lsw
\r
36 void store( unsigned * a, unsigned n ) const; // low level save, a[0] is lsw
\r
37 unsigned get_nunits() const;
\r
38 unsigned bits() const;
\r
41 class vlong_value * value;
\r
43 int cf( const vlong x ) const;
\r
48 // RSA.HPP -------------------------------------------
\r
54 vlong encrypt( const vlong& plain ); // Requires 0 <= plain < m
\r
55 void MakeMe(const char *);
\r
58 class private_key : public public_key
\r
62 vlong decrypt( const vlong& cipher );
\r
64 void create( const char * r1, const char * r2 );
\r
65 // r1 and r2 should be null terminated random strings
\r
66 // each of length around 35 characters (for a 500 bit modulus)
\r
68 void MakeMeStr(char *);
\r
69 void MakePq(const char *);
\r
70 void MakePqStr(char *);
\r
73 #define MAX_CRYPT_BITS 1024
\r
75 class CCryptoProviderRSA
\r
77 class private_key prkface;
\r
79 void EncryptPortion(const char *pt, size_t,char *ct,size_t &);
\r
80 void DecryptPortion(const char *ct, size_t,char *pt,size_t &);
\r
84 CCryptoProviderRSA();
\r
85 virtual ~CCryptoProviderRSA();
\r
87 virtual void Encrypt(const char *, size_t,char *, size_t &);
\r
88 virtual void Decrypt(const char *, size_t,char *, size_t &);
\r
89 virtual void ExportPublicKey(char *);
\r
90 virtual void ImportPublicKey(const char *);
\r
91 virtual void ExportPrivateKey(char *);
\r
92 virtual void ImportPrivateKey(const char *);
\r
93 virtual void GetBlockSize(int&, int&);
\r