00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #if !defined(AFX_CRYPTOPPLINK_H__B7F2370A_C422_447F_AD1A_59ECDA30DDF4__INCLUDED_)
00031 #define AFX_CRYPTOPPLINK_H__B7F2370A_C422_447F_AD1A_59ECDA30DDF4__INCLUDED_
00032
00033 #include <iostream>
00034 #include <math.h>
00035 #include "integer.h"
00036 #include "pubkey.h"
00037 #include "md2.h"
00038 #include "md5.h"
00039 #include "md5mac.h"
00040 #include "md4.h"
00041 #include "panama.h"
00042 #include "ripemd.h"
00043 #include "tiger.h"
00044 #include "hex.h"
00045 #include "rsa.h"
00046 #include "modarith.h"
00047 #include "polynomi.h"
00048 #include "randpool.h"
00049 #include "time.h"
00050 #include "osrng.h"
00051 #include "cryptlib.h"
00052 #include "filters.h"
00053 #include "modes.h"
00054 #include "aes.h"
00055 #include "des.h"
00056 #include "idea.h"
00057 #include "rc5.h"
00058 #include "mars.h"
00059 #include "rc6.h"
00060 #include "serpent.h"
00061 #include "twofish.h"
00062 #include "Global.h"
00063 #include "sha.h"
00064 #include "files.h"
00065 #include "eccrypto.h"
00066 #include "ecp.h"
00067 #include "ec2n.h"
00068 #include "oids.h"
00069 #include "haval.h"
00070 #include "KryptosTimer.h"
00071 using namespace CryptoPP;
00072 using namespace std;
00073
00074
00075 #include "AlgorithmSheet.h"
00076 #include "CryptoLink.h"
00077
00078
00079 #if _MSC_VER > 1000
00080 #pragma once
00081 #endif // _MSC_VER > 1000
00082
00083
00084
00086
00087
00093 class CCryptoPPLink : public CCryptoLink
00094 {
00095 private:
00096
00097
00098 int m_operator,m_operation;
00099 BOOL m_success;
00100 DWORD m_numPumps,m_sizePumps,m_lastPump;
00101
00102 StreamTransformationFilter *cryptoStreamer;
00103
00104 class NothingRng : public RandomNumberGenerator
00105 {
00106 byte GenerateByte() { return 0x7d;}
00107 };
00108
00109 CAlgorithmSheet* p_AlgorithmSheet;
00110 CWnd* m_pParent;
00111 BYTE *m_iv;
00112 BYTE *m_key;
00113
00114 int m_symCipAlg;
00115 int m_symCipKeySizeByte;
00116 int m_symCipBlockSizeByte;
00117 int m_rounds;
00118 int m_mode;
00119 int m_feedbackByte;
00120
00121 CString pathInFile;
00122 CString pathOutFile;
00123
00124 bool VerifyHMAC();
00125 void GenerateHMAC();
00126 bool VerifyMD5MAC();
00127 void GenerateMD5MAC();
00128 bool ProcessDES();
00129 bool ProcessDES_EDE2();
00130 bool ProcessDES_EDE3();
00131 bool Process3DES();
00132 bool ProcessIDEA();
00133 bool ProcessMARS();
00134 bool ProcessRC5();
00135 bool ProcessRC6();
00136 bool ProcessAES();
00137 bool ProcessSerpent();
00138 bool ProcessTwofish();
00139 bool processOCBEncrypt();
00140 bool processOCBDecrypt();
00141
00142 void RsaDecryptRawCBC(char *seed, CString pathInFile, CString pathOutFile);
00143 void RsaEncryptRawCBC(char *seed, CString pathInFile, CString pathOutFile);
00144 void RsaDecryptRaw(char *seed, CString pathInFile,CString pathOutFile);
00145 void RsaEncryptRaw(char *seed, CString pathInFile,CString pathOutFile);
00146 bool ECPVerifyFile(CString pathInFile, CString pathOutFile);
00147 bool EC2NVerifyFile(CString pathInFile, CString pathOutFile);
00148 void EC2NSignFile(CString pathInFile ,CString pathOutFile );
00149 void ECPSignFile(CString pathInFile ,CString pathOutFile );
00150 bool DSAVerifyFile(CString pathInFile, CString pathOutFile);
00151 void DSASignFile(CString pathInFile ,CString pathOutFile );
00152 string ByteToStr(byte *out, int bytesize);
00153 void shiftright(byte *x, unsigned int n);
00154 void shiftleft(byte *x, unsigned int n);
00155 void MyOCBDecrypt(BlockCipher &Encryptor, BlockCipher &Decryptor,CString infile,CString outfile, const byte* iv);
00156 void MyOCBEncrypt(BlockCipher &c,CString infile,CString outfile, const byte* iv);
00157 DWORD dwStart, dwFinish;
00158 RandomPool & GlobalRNG();
00159
00160 bool m_no_blinding;
00161
00162
00163
00164
00165 template<class HashFunction>
00166 string HashFileToString(const char *filename, HashFunction HASH);
00167
00168 template<class HashFunction>
00169 void HashFileToFile(const char *infilename, const char *outfilename, HashFunction HASH);
00170
00171 template<class HashFunction>
00172 string HashStringToString(const char *str, HashFunction HASH);
00173
00174 template <class STD >
00175 void RSAEncryptFile(STD * s, const char *seed, const char *msgfilename, const char *cipherfilename);
00176 template <class STD >
00177 void RSAEncryptFileCBC(STD * s, const char *seed, const char *msgfilename, const char *cipherfilename);
00178
00179 template <class STD >
00180 void RSADecryptFile(STD *s, const char *cipherfilename, const char *decipheredfilename);
00181 template <class STD >
00182 void RSADecryptFileCBC(STD *s, const char *cipherfilename, const char *decipheredfilename);
00183
00184 template <class STD >
00185 bool RSAVerifyFile1(STD *s, const char *messageFilename, const char *signatureFilename);
00186
00187 template <class STD >
00188 void RSASignFile1(STD *s, const char *messageFilename, const char *signatureFilename);
00189
00190 void setParameterKey();
00191 void setParameterIV();
00192 BOOL filterTransform();
00193 void MakePoly();
00194
00195 public:
00196 CCryptoPPLink();
00197 CCryptoPPLink(CWnd* parent, CAlgorithmSheet* options);
00198
00199 virtual ~CCryptoPPLink();
00200
00201 #ifdef _DEBUG
00202 virtual void AssertValid() const;
00203 virtual void Dump(CDumpContext& dc) const;
00204 #endif
00205
00206 DECLARE_DYNCREATE(CCryptoPPLink)
00207
00208
00209
00210
00211
00212 void Serialize(CArchive& ar);
00213
00214
00215
00216 virtual void ProcessMACVer();
00217 virtual void ProcessMACGen();
00218 virtual void ProcessHash();
00219 virtual void ProcessHashVerify();
00220 virtual bool processVerify();
00221 virtual void processSign();
00222 virtual void processPK();
00223 virtual BOOL processRequest(DWORD numPumps,DWORD sizePumps,DWORD m_lastPump);
00224 virtual string ByteToHexString(byte *out, int bytesize);
00225 virtual byte *GetIV( int bytesize);
00226 };
00227
00228 #endif // !defined(AFX_CRYPTOPPLINK_H__B7F2370A_C422_447F_AD1A_59ECDA30DDF4__INCLUDED_)