fix MSVC 2005 warnings

pull/2/head
weidai 2006-03-13 13:26:41 +00:00
parent 80a9a45ad0
commit 922fdeb150
20 changed files with 2618 additions and 2593 deletions

View File

@ -236,12 +236,12 @@ struct WindowSlider
exp >>= skipCount;
windowBegin += skipCount;
expWindow = exp % (1 << windowSize);
expWindow = word32(exp % (word(1) << windowSize));
if (fastNegate && exp.GetBit(windowSize))
{
negateNext = true;
expWindow = (1 << windowSize) - expWindow;
expWindow = (word32(1) << windowSize) - expWindow;
exp += windowModulus;
}
else
@ -249,7 +249,8 @@ struct WindowSlider
}
Integer exp, windowModulus;
unsigned int windowSize, windowBegin, expWindow;
unsigned int windowSize, windowBegin;
word32 expWindow;
bool fastNegate, negateNext, firstTime, finished;
};

View File

@ -1,5 +1,7 @@
// bench.cpp - written and placed in the public domain by Wei Dai
#define _CRT_SECURE_NO_DEPRECATE
#include "bench.h"
#include "crc.h"
#include "adler32.h"

View File

@ -28,10 +28,9 @@ public:
bool IsForwardTransformation() const {return true;}
protected:
const ModularArithmetic modn;
const word maxBits;
ModularArithmetic modn;
word maxBits, bitsLeft;
Integer current;
int bitsLeft;
friend class BlumGoldwasserPublicKey;
friend class BlumGoldwasserPrivateKey;

File diff suppressed because it is too large Load Diff

View File

@ -358,7 +358,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
is.clear();
is.ignore();
if (value[value.size()-1] == '\\')
if (!value.empty() && value[value.size()-1] == '\\')
{
value.resize(value.size()-1);
continueLine = true;

View File

@ -374,9 +374,9 @@ void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const I
std::vector<ProjectivePoint> bases;
std::vector<WindowSlider> exponents;
exponents.reserve(expCount);
std::vector<std::vector<unsigned int> > baseIndices(expCount);
std::vector<std::vector<word32> > baseIndices(expCount);
std::vector<std::vector<bool> > negateBase(expCount);
std::vector<std::vector<unsigned int> > exponentWindows(expCount);
std::vector<std::vector<word32> > exponentWindows(expCount);
unsigned int i;
for (i=0; i<expCount; i++)
@ -432,7 +432,7 @@ void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const I
}
}
std::vector<BaseAndExponent<Point, word> > finalCascade;
std::vector<BaseAndExponent<Point, Integer> > finalCascade;
for (i=0; i<expCount; i++)
{
finalCascade.resize(baseIndices[i].size());
@ -450,7 +450,7 @@ void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const I
else
finalCascade[j].base.y = base.y;
}
finalCascade[j].exponent = exponentWindows[i][j];
finalCascade[j].exponent = Integer(Integer::POSITIVE, 0, exponentWindows[i][j]);
}
results[i] = GeneralCascadeMultiplication(*this, finalCascade.begin(), finalCascade.end());
}

View File

