CryptoPPLink.h

Go to the documentation of this file.
00001 /***********************************************************************
00002 *
00003 * KRYPTOS - Educational software for teaching cryptography
00004 * For more information, see http://www.kryptosproject.org/
00005 * Submissions may be sent to kryptos@gmu.edu (see web site for details)
00006 * 
00007 * 
00008 * Copyright (c) 2002-2006 George Mason University
00009 * 
00010 * Permission is hereby granted, free of charge, to any person obtaining
00011 * a copy of this software and associated documentation files (the
00012 * "Software"), to deal in the Software without restriction, including
00013 * without limitation the rights to use, copy, modify, merge, publish,
00014 * distribute, sublicense, and/or sell copies of the Software, and to
00015 * permit persons to whom the Software is furnished to do so, subject
00016 * to the following conditions:
00017 *
00018 * The above copyright notice and this permission notice shall be
00019 * included in all copies or substantial portions of the Software.
00020 *
00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00025 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00026 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00027 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // CryptoPPLink.h : header file
00083 //
00084 
00086 // CCryptoPPLink document
00087 
00093 class CCryptoPPLink : public CCryptoLink
00094 {
00095 private:
00096                 
00097         //MEMBER VARIABLES
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;                             // Disable blinding for RSA
00161 
00162         //CKryptosTimer overallTimer;           // Includes I/O time
00163         //CKryptosTimer internalTimer;  // Includes processing time only
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();           // protected constructor used by dynamic creation
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         // Operations
00209         //MODIFICATION MEMBER FUNCTIONS
00210 
00211 // Overrides
00212         void Serialize(CArchive& ar);   // overridden for document i/o
00213 
00214 // Implementation
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_)

Generated on Sun Dec 17 14:54:15 2006 for Kryptos by  doxygen 1.5.1-p1