From d5ebf62bed594d1fe6ab616a6bbcbcf0a5892d47 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 git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@198 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- seckey.h | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'seckey.h') diff --git a/seckey.h b/seckey.h index bcbb884..d7f90d2 100644 --- a/seckey.h +++ b/seckey.h @@ -35,13 +35,13 @@ public: protected: template - static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, unsigned int length, const NameValuePairs ¶m) + static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m) { obj->ThrowIfInvalidKeyLength(length); int rounds = param.GetIntValueWithDefault("Rounds", ROUNDS); if (rounds != ROUNDS) throw InvalidRounds(obj->StaticAlgorithmName(), rounds); - obj->UncheckedSetKey(dir, key, length); + obj->UncheckedSetKey(dir, key, (unsigned int)length); } }; @@ -51,7 +51,7 @@ class VariableRounds { public: enum {DEFAULT_ROUNDS = D, MIN_ROUNDS = N, MAX_ROUNDS = M}; - static unsigned int StaticGetDefaultRounds(unsigned int keylength) {return DEFAULT_ROUNDS;} + static unsigned int StaticGetDefaultRounds(size_t keylength) {return DEFAULT_ROUNDS;} protected: static inline void AssertValidRounds(unsigned int rounds) @@ -60,13 +60,13 @@ protected: } template - static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, unsigned int length, const NameValuePairs ¶m) + static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m) { obj->ThrowIfInvalidKeyLength(length); int rounds = param.GetIntValueWithDefault("Rounds", obj->StaticGetDefaultRounds(length)); if (rounds < (int)MIN_ROUNDS || rounds > (int)MAX_ROUNDS) throw InvalidRounds(obj->AlgorithmName(), rounds); - obj->UncheckedSetKey(dir, key, length, rounds); + obj->UncheckedSetKey(dir, key, (unsigned int)length, rounds); } }; @@ -79,7 +79,7 @@ class FixedKeyLength public: enum {KEYLENGTH=N, MIN_KEYLENGTH=N, MAX_KEYLENGTH=N, DEFAULT_KEYLENGTH=N}; enum {IV_REQUIREMENT = IV_REQ}; - static unsigned int CRYPTOPP_API StaticGetValidKeyLength(unsigned int) {return KEYLENGTH;} + static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t) {return KEYLENGTH;} }; /// support query of variable key length, template parameters are default, min, max, multiple (default multiple 1) @@ -96,12 +96,12 @@ class VariableKeyLength public: enum {MIN_KEYLENGTH=N, MAX_KEYLENGTH=M, DEFAULT_KEYLENGTH=D, KEYLENGTH_MULTIPLE=Q}; enum {IV_REQUIREMENT = IV_REQ}; - static unsigned int CRYPTOPP_API StaticGetValidKeyLength(unsigned int n) + static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t n) { - if (n < (unsigned int)MIN_KEYLENGTH) + if (n < (size_t)MIN_KEYLENGTH) return MIN_KEYLENGTH; - else if (n > (unsigned int)MAX_KEYLENGTH) - return (unsigned int)MAX_KEYLENGTH; + else if (n > (size_t)MAX_KEYLENGTH) + return (size_t)MAX_KEYLENGTH; else { n += KEYLENGTH_MULTIPLE-1; @@ -117,24 +117,24 @@ class SameKeyLengthAs public: enum {MIN_KEYLENGTH=T::MIN_KEYLENGTH, MAX_KEYLENGTH=T::MAX_KEYLENGTH, DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH}; enum {IV_REQUIREMENT = T::IV_REQUIREMENT}; - static unsigned int CRYPTOPP_API StaticGetValidKeyLength(unsigned int keylength) + static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) {return T::StaticGetValidKeyLength(keylength);} }; // ************** implementation helper for SimpledKeyed *************** template -static inline void CheckedSetKey(T *obj, Empty empty, const byte *key, unsigned int length, const NameValuePairs ¶m) +static inline void CheckedSetKey(T *obj, Empty empty, const byte *key, size_t length, const NameValuePairs ¶m) { obj->ThrowIfInvalidKeyLength(length); - obj->UncheckedSetKey(key, length); + obj->UncheckedSetKey(key, (unsigned int)length); } template -static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, unsigned int length, const NameValuePairs ¶m) +static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m) { obj->ThrowIfInvalidKeyLength(length); - obj->UncheckedSetKey(dir, key, length); + obj->UncheckedSetKey(dir, key, (unsigned int)length); } //! _ @@ -142,14 +142,14 @@ template class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE { public: - unsigned int MinKeyLength() const {return INFO::MIN_KEYLENGTH;} - unsigned int MaxKeyLength() const {return (unsigned int)INFO::MAX_KEYLENGTH;} - unsigned int DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;} - unsigned int GetValidKeyLength(unsigned int n) const {return INFO::StaticGetValidKeyLength(n);} + size_t MinKeyLength() const {return INFO::MIN_KEYLENGTH;} + size_t MaxKeyLength() const {return (size_t)INFO::MAX_KEYLENGTH;} + size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;} + size_t GetValidKeyLength(size_t n) const {return INFO::StaticGetValidKeyLength(n);} typename BASE::IV_Requirement IVRequirement() const {return (typename BASE::IV_Requirement)INFO::IV_REQUIREMENT;} protected: - void AssertValidKeyLength(unsigned int length) {assert(GetValidKeyLength(length) == length);} + void AssertValidKeyLength(size_t length) {assert(GetValidKeyLength(length) == length);} }; template @@ -167,14 +167,14 @@ public: BlockCipherFinal() {} BlockCipherFinal(const byte *key) {SetKey(key, this->DEFAULT_KEYLENGTH);} - BlockCipherFinal(const byte *key, unsigned int length) + BlockCipherFinal(const byte *key, size_t length) {SetKey(key, length);} - BlockCipherFinal(const byte *key, unsigned int length, unsigned int rounds) + BlockCipherFinal(const byte *key, size_t length, unsigned int rounds) {this->SetKeyWithRounds(key, length, rounds);} bool IsForwardTransformation() const {return DIR == ENCRYPTION;} - void SetKey(const byte *key, unsigned int length, const NameValuePairs ¶m = g_nullNameValuePairs) + void SetKey(const byte *key, size_t length, const NameValuePairs ¶m = g_nullNameValuePairs) { CheckedSetKey(this, DIR, key, length, param); } @@ -185,7 +185,7 @@ template class MessageAuthenticationCodeImpl : public AlgorithmImpl, INFO> { public: - void SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms = g_nullNameValuePairs) + void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs) { CheckedSetKey(this, Empty(), key, length, params); } @@ -199,7 +199,7 @@ public: MessageAuthenticationCodeFinal() {} MessageAuthenticationCodeFinal(const byte *key) {SetKey(key, this->DEFAULT_KEYLENGTH);} - MessageAuthenticationCodeFinal(const byte *key, unsigned int length) + MessageAuthenticationCodeFinal(const byte *key, size_t length) {this->SetKey(key, length);} }; -- cgit v1.2.1