@ -11,6 +11,8 @@ static const int IDEA_KEYLEN=(6*IDEA::ROUNDS+4); // key schedule length in # of
#define low16(x) ((x)&0xffff) // compiler should be able to optimize this away if word is 16 bits
#define high16(x) ((x)>>16)
CRYPTOPP_COMPILE_ASSERT(sizeof(IDEA::Word) >= 2);
// should use an inline function but macros are still faster in MSVC 4.0
#define DirectMUL(a,b) \
{ \
@ -21,7 +23,7 @@ static const int IDEA_KEYLEN=(6*IDEA::ROUNDS+4); // key schedule length in # of
if (p) \
{ \
p = low16(p) - high16(p); \
a = (word)p - (word)high16(p); \
a = (IDEA::Word)p - (IDEA::Word)high16(p); \
} \
else \
a = 1-a-b; \
@ -40,7 +42,7 @@ void IDEA::Base::BuildLogTables()
{
tablesBuilt = true;
word x=1;
IDEA::Word x=1;
word32 i;
for (i=0; i<0x10000; i++)
@ -56,7 +58,7 @@ void IDEA::Base::BuildLogTables()
void IDEA::Base::LookupKeyLogs()
{
word* Z=key;
IDEA::Word* Z=key;
int r=ROUNDS;
do
{
@ -70,7 +72,7 @@ void IDEA::Base::LookupKeyLogs()
Z[3] = log[Z[3]];
}
inline void IDEA::Base::LookupMUL(word &a, word b)
inline void IDEA::Base::LookupMUL(IDEA::Word &a, IDEA::Word b)
{
a = antilog[low16(log[low16(a)]+b)];
}
@ -99,7 +101,7 @@ void IDEA::Base::EnKey (const byte *userKey)
unsigned int i;
for (i=0; i<8; i++)
m_key[i] = ((word)userKey[2*i]<<8) | userKey[2*i+1];
m_key[i] = ((IDEA::Word)userKey[2*i]<<8) | userKey[2*i+1];
for (; i<IDEA_KEYLEN; i++)
{
@ -108,9 +110,9 @@ void IDEA::Base::EnKey (const byte *userKey)
}
}
static word MulInv(word x)
static IDEA::Word MulInv(IDEA::Word x)
{
word y=x;
IDEA::Word y=x;
for (unsigned i=0; i<15; i++)
{
DirectMUL(y,low16(y));
@ -119,14 +121,14 @@ static word MulInv(word x)
return low16(y);
}
static inline word AddInv(word x)
static inline IDEA::Word AddInv(IDEA::Word x)
{
return low16(0-x);
}
void IDEA::Base::DeKey()
{
FixedSizeSecBlock<word, 6*ROUNDS+4> tempkey;
FixedSizeSecBlock<IDEA::Word, 6*ROUNDS+4> tempkey;
unsigned int i;
for (i=0; i<ROUNDS; i++)
@ -157,8 +159,8 @@ void IDEA::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, b
{
typedef BlockGetAndPut<word16, BigEndian> Block;
const word *key = m_key;
word x0,x1,x2,x3,t0,t1;
const IDEA::Word *key = m_key;
IDEA::Word x0,x1,x2,x3,t0,t1;
Block::Get(inBlock)(x0)(x1)(x2)(x3);
for (unsigned int i=0; i<ROUNDS; i++)

10
idea.h
View File

@ -18,6 +18,14 @@ struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public F
/// <a href="http://www.weidai.com/scan-mirror/cs.html#IDEA">IDEA</a>
class IDEA : public IDEA_Info, public BlockCipherDocumentation
{
public: // made public for internal purposes
#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
typedef word Word;
#else
typedef hword Word;
#endif
private:
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<IDEA_Info>
{
public:
@ -29,7 +37,7 @@ class IDEA : public IDEA_Info, public BlockCipherDocumentation
private:
void EnKey(const byte *);
void DeKey();
FixedSizeSecBlock<word, 6*ROUNDS+4> m_key;
FixedSizeSecBlock<Word, 6*ROUNDS+4> m_key;
#ifdef IDEA_LARGECACHE
static inline void LookupMUL(word &a, word b);

View File

@ -123,7 +123,7 @@ static int Compare(const word *A, const word *B, size_t N)
return 0;
}
static word Increment(word *A, size_t N, word B=1)
static int Increment(word *A, size_t N, word B=1)
{
assert(N);
word t = A[0];
@ -136,7 +136,7 @@ static word Increment(word *A, size_t N, word B=1)
return 1;
}
static word Decrement(word *A, size_t N, word B=1)
static int Decrement(word *A, size_t N, word B=1)
{
assert(N);
word t = A[0];
@ -462,8 +462,8 @@ inline word DWord::operator%(word a)
class Portable
{
public:
static word Add(word *C, const word *A, const word *B, size_t N);
static word Subtract(word *C, const word *A, const word *B, size_t N);
static int Add(word *C, const word *A, const word *B, size_t N);
static int Subtract(word *C, const word *A, const word *B, size_t N);
static inline void Multiply2(word *C, const word *A, const word *B);
static inline word Multiply2Add(word *C, const word *A, const word *B);
@ -482,7 +482,7 @@ public:
static inline unsigned int SquareRecursionLimit() {return 4;}
};
word Portable::Add(word *C, const word *A, const word *B, size_t N)
int Portable::Add(word *C, const word *A, const word *B, size_t N)
{
assert (N%2 == 0);
@ -494,10 +494,10 @@ word Portable::Add(word *C, const word *A, const word *B, size_t N)
u = DWord(A[i+1]) + B[i+1] + u.GetHighHalf();
C[i+1] = u.GetLowHalf();
}
return u.GetHighHalf();
return int(u.GetHighHalf());
}
word Portable::Subtract(word *C, const word *A, const word *B, size_t N)
int Portable::Subtract(word *C, const word *A, const word *B, size_t N)
{
assert (N%2 == 0);
@ -509,7 +509,7 @@ word Portable::Subtract(word *C, const word *A, const word *B, size_t N)
u = (DWord) A[i+1] - B[i+1] - u.GetHighHalfAsBorrow();
C[i+1] = u.GetLowHalf();
}
return 0-u.GetHighHalf();
return int(0-u.GetHighHalf());
}
void Portable::Multiply2(word *C, const word *A, const word *B)
@ -991,8 +991,8 @@ static bool IsP4()
class PentiumOptimized : public Portable
{
public:
static word Add(word *C, const word *A, const word *B, size_t N);
static word Subtract(word *C, const word *A, const word *B, size_t N);
static int Add(word *C, const word *A, const word *B, size_t N);
static int Subtract(word *C, const word *A, const word *B, size_t N);
static void Multiply4(word *C, const word *A, const word *B);
static void Multiply8(word *C, const word *A, const word *B);
static void Multiply8Bottom(word *C, const word *A, const word *B);
@ -1001,8 +1001,8 @@ public:
class P4Optimized
{
public:
static word Add(word *C, const word *A, const word *B, size_t N);
static word Subtract(word *C, const word *A, const word *B, size_t N);
static int Add(word *C, const word *A, const word *B, size_t N);
static int Subtract(word *C, const word *A, const word *B, size_t N);
#ifdef SSE2_INTRINSICS_AVAILABLE
static void Multiply4(word *C, const word *A, const word *B);
static void Multiply8(word *C, const word *A, const word *B);
@ -1010,7 +1010,7 @@ public:
#endif
};
typedef word (* PAddSub)(word *C, const word *A, const word *B, size_t N);
typedef int (* PAddSub)(word *C, const word *A, const word *B, size_t N);
typedef void (* PMul)(word *C, const word *A, const word *B);
static PAddSub s_pAdd, s_pSub;
@ -1058,9 +1058,9 @@ void DisableSSE2()
class LowLevel : public PentiumOptimized
{
public:
inline static word Add(word *C, const word *A, const word *B, size_t N)
inline static int Add(word *C, const word *A, const word *B, size_t N)
{return s_pAdd(C, A, B, N);}
inline static word Subtract(word *C, const word *A, const word *B, size_t N)
inline static int Subtract(word *C, const word *A, const word *B, size_t N)
{return s_pSub(C, A, B, N);}
inline static void Square4(word *R, const word *A)
{Multiply4(R, A, A);}
@ -1146,7 +1146,7 @@ public:
);
#endif
CRYPTOPP_NAKED word PentiumOptimized::Add(word *C, const word *A, const word *B, size_t N)
CRYPTOPP_NAKED int PentiumOptimized::Add(word *C, const word *A, const word *B, size_t N)
{
AddPrologue
@ -1184,7 +1184,7 @@ CRYPTOPP_NAKED word PentiumOptimized::Add(word *C, const word *A, const word *B,
AddEpilogue
}
CRYPTOPP_NAKED word PentiumOptimized::Subtract(word *C, const word *A, const word *B, size_t N)
CRYPTOPP_NAKED int PentiumOptimized::Subtract(word *C, const word *A, const word *B, size_t N)
{
AddPrologue
@ -1224,7 +1224,7 @@ CRYPTOPP_NAKED word PentiumOptimized::Subtract(word *C, const word *A, const wor
// On Pentium 4, the adc and sbb instructions are very expensive, so avoid them.
CRYPTOPP_NAKED word P4Optimized::Add(word *C, const word *A, const word *B, size_t N)
CRYPTOPP_NAKED int P4Optimized::Add(word *C, const word *A, const word *B, size_t N)
{
AddPrologue
@ -1271,7 +1271,7 @@ CRYPTOPP_NAKED word P4Optimized::Add(word *C, const word *A, const word *B, size
AddEpilogue
}
CRYPTOPP_NAKED word P4Optimized::Subtract(word *C, const word *A, const word *B, size_t N)
CRYPTOPP_NAKED int P4Optimized::Subtract(word *C, const word *A, const word *B, size_t N)
{
AddPrologue
@ -2090,7 +2090,7 @@ void RecursiveSquare(word *R, word *T, const word *A, size_t N)
RecursiveSquare(R2, T2, A1, N2);
RecursiveMultiply(T0, T2, A0, A1, N2);
word carry = LowLevel::Add(R1, R1, T0, N);
int carry = LowLevel::Add(R1, R1, T0, N);
carry += LowLevel::Add(R1, R1, T0, N);
Increment(R3, N2, carry);
}
@ -2187,9 +2187,9 @@ void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A, const
// now T[01] holds (A1-A0)*(B0-B1), T[23] holds A1*B1
word c2 = LowLevel::Subtract(R0, L+N2, L, N2);
int c2 = LowLevel::Subtract(R0, L+N2, L, N2);
c2 += LowLevel::Subtract(R0, R0, T0, N2);
word t = (Compare(R0, T2, N2) == -1);
int t = (Compare(R0, T2, N2) == -1);
carry += t;
carry += Increment(R0, N2, c2+t);
@ -2202,12 +2202,12 @@ void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A, const
}
}
inline word Add(word *C, const word *A, const word *B, size_t N)
inline int Add(word *C, const word *A, const word *B, size_t N)
{
return LowLevel::Add(C, A, B, N);
}
inline word Subtract(word *C, const word *A, const word *B, size_t N)
inline int Subtract(word *C, const word *A, const word *B, size_t N)
{
return LowLevel::Subtract(C, A, B, N);
}
@ -2738,7 +2738,7 @@ static inline size_t RoundupSize(size_t n)
return 32;
else if (n<=64)
return 64;
else return 1U << BitPrecision(n-1);
else return size_t(1) << BitPrecision(n-1);
}
Integer::Integer()
@ -2786,8 +2786,8 @@ bool Integer::IsConvertableToLong() const
if (ByteCount() > sizeof(long))
return false;
unsigned long value = reg[0];
value += SafeLeftShift<WORD_BITS, unsigned long>(reg[1]);
unsigned long value = (unsigned long)reg[0];
value += SafeLeftShift<WORD_BITS, unsigned long>((unsigned long)reg[1]);
if (sign==POSITIVE)
return (signed long)value >= 0;
@ -2799,8 +2799,8 @@ signed long Integer::ConvertToLong() const
{
assert(IsConvertableToLong());
unsigned long value = reg[0];
value += SafeLeftShift<WORD_BITS, unsigned long>(reg[1]);
unsigned long value = (unsigned long)reg[0];
value += SafeLeftShift<WORD_BITS, unsigned long>((unsigned long)reg[1]);
return sign==POSITIVE ? value : -(signed long)value;
}
@ -2953,7 +2953,7 @@ Integer::Integer(word value, size_t length)
template <class T>
static Integer StringToInteger(const T *str)
{
word radix;
int radix;
// GCC workaround
// std::char_traits<wchar_t>::length() not defined in GCC 3.2 and STLport 4.5.3
unsigned int length;
@ -2987,7 +2987,7 @@ static Integer StringToInteger(const T *str)
for (unsigned i=0; i<length; i++)
{
word digit;
int digit;
if (str[i] >= '0' && str[i] <= '9')
digit = str[i] - '0';
@ -3456,7 +3456,7 @@ Integer& Integer::operator--()
void PositiveAdd(Integer &sum, const Integer &a, const Integer& b)
{
word carry;
int carry;
if (a.reg.size() == b.reg.size())
carry = Add(sum.reg, a.reg, b.reg, a.reg.size());
else if (a.reg.size() > b.reg.size())
@ -3750,7 +3750,7 @@ void Integer::DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigne
CopyWords(r.reg, a.reg, wordCount);
SetWords(r.reg+wordCount, 0, r.reg.size()-wordCount);
if (n % WORD_BITS != 0)
r.reg[wordCount-1] %= (1 << (n % WORD_BITS));
r.reg[wordCount-1] %= (word(1) << (n % WORD_BITS));
}
else
{

View File

@ -278,7 +278,7 @@ public:
//!
Integer& operator/=(word t) {return *this = DividedBy(t);}
//!
Integer& operator%=(word t) {return *this = Modulo(t);}
Integer& operator%=(word t) {return *this = Integer(POSITIVE, 0, Modulo(t));}
//!
Integer& operator<<=(size_t);

View File

@ -84,7 +84,7 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
if (xorBlock)
xorbuf(outBlock, xorBlock, this->buffer, 2*this->S);
else
memcpy(outBlock, this->buffer, 2*this->S);
memcpy_s(outBlock, 2*this->S, this->buffer, 2*this->S);
}
};

2
mdc.h
View File

@ -32,7 +32,7 @@ class MDC : public MDC_Info<T>
{
assert(direction == ENCRYPTION);
this->AssertValidKeyLength(length);
memcpy(Key(), userKey, this->KEYLENGTH);
memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
}

6
misc.h
View File

@ -355,7 +355,7 @@ inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int
int i, carry;
for (i=s-1, carry=1; i>=0 && carry; i--)
carry = !(output[i] = input[i]+1);
memcpy(output, input, i+1);
memcpy_s(output, s, input, i+1);
}
// ************** rotate functions ***************
@ -602,7 +602,7 @@ inline void ConditionalByteReverse(ByteOrder order, T *out, const T *in, size_t
if (!NativeByteOrderIs(order))
ByteReverse(out, in, byteCount);
else if (in != out)
memcpy(out, in, byteCount);
memcpy_s(out, byteCount, in, byteCount);
}
template <class T>
@ -852,7 +852,7 @@ template <class T>
T StringToWord(const std::string &str, ByteOrder order = BIG_ENDIAN_ORDER)
{
T value = 0;
memcpy(&value, str.data(), UnsignedMin(str.size(), sizeof(value)));
memcpy_s(&value, sizeof(value), str.data(), UnsignedMin(str.size(), sizeof(value)));
return NativeByteOrderIs(order) ? value : ByteReverse(value);
}

13
modes.h
View File

@ -90,12 +90,13 @@ protected:
void TransformRegister()
{
m_cipher->ProcessBlock(m_register, m_temp);
memmove(m_register, m_register+m_feedbackSize, BlockSize()-m_feedbackSize);
memcpy(m_register+BlockSize()-m_feedbackSize, m_temp, m_feedbackSize);
unsigned int updateSize = BlockSize()-m_feedbackSize;
memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize);
memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize);
}
void CipherResynchronize(const byte *iv)
{
memcpy(m_register, iv, BlockSize());
memcpy_s(m_register, m_register.size(), iv, BlockSize());
TransformRegister();
}
void SetFeedbackSize(unsigned int feedbackSize)
@ -117,7 +118,7 @@ protected:
inline void CopyOrZero(void *dest, const void *src, size_t s)
{
if (src)
memcpy(dest, src, s);
memcpy_s(dest, s, src, s);
else
memset(dest, 0, s);
}
@ -136,7 +137,7 @@ private:
{
assert(iterationCount == 1);
m_cipher->ProcessBlock(keystreamBuffer);
memcpy(m_register, keystreamBuffer, BlockSize());
memcpy_s(m_register, m_register.size(), keystreamBuffer, BlockSize());
}
void CipherResynchronize(byte *keystreamBuffer, const byte *iv)
{
@ -175,7 +176,7 @@ public:
bool IsRandomAccess() const {return false;}
bool IsSelfInverting() const {return false;}
bool IsForwardTransformation() const {return m_cipher->IsForwardTransformation();}
void Resynchronize(const byte *iv) {memcpy(m_register, iv, BlockSize());}
void Resynchronize(const byte *iv) {memcpy_s(m_register, m_register.size(), iv, BlockSize());}
void ProcessData(byte *outString, const byte *inString, size_t length);
protected:

View File

@ -319,7 +319,7 @@ bool PrimeSieve::NextCandidate(Integer &c)
}
else
{
c = m_first + m_next*m_step;
c = m_first + long(m_next)*m_step;
++m_next;
return true;
}
@ -330,9 +330,9 @@ void PrimeSieve::SieveSingle(std::vector<bool> &sieve, word16 p, const Integer &
if (stepInv)
{
size_t sieveSize = sieve.size();
word j = word((word32(p-(first%p))*stepInv) % p);
size_t j = (word32(p-(first%p))*stepInv) % p;
// if the first multiple of p is p, skip it
if (first.WordCount() <= 1 && first + step*j == p)
if (first.WordCount() <= 1 && first + step*long(j) == p)
j += p;
for (; j < sieveSize; j += p)
sieve[j] = true;
@ -353,7 +353,7 @@ void PrimeSieve::DoSieve()
if (m_delta == 0)
{
for (unsigned int i = 0; i < primeTableSize; ++i)
SieveSingle(m_sieve, primeTable[i], m_first, m_step, m_step.InverseMod(primeTable[i]));
SieveSingle(m_sieve, primeTable[i], m_first, m_step, (word16)m_step.InverseMod(primeTable[i]));
}
else
{
@ -363,7 +363,7 @@ void PrimeSieve::DoSieve()
for (unsigned int i = 0; i < primeTableSize; ++i)
{
word16 p = primeTable[i];
word16 stepInv = m_step.InverseMod(p);
word16 stepInv = (word16)m_step.InverseMod(p);
SieveSingle(m_sieve, p, m_first, m_step, stepInv);
word16 halfStepInv = 2*stepInv < p ? 2*stepInv : 2*stepInv-p;

View File

@ -61,7 +61,7 @@ typename A::pointer StandardReallocate(A& a, T *p, typename A::size_type oldSize
{
A b;
typename A::pointer newPointer = b.allocate(newSize, NULL);
memcpy(newPointer, p, sizeof(T)*STDMIN(oldSize, newSize));
memcpy_s(newPointer, sizeof(T)*newSize, p, sizeof(T)*STDMIN(oldSize, newSize));
a.deallocate(p, oldSize);
std::swap(a, b);
return newPointer;
@ -211,7 +211,7 @@ public:
explicit SecBlock(size_type size=0)
: m_size(size) {m_ptr = m_alloc.allocate(size, NULL);}
SecBlock(const SecBlock<T, A> &t)
: m_size(t.m_size) {m_ptr = m_alloc.allocate(m_size, NULL); memcpy(m_ptr, t.m_ptr, m_size*sizeof(T));}
: m_size(t.m_size) {m_ptr = m_alloc.allocate(m_size, NULL); memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, m_size*sizeof(T));}
SecBlock(const T *t, size_type len)
: m_size(len)
{
@ -270,16 +270,18 @@ public:
size_type size() const {return m_size;}
bool empty() const {return m_size == 0;}
size_type SizeInBytes() const {return m_size*sizeof(T);}
void Assign(const T *t, size_type len)
{
New(len);
memcpy(m_ptr, t, len*sizeof(T));
memcpy_s(m_ptr, m_size*sizeof(T), t, len*sizeof(T));
}
void Assign(const SecBlock<T, A> &t)
{
New(t.m_size);
memcpy(m_ptr, t.m_ptr, m_size*sizeof(T));
memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, m_size*sizeof(T));
}
SecBlock<T, A>& operator=(const SecBlock<T, A> &t)
@ -292,15 +294,15 @@ public:
{
size_type oldSize = m_size;
Grow(m_size+t.m_size);
memcpy(m_ptr+oldSize, t.m_ptr, t.m_size*sizeof(T));
memcpy_s(m_ptr+oldSize, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
return *this;
}
SecBlock<T, A> operator+(const SecBlock<T, A> &t)
{
SecBlock<T, A> result(m_size+t.m_size);
memcpy(result.m_ptr, m_ptr, m_size*sizeof(T));
memcpy(result.m_ptr+m_size, t.m_ptr, t.m_size*sizeof(T));
memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T));
memcpy_s(result.m_ptr+m_size, t.m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
return result;
}

View File

@ -1,6 +1,8 @@
// test.cpp - written and placed in the public domain by Wei Dai
#define _CRT_SECURE_NO_DEPRECATE
#define CRYPTOPP_DEFAULT_NO_DLL
#include "dll.h"
#include "md5.h"
#include "ripemd.h"
@ -190,7 +192,7 @@ int __cdecl main(int argc, char *argv[])
return 1;
}
unsigned int macPos = found-buf.begin();
unsigned int macPos = unsigned int(found-buf.begin());
member_ptr<MessageAuthenticationCode> pMac(NewIntegrityCheckingMAC());
pMac->Update(buf.begin(), macPos);
pMac->Update(buf.begin() + macPos + sizeof(dummyMac), fileSize - sizeof(dummyMac) - macPos);

View File

@ -79,7 +79,7 @@ template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const
GetWord(false, BIG_ENDIAN_ORDER, m_counter, iv);
else
params.GetValue(Name::XMACC_Counter(), m_counter);
memcpy(m_key, key, this->KEYLENGTH);
memcpy_s(m_key, m_key.SizeInBytes(), key, this->KEYLENGTH);
Init();
}
@ -105,7 +105,7 @@ template <class T> inline void XMACC_Base<T>::XorDigest(HashWordType *digest, co
template <class T> void XMACC_Base<T>::HashEndianCorrectedBlock(const HashWordType *input)
{
memcpy(m_buffer, m_key, this->KEYLENGTH);
memcpy_s(m_buffer, m_buffer.SizeInBytes(), m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, ++m_index);
T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
T::Transform(m_buffer, input);
@ -126,7 +126,7 @@ template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, size_t size)
this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
HashEndianCorrectedBlock(this->m_data);
memcpy(m_buffer, m_key, this->KEYLENGTH);
memcpy_s(m_buffer, m_buffer.SizeInBytes(), m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
memset(this->m_data, 0, this->BLOCKSIZE-4);
WriteWord32((byte *)this->m_data.begin()+this->BLOCKSIZE-4, ++m_counter);
@ -137,7 +137,7 @@ template <class T> void XMACC_Base<T>::TruncatedFinal(byte *mac, size_t size)
WriteWord32(mac, m_counter);
T::CorrectEndianess(this->m_digest, this->m_digest, T::DIGESTSIZE);
memcpy(mac+4, this->m_digest, size-4);
memcpy_s(mac+4, size-4, this->m_digest, size-4);
this->Restart(); // reinit for next use
}
@ -152,10 +152,10 @@ template <class T> bool XMACC_Base<T>::TruncatedVerify(const byte *mac, size_t s
this->m_data[this->m_data.size()-1] = ByteReverse(this->GetBitCountLo());
HashEndianCorrectedBlock(this->m_data);
memcpy(m_buffer, m_key, this->KEYLENGTH);
memcpy_s(m_buffer, m_buffer.SizeInBytes(), m_key, this->KEYLENGTH);
WriteWord32((byte *)m_buffer.begin()+this->KEYLENGTH, 0);
memset(this->m_data, 0, this->BLOCKSIZE-4);
memcpy((byte *)this->m_data.begin()+this->BLOCKSIZE-4, mac, 4);
memcpy_s((byte *)this->m_data.begin()+this->BLOCKSIZE-4, 4, mac, 4);
T::CorrectEndianess(m_buffer, m_buffer, T::DIGESTSIZE);
T::CorrectEndianess(this->m_data, this->m_data, this->BLOCKSIZE);
T::Transform(m_buffer, this->m_data);

View File

@ -383,7 +383,7 @@ unsigned int Deflator::LongestMatch(unsigned int &bestMatch) const
if (scan[bestLength-1] == match[bestLength-1] && scan[bestLength] == match[bestLength] && scan[0] == match[0] && scan[1] == match[1])
{
assert(scan[2] == match[2]);
unsigned int len = (unsigned int)(std::mismatch(scan+3, scanEnd, match+3).first - scan);
unsigned int len = (unsigned int)(stdext::unchecked_mismatch(scan+3, scanEnd, match+3).first - scan);
assert(len != bestLength);
if (len > bestLength)
{

View File

@ -138,7 +138,7 @@ void HuffmanDecoder::Initialize(const unsigned int *codeBits, unsigned int nCode
m_normalizedCacheMask = NormalizeCode(m_cacheMask, m_cacheBits);
assert(m_normalizedCacheMask == BitReverse(m_cacheMask));
if (m_cache.size() != 1 << m_cacheBits)
if (m_cache.size() != size_t(1) << m_cacheBits)
m_cache.resize(1 << m_cacheBits);
for (i=0; i<m_cache.size(); i++)