00001
00009 #ifndef __PKIFNSSRAW_H__
00010 #define __PKIFNSSRAW_H__
00011
00012 #if _MSC_VER > 1000
00013 #pragma once
00014 #endif // _MSC_VER > 1000
00015
00016 #include "PKIFdll.h"
00017 #include "IPKIFColleague.h"
00018 #include "IPKIFCryptoRaw.h"
00019 #include "IPKIFCryptoMisc.h"
00020 #include "components.h"
00021
00022 struct CPKIFNSSRawImpl;
00031 class CAC_API CPKIFNSSRaw : public IPKIFColleague,
00032 public IPKIFCryptoRaw,
00033 public IPKIFCryptoMisc
00034 {
00035 public:
00036 CPKIFNSSRaw(const std::string & dbdir = "");
00037 virtual ~CPKIFNSSRaw(void);
00038
00039
00040 void Initialize();
00041
00042
00043 void GenRandom(unsigned char* buf, int len);
00044 IPKIFHashContext* HashInit(PKIFCRYPTO::HASH_ALG alg);
00045 void HashUpdate(IPKIFHashContext* hash, unsigned char* pData, int nDataLen);
00046 void HashFinal(IPKIFHashContext* hash, unsigned char* pResult, int* pnResultLen);
00047
00048
00049 bool SupportsAlgorithm(const CPKIFKeyMaterial& key);
00050
00051
00052 void Sign(const CPKIFKeyMaterial& key, unsigned char* pHashData, int nHashDataLen, unsigned char* pSignature, int* nSignatureLen, PKIFCRYPTO::HASH_ALG hashAlg);
00053 void Decrypt(const CPKIFKeyMaterial& key, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool pad = true);
00054 void Encrypt(const CPKIFKeyMaterial& key, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool pad = true);
00055 bool Verify(const CPKIFKeyMaterial& key, unsigned char* pHashData, int nHashDataLen, unsigned char* pSignature, int nSignatureLen, PKIFCRYPTO::HASH_ALG hashAlg);
00056 bool VerifyCertificate(const CPKIFCertificate& issCert, const CPKIFCertificate& subCert);
00057
00058 IPKIFRawCryptContext* CryptInit(const CPKIFKeyMaterial& key, bool pad = true);
00059 void Decrypt(IPKIFRawCryptContext* cryptContext, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool final);
00060 void Encrypt(IPKIFRawCryptContext* cryptContext, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool final);
00061
00062 IPKIFRawCryptContext* HMACInit(const CPKIFKeyMaterial &key, PKIFCRYPTO::HASH_ALG ha);
00063 void HMACUpdate(IPKIFRawCryptContext* ctx, unsigned char* pData, int nDataLen);
00064 void HMACFinal(IPKIFRawCryptContext* ctx, unsigned char* pResult, int* pnResultLen);
00065
00066
00067
00068 enum { thisComponent = TOOLKIT_CRYPTO_NSSRAW };
00069
00070 protected:
00071 template <bool _CryptDirection> void CryptFunc(IPKIFRawCryptContext* cryptContext, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool final);
00072
00073 private:
00075 CPKIFNSSRaw(const CPKIFNSSRaw& copy);
00077 CPKIFNSSRaw& operator=(const CPKIFNSSRaw& rhs);
00078
00079 CPKIFNSSRawImpl * m_impl;
00080 };
00081 DECLARE_SMART_POINTERS(CPKIFNSSRaw);
00082
00083 #endif // !defined(__PKIFNSSRAW_H__)
00084