From 1db8ea50840eb47f0f7d8f3c30d8e0916932ce90 Mon Sep 17 00:00:00 2001 From: weidai Date: Tue, 12 Jul 2005 04:23:32 +0000 Subject: port to MSVC .NET 2005 beta 2 --- pwdbased.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'pwdbased.h') diff --git a/pwdbased.h b/pwdbased.h index aa1db3f1..bdd1edcd 100644 --- a/pwdbased.h +++ b/pwdbased.h @@ -13,12 +13,12 @@ NAMESPACE_BEGIN(CryptoPP) class PasswordBasedKeyDerivationFunction { public: - virtual unsigned int MaxDerivedKeyLength() const =0; + virtual size_t MaxDerivedKeyLength() const =0; virtual bool UsesPurposeByte() const =0; //! derive key from password /*! If timeInSeconds != 0, will iterate until time elapsed, as measured by ThreadUserTimer Returns actual iteration count, which is equal to iterations if timeInSeconds == 0, and not less than iterations otherwise. */ - virtual unsigned int DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds=0) const =0; + virtual unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const =0; }; //! PBKDF1 from PKCS #5, T should be a HashTransformation class @@ -26,10 +26,10 @@ template class PKCS5_PBKDF1 : public PasswordBasedKeyDerivationFunction { public: - unsigned int MaxDerivedKeyLength() const {return T::DIGESTSIZE;} + size_t MaxDerivedKeyLength() const {return T::DIGESTSIZE;} bool UsesPurposeByte() const {return false;} // PKCS #5 says PBKDF1 should only take 8-byte salts. This implementation allows salts of any length. - unsigned int DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds=0) const; + unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const; }; //! PBKDF2 from PKCS #5, T should be a HashTransformation class @@ -37,9 +37,9 @@ template class PKCS5_PBKDF2_HMAC : public PasswordBasedKeyDerivationFunction { public: - unsigned int MaxDerivedKeyLength() const {return 0xffffffffU;} // should multiply by T::DIGESTSIZE, but gets overflow that way + size_t MaxDerivedKeyLength() const {return 0xffffffffU;} // should multiply by T::DIGESTSIZE, but gets overflow that way bool UsesPurposeByte() const {return false;} - unsigned int DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds=0) const; + unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const; }; /* @@ -53,7 +53,7 @@ public: */ template -unsigned int PKCS5_PBKDF1::DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds) const +unsigned int PKCS5_PBKDF1::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const { assert(derivedLen <= MaxDerivedKeyLength()); assert(iterations > 0 || timeInSeconds > 0); @@ -82,7 +82,7 @@ unsigned int PKCS5_PBKDF1::DeriveKey(byte *derived, unsigned int derivedLen, } template -unsigned int PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds) const +unsigned int PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const { assert(derivedLen <= MaxDerivedKeyLength()); assert(iterations > 0 || timeInSeconds > 0); @@ -106,7 +106,7 @@ unsigned int PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, unsigned int derived } hmac.Final(buffer); - unsigned int segmentLen = STDMIN(derivedLen, (unsigned int)buffer.size()); + size_t segmentLen = STDMIN(derivedLen, buffer.size()); memcpy(derived, buffer, segmentLen); if (timeInSeconds) @@ -140,13 +140,13 @@ template class PKCS12_PBKDF : public PasswordBasedKeyDerivationFunction { public: - unsigned int MaxDerivedKeyLength() const {return UINT_MAX;} + size_t MaxDerivedKeyLength() const {return size_t(0)-1;} bool UsesPurposeByte() const {return true;} - unsigned int DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds) const; + unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const; }; template -unsigned int PKCS12_PBKDF::DeriveKey(byte *derived, unsigned int derivedLen, byte purpose, const byte *password, unsigned int passwordLen, const byte *salt, unsigned int saltLen, unsigned int iterations, double timeInSeconds) const +unsigned int PKCS12_PBKDF::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const { assert(derivedLen <= MaxDerivedKeyLength()); assert(iterations > 0 || timeInSeconds > 0); @@ -154,14 +154,14 @@ unsigned int PKCS12_PBKDF::DeriveKey(byte *derived, unsigned int derivedLen, if (!iterations) iterations = 1; - const unsigned int v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 - const unsigned int DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); - const unsigned int PLen = RoundUpToMultipleOf(passwordLen, v), ILen = SLen + PLen; + const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 + const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); + const size_t PLen = RoundUpToMultipleOf(passwordLen, v), ILen = SLen + PLen; SecByteBlock buffer(DLen + SLen + PLen); byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; memset(D, purpose, DLen); - unsigned int i; + size_t i; for (i=0; i::DeriveKey(byte *derived, unsigned int derivedLen, if (timeInSeconds) { - iterations = i; + iterations = (unsigned int)i; timeInSeconds = 0; } @@ -199,7 +199,7 @@ unsigned int PKCS12_PBKDF::DeriveKey(byte *derived, unsigned int derivedLen, for (i=0; i