Make OST buildable w/ Apple Clang with -std=c++17. Changes are mostly avoiding conflict w/ std::byte, and replacing std::ptr_fun with lambdas, and getting rid of set_unexpected calls

This commit is contained in:
Brian Cox 2018-10-13 20:56:05 -07:00
parent ee71c537a8
commit 432efb34fb
57 changed files with 522 additions and 492 deletions

View File

@ -360,7 +360,7 @@ cFile::File_t cFile::Read(void* buffer, File_t nBytes) const //throw(eFile)
}
else
{
iBytesRead = fread(buffer, sizeof(byte), nBytes, mpData->mpCurrStream);
iBytesRead = fread(buffer, sizeof(uint8_t), nBytes, mpData->mpCurrStream);
if (ferror(mpData->mpCurrStream) != 0)
{
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
@ -382,7 +382,7 @@ cFile::File_t cFile::Write(const void* buffer, File_t nBytes) //throw(eFile)
ASSERT(mpData->mpCurrStream != NULL);
ASSERT(isWritable);
if ((actual_count = fwrite(buffer, sizeof(byte), nBytes, mpData->mpCurrStream)) < nBytes)
if ((actual_count = fwrite(buffer, sizeof(uint8_t), nBytes, mpData->mpCurrStream)) < nBytes)
throw eFileWrite(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
else
return actual_count;

View File

@ -32,11 +32,11 @@
// hashtable.h : a template class for mapping tuples using TCHAR*'s
//
// implements cHashTable, which maps a key of arbitrary type to a value
// of arbitrary type. The key data type MUST have the const byte*()
// of arbitrary type. The key data type MUST have the const uint8_t*()
// operator overloaded in order for this to work. TSTRINGS will always
// work as the key value because of the overloaded-template-function
//
// Note: Any overloaded const byte*() operator must return an
// Note: Any overloaded const uint8_t*() operator must return an
// length of key as well. see cDefaultConvert
//
// IMPORTANT -- cDefaultConvert only works for pointers to objects
@ -85,26 +85,26 @@ template<> inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs,
///////////////////////////////////////////////////////////////////////////////
// Conversion function objects ... used by the hash table to locate the key in KEY_TYPE
// into a byte* and a key length (for hashing purposes). The default implementation
// into a uint8_t* and a key length (for hashing purposes). The default implementation
// just does a cast. A specialization is also provided for TSTRINGs.
///////////////////////////////////////////////////////////////////////////////
template<class T> class cDefaultConvert
{
public:
const byte* operator()(const T& obj, int* const pcbKeyLen)
const uint8_t* operator()(const T& obj, int* const pcbKeyLen)
{
// HACK! TODO: in the interest of time, I've left this as it is.....
*pcbKeyLen = sizeof(TCHAR) * _tcslen(obj);
return (byte*)obj;
return (uint8_t*)obj;
}
};
/////////////////////////////////////////////////////////
// specialization for TSTRINGS
/////////////////////////////////////////////////////////
template<> inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen)
template<> inline const uint8_t* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen)
{
*pcbKeyLen = sizeof(TCHAR) * obj.length();
return (byte*)obj.c_str();
return (uint8_t*)obj.c_str();
}
///////////////////////////////////////////////////////////////////////////////
@ -113,8 +113,8 @@ template<> inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING
// VAL -- the value you want associated with that key
// CMP -- a function object that takes (KEY, KEY) and returns true if they
// are equal.
// CONVERTER -- function object that takes (KEY, int* pcbKeyLen) and returns a const byte*
// ( points to start of key ) and a byte length (in pcbKeyLen) that tells the hashtable
// CONVERTER -- function object that takes (KEY, int* pcbKeyLen) and returns a const uint8_t*
// ( points to start of key ) and a uint8_t length (in pcbKeyLen) that tells the hashtable
// how long the key is
///////////////////////////////////////////////////////////////////////////////
// these were moved outside of the class because it sucks to have to name the class with template parameters
@ -510,7 +510,7 @@ uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash(const KEY_TYP
{
CONVERTER converter;
int len;
const byte* pb = converter(key, &len); //locates key
const uint8_t* pb = converter(key, &len); //locates key
uint32 hindex;
hindex = *pb;

View File

@ -222,27 +222,27 @@ static uint8 padding[128] = { /* constants for padding */
#define rotate_right(x, n) (((x) >> (n)) | ((x) << (32-(n))))
#define FF_1(x7, x6, x5, x4, x3, x2, x1, x0, w) { \
register haval_word temp = Fphi_1(x6, x5, x4, x3, x2, x1, x0); \
haval_word temp = Fphi_1(x6, x5, x4, x3, x2, x1, x0); \
(x7) = rotate_right(temp, 7) + rotate_right((x7), 11) + (w); \
}
#define FF_2(x7, x6, x5, x4, x3, x2, x1, x0, w, c) { \
register haval_word temp = Fphi_2(x6, x5, x4, x3, x2, x1, x0); \
haval_word temp = Fphi_2(x6, x5, x4, x3, x2, x1, x0); \
(x7) = rotate_right(temp, 7) + rotate_right((x7), 11) + (w) + (c); \
}
#define FF_3(x7, x6, x5, x4, x3, x2, x1, x0, w, c) { \
register haval_word temp = Fphi_3(x6, x5, x4, x3, x2, x1, x0); \
haval_word temp = Fphi_3(x6, x5, x4, x3, x2, x1, x0); \
(x7) = rotate_right(temp, 7) + rotate_right((x7), 11) + (w) + (c); \
}
#define FF_4(x7, x6, x5, x4, x3, x2, x1, x0, w, c) { \
register haval_word temp = Fphi_4(x6, x5, x4, x3, x2, x1, x0); \
haval_word temp = Fphi_4(x6, x5, x4, x3, x2, x1, x0); \
(x7) = rotate_right(temp, 7) + rotate_right((x7), 11) + (w) + (c); \
}
#define FF_5(x7, x6, x5, x4, x3, x2, x1, x0, w, c) { \
register haval_word temp = Fphi_5(x6, x5, x4, x3, x2, x1, x0); \
haval_word temp = Fphi_5(x6, x5, x4, x3, x2, x1, x0); \
(x7) = rotate_right(temp, 7) + rotate_right((x7), 11) + (w) + (c); \
}
@ -448,7 +448,7 @@ void haval_end (haval_state* state, uint8 final_fpt[FPTLEN >> 3])
/* hash a 32-word block */
void haval_hash_block (haval_state* state)
{
register haval_word t0 = state->fingerprint[0], /* make use of */
haval_word t0 = state->fingerprint[0], /* make use of */
t1 = state->fingerprint[1], /* internal registers */
t2 = state->fingerprint[2],
t3 = state->fingerprint[3],

View File

@ -227,7 +227,7 @@ char *getenv(); /* get variable from environment */
char *str;
# endif
{
register char *p; /* temp pointer */
char *p; /* temp pointer */
/*
* allocate space for the string, and copy if successful
@ -253,7 +253,7 @@ char **old;
int *sz_alloc;
#endif
{
register int i; /* counter in a for loop */
int i; /* counter in a for loop */
union xyzzy x; /* used to cast malloc properly */
/*
@ -284,8 +284,8 @@ static int initenv(void)
static int initenv()
#endif
{
register int i;
register int rval;
int i;
int rval;
if (envp != NULL)
le_clobber();
@ -306,7 +306,7 @@ void le_clobber(void)
void le_clobber()
#endif
{
register int i; /* counter in a for loop */
int i; /* counter in a for loop */
union {
char **ep;
char *p;
@ -344,8 +344,8 @@ static int le_getenv(var)
char *var;
#endif
{
register int i; /* counter in a for loop */
register char *p, *q; /* used to compare two strings */
int i; /* counter in a for loop */
char *p, *q; /* used to compare two strings */
/*
* check for no environment
@ -385,8 +385,8 @@ int le_set(env)
char *env;
#endif
{
register char *p, *q; /* what is to be put into env */
register int n; /* where a previous definition is */
char *p, *q; /* what is to be put into env */
int n; /* where a previous definition is */
/*
* see if you need to create the environment list
@ -475,7 +475,7 @@ int le_unset(env)
char *env;
#endif
{
register int i; /* counter in a for loop */
int i; /* counter in a for loop */
/*
* delete it from the environment
@ -595,8 +595,8 @@ static const char *shellenv(void)
static const char *shellenv()
#endif
{
register int i; /* counter in a for loop */
register const char *shptr; /* points to shell name */
int i; /* counter in a for loop */
const char *shptr; /* points to shell name */
/*
* error check; should never happen
@ -631,9 +631,9 @@ char *cmd;
#endif
{
const char *argv[5]; /* argument list */
register const char *p; /* temoporary pointers */
register const char* shptr; /* the program to be run */
register int i; /* index number of child */
const char *p; /* temoporary pointers */
const char* shptr; /* the program to be run */
int i; /* index number of child */
/*
* if it's NULL, initialize it
@ -684,10 +684,10 @@ char *mode;
#endif
{
const char *argv[5]; /* argument list */
register const char *p; /* temoporary pointers */
register const char *shptr; /* the program to be run */
const char *p; /* temoporary pointers */
const char *shptr; /* the program to be run */
FILE *fpa[3]; /* process communication descriptors */
register int indx; /* index number of child */
int indx; /* index number of child */
/*
* see if anything is available
@ -733,8 +733,8 @@ int mpclose(fp)
FILE *fp;
#endif
{
register int indx; /* used to look for corresponding pid */
register int rstatus; /* return status of command */
int indx; /* used to look for corresponding pid */
int rstatus; /* return status of command */
/*
* loop until you find the right process
@ -771,9 +771,9 @@ FILE *fpa[];
#endif
{
const char *argv[5]; /* argument list */
register const char *p; /* temoporary pointers */
register const char *shptr; /* the program to be run */
register int indx; /* index number of child */
const char *p; /* temoporary pointers */
const char *shptr; /* the program to be run */
int indx; /* index number of child */
/*
* see if anything is available
@ -816,7 +816,7 @@ int indx;
FILE *fp[];
#endif
{
register int rstatus; /* return status of command */
int rstatus; /* return status of command */
/*
* loop until you find the right process
@ -850,7 +850,7 @@ char *argv[];
FILE *fpa[];
#endif
{
register int indx; /* index number of child */
int indx; /* index number of child */
/*
* see if anything is available
@ -910,9 +910,9 @@ int mask;
#endif
{
int p[3][2]; /* pipes to/from child */
register int i; /* counter in for loop */
register int ch_pid; /* child PID */
register int euid, egid; /* in case reset[gu]id is -1 */
int i; /* counter in for loop */
int ch_pid; /* child PID */
int euid, egid; /* in case reset[gu]id is -1 */
/*
* create 1 pipe for each of standard input, output, error
*/
@ -1029,7 +1029,7 @@ int pid;
#endif
{
register int r; /* PID of process just exited */
int r; /* PID of process just exited */
int status; /* status of wait call */
/*

View File

@ -84,10 +84,10 @@
class tss_hash_key_convert
{
public:
const byte* operator()(const wc16_string& s, int* const pcbKeyLen)
const uint8_t* operator()(const wc16_string& s, int* const pcbKeyLen)
{
*pcbKeyLen = sizeof(WCHAR16) * s.length();
return (byte*)s.c_str();
return (uint8_t*)s.c_str();
}
};

View File

@ -44,8 +44,9 @@
//-----------------------------------------------------------------------------
// standard TSS types
//-----------------------------------------------------------------------------
typedef unsigned char byte; // platform-independent
#if __cplusplus < 201103L
typedef unsigned char uint8_t
#endif
typedef signed char int8;
typedef short int16;

View File

@ -6,19 +6,19 @@
#include <stdlib.h>
#include <stdio.h>
unsigned int DERLengthEncode(unsigned int length, byte *output)
unsigned int DERLengthEncode(unsigned int length, uint8_t *output)
{
unsigned int i=0;
if (length <= 0x7f)
{
output[i++] = byte(length);
output[i++] = uint8_t(length);
}
else
{
output[i++] = byte(BytePrecision(length) | 0x80);
output[i++] = uint8_t(BytePrecision(length) | 0x80);
for (int j=BytePrecision(length); j; --j)
{
output[i++] = byte (length >> (j-1)*8);
output[i++] = uint8_t (length >> (j-1)*8);
}
}
return i;
@ -26,7 +26,7 @@ unsigned int DERLengthEncode(unsigned int length, byte *output)
unsigned int DERLengthEncode(unsigned int length, BufferedTransformation &bt)
{
byte buf[10]; // should be more than enough
uint8_t buf[10]; // should be more than enough
unsigned int i = DERLengthEncode(length, buf);
assert(i <= 10);
bt.Put(buf, i);
@ -35,7 +35,7 @@ unsigned int DERLengthEncode(unsigned int length, BufferedTransformation &bt)
bool BERLengthDecode(BufferedTransformation &bt, unsigned int &length)
{
byte b;
uint8_t b;
if (!bt.Get(b))
BERDecodeError();
@ -76,7 +76,7 @@ bool BERLengthDecode(BufferedTransformation &bt, unsigned int &length)
BERSequenceDecoder::BERSequenceDecoder(BufferedTransformation &inQueue)
: inQueue(inQueue)
{
byte b;
uint8_t b;
if (!inQueue.Get(b) || b != (SEQUENCE | CONSTRUCTED))
BERDecodeError();

View File

@ -8,7 +8,7 @@
enum ASNTag {INTEGER=0x02, BIT_STRING=0x03, SEQUENCE=0x10};
enum ASNIdFlag {CONSTRUCTED = 0x20};
unsigned int DERLengthEncode(unsigned int length, byte *output);
unsigned int DERLengthEncode(unsigned int length, uint8_t *output);
unsigned int DERLengthEncode(unsigned int length, BufferedTransformation &);
#ifdef THROW_EXCEPTIONS
@ -27,16 +27,16 @@ public:
BERSequenceDecoder(BufferedTransformation &inQueue);
~BERSequenceDecoder();
void Put(byte) {}
void Put(const byte *, unsigned int) {}
void Put(uint8_t) {}
void Put(const uint8_t *, unsigned int) {}
unsigned long MaxRetrieveable()
{return inQueue.MaxRetrieveable();}
unsigned int Get(byte &outByte)
unsigned int Get(uint8_t &outByte)
{return inQueue.Get(outByte);}
unsigned int Get(byte *outString, unsigned int getMax)
unsigned int Get(uint8_t *outString, unsigned int getMax)
{return inQueue.Get(outString, getMax);}
unsigned int Peek(byte &outByte) const
unsigned int Peek(uint8_t &outByte) const
{return inQueue.Peek(outByte);}
private:

View File

@ -82,7 +82,10 @@
// Make sure these typedefs are correct for your computer
typedef unsigned char byte;
#if __cplusplus < 201103L
typedef unsigned char uint8_t;
#endif
typedef unsigned short word16;
#if SIZEOF_INT == 4
typedef unsigned int word32;

View File

@ -9,7 +9,7 @@ unsigned int RandomNumberGenerator::GetBit()
return Parity(GetByte());
}
void RandomNumberGenerator::GetBlock(byte *output, unsigned int size)
void RandomNumberGenerator::GetBlock(uint8_t *output, unsigned int size)
{
while (size--)
*output++ = GetByte();
@ -35,19 +35,19 @@ word32 RandomNumberGenerator::GetLong(word32 min, word32 max)
return value+min;
}
void StreamCipher::ProcessString(byte *outString, const byte *inString, unsigned int length)
void StreamCipher::ProcessString(uint8_t *outString, const uint8_t *inString, unsigned int length)
{
while(length--)
*outString++ = ProcessByte(*inString++);
}
void StreamCipher::ProcessString(byte *inoutString, unsigned int length)
void StreamCipher::ProcessString(uint8_t *inoutString, unsigned int length)
{
for(;length--; inoutString++)
*inoutString = ProcessByte(*inoutString);
}
bool MessageAuthenticationCode::Verify(const byte *macIn)
bool MessageAuthenticationCode::Verify(const uint8_t *macIn)
{
SecByteBlock mac(DigestSize());
Final(mac);
@ -82,11 +82,11 @@ void BufferedTransformation::PutShort(word16 value, bool highFirst)
if (highFirst)
{
Put(value>>8);
Put(byte(value));
Put(uint8_t(value));
}
else
{
Put(byte(value));
Put(uint8_t(value));
Put(value>>8);
}
}
@ -96,12 +96,12 @@ void BufferedTransformation::PutLong(word32 value, bool highFirst)
if (highFirst)
{
for (int i=0; i<4; i++)
Put(byte(value>>((3-i)*8)));
Put(uint8_t(value>>((3-i)*8)));
}
else
{
for (int i=0; i<4; i++)
Put(byte(value>>(i*8)));
Put(uint8_t(value>>(i*8)));
}
}
@ -110,7 +110,7 @@ int BufferedTransformation::GetShort(word16 &value, bool highFirst)
if (MaxRetrieveable()<2)
return 0;
byte buf[2];
uint8_t buf[2];
Get(buf, 2);
if (highFirst)
@ -126,7 +126,7 @@ int BufferedTransformation::GetLong(word32 &value, bool highFirst)
if (MaxRetrieveable()<4)
return 0;
byte buf[4];
uint8_t buf[4];
Get(buf, 4);
if (highFirst)
@ -139,7 +139,7 @@ int BufferedTransformation::GetLong(word32 &value, bool highFirst)
unsigned int BufferedTransformation::Skip(unsigned int skipMax)
{
byte b;
uint8_t b;
unsigned int skipActual=0;
while (skipMax-- && Get(b))
@ -163,7 +163,7 @@ unsigned int PK_FixedLengthCryptoSystem::CipherTextLength(unsigned int plainText
return 0;
}
unsigned int PK_FixedLengthDecryptor::Decrypt(const byte *cipherText, unsigned int cipherTextLength, byte *plainText)
unsigned int PK_FixedLengthDecryptor::Decrypt(const uint8_t *cipherText, unsigned int cipherTextLength, uint8_t *plainText)
{
if (cipherTextLength != CipherTextLength())
return 0;
@ -171,7 +171,7 @@ unsigned int PK_FixedLengthDecryptor::Decrypt(const byte *cipherText, unsigned i
return Decrypt(cipherText, plainText);
}
bool PK_VerifierWithRecovery::Verify(const byte *message, unsigned int messageLength, const byte *signature)
bool PK_VerifierWithRecovery::Verify(const uint8_t *message, unsigned int messageLength, const uint8_t *signature)
{
SecByteBlock recovered(MaxMessageLength());
unsigned int rLen = Recover(signature, recovered);

View File

@ -53,11 +53,11 @@ public:
/// encrypt or decrypt one block in place
//* Precondition: size of inoutBlock == BlockSize().
virtual void ProcessBlock(byte *inoutBlock) =0;
virtual void ProcessBlock(uint8_t *inoutBlock) =0;
/// encrypt or decrypt one block, may assume inBlock != outBlock
//* Precondition: size of inBlock and outBlock == BlockSize().
virtual void ProcessBlock(const byte *inBlock, byte *outBlock) =0;
virtual void ProcessBlock(const uint8_t *inBlock, uint8_t *outBlock) =0;
/// block size of the cipher in bytes
virtual unsigned int BlockSize() const =0;
@ -73,12 +73,12 @@ public:
virtual ~StreamCipher() {}
/// encrypt or decrypt one byte
virtual byte ProcessByte(byte input) =0;
virtual uint8_t ProcessByte(uint8_t input) =0;
/// encrypt or decrypt an array of bytes of specified length in place
virtual void ProcessString(byte *inoutString, unsigned int length);
virtual void ProcessString(uint8_t *inoutString, unsigned int length);
/// encrypt or decrypt an array of bytes of specified length, may assume inString != outString
virtual void ProcessString(byte *outString, const byte *inString, unsigned int length);
virtual void ProcessString(uint8_t *outString, const uint8_t *inString, unsigned int length);
};
/// abstract base class for random access stream ciphers
@ -103,7 +103,7 @@ public:
virtual ~RandomNumberGenerator() {}
/// generate new random byte and return it
virtual byte GetByte() =0;
virtual uint8_t GetByte() =0;
/// generate new random bit and return it
/** Default implementation is to call GetByte() and return its parity. */
@ -117,7 +117,7 @@ public:
/// generate random array of bytes
//* Default implementation is to call GetByte size times.
virtual void GetBlock(byte *output, unsigned int size);
virtual void GetBlock(uint8_t *output, unsigned int size);
};
/// randomly shuffle the specified array, resulting permutation is uniformly distributed
@ -141,18 +141,18 @@ public:
virtual ~HashModule() {}
/// process more input
virtual void Update(const byte *input, unsigned int length) =0;
virtual void Update(const uint8_t *input, unsigned int length) =0;
/*/ calculate hash for the current message (the concatenation of all
inputs passed in via Update()), then reinitialize the object */
//* Precondition: size of digest == DigestSize().
virtual void Final(byte *digest) =0;
virtual void Final(uint8_t *digest) =0;
/// size of the hash returned by Final()
virtual unsigned int DigestSize() const =0;
/// use this if your input is short and you don't want to call Update() and Final() seperately
virtual void CalculateDigest(byte *digest, const byte *input, int length)
virtual void CalculateDigest(uint8_t *digest, const uint8_t *input, int length)
{Update(input, length); Final(digest);}
};
@ -173,10 +173,10 @@ public:
/// verify that mac is a valid MAC for the current message, then reinitialize the object
/** Default implementation is to call Final() and do a bitwise comparison
between its output and mac. */
virtual bool Verify(const byte *mac);
virtual bool Verify(const uint8_t *mac);
/// use this if your input is short and you don't want to call Update() and Verify() seperately
virtual bool VerifyMAC(const byte *mac, const byte *input, int length)
virtual bool VerifyMAC(const uint8_t *mac, const uint8_t *input, int length)
{Update(input, length); return Verify(mac);}
};
@ -203,9 +203,9 @@ public:
//@Man: INPUT
//@{
/// input a byte for processing
virtual void Put(byte inByte) =0;
virtual void Put(uint8_t inByte) =0;
/// input multiple bytes
virtual void Put(const byte *inString, unsigned int length) =0;
virtual void Put(const uint8_t *inString, unsigned int length) =0;
/// signal that no more input is available
virtual void InputFinished() {}
@ -224,9 +224,9 @@ public:
virtual unsigned long MaxRetrieveable() =0;
/// try to retrieve a single byte
virtual unsigned int Get(byte &outByte) =0;
virtual unsigned int Get(uint8_t &outByte) =0;
/// try to retrieve multiple bytes
virtual unsigned int Get(byte *outString, unsigned int getMax) =0;
virtual unsigned int Get(uint8_t *outString, unsigned int getMax) =0;
/// try to retrieve a 16-bit word, big-endian or little-endian depending on highFirst
int GetShort(word16 &value, bool highFirst=true);
@ -239,7 +239,7 @@ public:
virtual unsigned int TransferTo(BufferedTransformation &target, unsigned int transferMax);
/// peek at the next byte without removing it from the output buffer
virtual unsigned int Peek(byte &outByte) const =0;
virtual unsigned int Peek(uint8_t &outByte) const =0;
/// discard some bytes from the output buffer
unsigned int Skip(unsigned int skipMax);
@ -299,7 +299,7 @@ public:
\item size of cipherText == CipherTextLength(plainTextLength)
\end{itemize}
*/
virtual void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) =0;
virtual void Encrypt(RandomNumberGenerator &rng, const uint8_t *plainText, unsigned int plainTextLength, uint8_t *cipherText) =0;
};
/// abstract base class for public-key decryptors
@ -317,7 +317,7 @@ public:
The function returns the actual length of the plaintext, or 0
if decryption fails.
*/
virtual unsigned int Decrypt(const byte *cipherText, unsigned int cipherTextLength, byte *plainText) =0;
virtual unsigned int Decrypt(const uint8_t *cipherText, unsigned int cipherTextLength, uint8_t *plainText) =0;
};
/// abstract base class for encryptors and decryptors with fixed length ciphertext
@ -361,9 +361,9 @@ public:
The function returns the actual length of the plaintext, or 0
if decryption fails.
*/
virtual unsigned int Decrypt(const byte *cipherText, byte *plainText) =0;
virtual unsigned int Decrypt(const uint8_t *cipherText, uint8_t *plainText) =0;
unsigned int Decrypt(const byte *cipherText, unsigned int cipherTextLength, byte *plainText);
unsigned int Decrypt(const uint8_t *cipherText, unsigned int cipherTextLength, uint8_t *plainText);
};
/// abstract base class for public-key signers and verifiers
@ -402,7 +402,7 @@ public:
\item size of signature == SignatureLength()
\end{itemize}
*/
virtual void Sign(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature) =0;
virtual void Sign(RandomNumberGenerator &rng, const uint8_t *message, unsigned int messageLen, uint8_t *signature) =0;
};
/// abstract base class for public-key verifiers
@ -420,7 +420,7 @@ public:
\item length of signature == SignatureLength()
\end{itemize}
*/
virtual bool Verify(const byte *message, unsigned int messageLen, const byte *sig) =0;
virtual bool Verify(const uint8_t *message, unsigned int messageLen, const uint8_t *sig) =0;
};
/// abstract base class for public-key verifiers with recovery
@ -439,9 +439,9 @@ public:
\item size of recoveredMessage == MaxMessageLength()
\end{itemize}
*/
virtual unsigned int Recover(const byte *signature, byte *recoveredMessage) =0;
virtual unsigned int Recover(const uint8_t *signature, uint8_t *recoveredMessage) =0;
bool Verify(const byte *message, unsigned int messageLen, const byte *signature);
bool Verify(const uint8_t *message, unsigned int messageLen, const uint8_t *signature);
};
/// abstract base class for key agreement protocols
@ -471,7 +471,7 @@ public:
/// produce public value
//* Precondition: size of publicValue == PublicValueLength()
virtual void Setup(RandomNumberGenerator &rng, byte *publicValue) =0;
virtual void Setup(RandomNumberGenerator &rng, uint8_t *publicValue) =0;
/// calculate agreed key given other party's public value
/** Precondition:
@ -480,7 +480,7 @@ public:
\item size of agreedKey == AgreedKeyLength()
\end{itemize}
*/
virtual void Agree(const byte *otherPublicValue, byte *agreedKey) const =0;
virtual void Agree(const uint8_t *otherPublicValue, uint8_t *agreedKey) const =0;
};
/// abstract base class for all objects that support precomputation

View File

@ -28,7 +28,7 @@
*/
#ifdef notdef
/* initial permutation IP */
static byte ip[] = {
static uint8_t ip[] = {
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
@ -40,7 +40,7 @@ static byte ip[] = {
};
/* final permutation IP^-1 */
static byte fp[] = {
static uint8_t fp[] = {
40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30,
@ -51,7 +51,7 @@ static byte fp[] = {
33, 1, 41, 9, 49, 17, 57, 25
};
/* expansion operation matrix */
static byte ei[] = {
static uint8_t ei[] = {
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
@ -62,7 +62,7 @@ static byte ei[] = {
28, 29, 30, 31, 32, 1
};
/* The (in)famous S-boxes */
static byte sbox[8][64] = {
static uint8_t sbox[8][64] = {
/* S1 */
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
@ -113,7 +113,7 @@ static byte sbox[8][64] = {
};
/* 32-bit permutation function P used on the output of the S-boxes */
static byte p32i[] = {
static uint8_t p32i[] = {
16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
@ -126,7 +126,7 @@ static byte p32i[] = {
#endif
/* permuted choice table (key) */
static const byte pc1[] = {
static const uint8_t pc1[] = {
57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
@ -139,12 +139,12 @@ static const byte pc1[] = {
};
/* number left rotations of pc1 */
static const byte totrot[] = {
static const uint8_t totrot[] = {
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28
};
/* permuted choice key (table) */
static const byte pc2[] = {
static const uint8_t pc2[] = {
14, 17, 11, 24, 1, 5,
3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8,
@ -163,14 +163,14 @@ static const int bytebit[] = {
};
/* Set key (initialize key schedule array) */
DES::DES(const byte *key, CipherDir dir)
DES::DES(const uint8_t *key, CipherDir dir)
: k(32)
{
SecByteBlock buffer(56+56+8);
byte *const pc1m=buffer; /* place to modify pc1 into */
byte *const pcr=pc1m+56; /* place to rotate pc1 into */
byte *const ks=pcr+56;
register unsigned int i,j,l;
uint8_t *const pc1m=buffer; /* place to modify pc1 into */
uint8_t *const pcr=pc1m+56; /* place to rotate pc1 into */
uint8_t *const ks=pcr+56;
unsigned int i,j,l;
int m;
for (j=0; j<56; j++) { /* convert pc1 to bits of key */
@ -311,7 +311,7 @@ inline void FPERM(word32 &left, word32 &right)
}
// Encrypt or decrypt a block of data in ECB mode
void DES::ProcessBlock(const byte *inBlock, byte * outBlock)
void DES::ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock)
{
word32 l,r,work;
@ -363,56 +363,56 @@ void DES::ProcessBlock(const byte *inBlock, byte * outBlock)
#endif
}
void DES_EDE_Encryption::ProcessBlock(byte *inoutBlock)
void DES_EDE_Encryption::ProcessBlock(uint8_t *inoutBlock)
{
e.ProcessBlock(inoutBlock);
d.ProcessBlock(inoutBlock);
e.ProcessBlock(inoutBlock);
}
void DES_EDE_Encryption::ProcessBlock(const byte *inBlock, byte *outBlock)
void DES_EDE_Encryption::ProcessBlock(const uint8_t *inBlock, uint8_t *outBlock)
{
e.ProcessBlock(inBlock, outBlock);
d.ProcessBlock(outBlock);
e.ProcessBlock(outBlock);
}
void DES_EDE_Decryption::ProcessBlock(byte *inoutBlock)
void DES_EDE_Decryption::ProcessBlock(uint8_t *inoutBlock)
{
d.ProcessBlock(inoutBlock);
e.ProcessBlock(inoutBlock);
d.ProcessBlock(inoutBlock);
}
void DES_EDE_Decryption::ProcessBlock(const byte *inBlock, byte *outBlock)
void DES_EDE_Decryption::ProcessBlock(const uint8_t *inBlock, uint8_t *outBlock)
{
d.ProcessBlock(inBlock, outBlock);
e.ProcessBlock(outBlock);
d.ProcessBlock(outBlock);
}
void TripleDES_Encryption::ProcessBlock(byte *inoutBlock)
void TripleDES_Encryption::ProcessBlock(uint8_t *inoutBlock)
{
e1.ProcessBlock(inoutBlock);
d.ProcessBlock(inoutBlock);
e2.ProcessBlock(inoutBlock);
}
void TripleDES_Encryption::ProcessBlock(const byte *inBlock, byte *outBlock)
void TripleDES_Encryption::ProcessBlock(const uint8_t *inBlock, uint8_t *outBlock)
{
e1.ProcessBlock(inBlock, outBlock);
d.ProcessBlock(outBlock);
e2.ProcessBlock(outBlock);
}
void TripleDES_Decryption::ProcessBlock(byte *inoutBlock)
void TripleDES_Decryption::ProcessBlock(uint8_t *inoutBlock)
{
d1.ProcessBlock(inoutBlock);
e.ProcessBlock(inoutBlock);
d2.ProcessBlock(inoutBlock);
}
void TripleDES_Decryption::ProcessBlock(const byte *inBlock, byte *outBlock)
void TripleDES_Decryption::ProcessBlock(const uint8_t *inBlock, uint8_t *outBlock)
{
d1.ProcessBlock(inBlock, outBlock);
e.ProcessBlock(outBlock);

View File

@ -7,10 +7,10 @@
class DES : public BlockTransformation
{
public:
DES(const byte *userKey, CipherDir);
DES(const uint8_t *userKey, CipherDir);
void ProcessBlock(const byte *inBlock, byte * outBlock);
void ProcessBlock(byte * inoutBlock)
void ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock);
void ProcessBlock(uint8_t * inoutBlock)
{DES::ProcessBlock(inoutBlock, inoutBlock);}
enum {KEYLENGTH=8, BLOCKSIZE=8};
@ -25,25 +25,25 @@ protected:
class DESEncryption : public DES
{
public:
DESEncryption(const byte * userKey)
DESEncryption(const uint8_t * userKey)
: DES (userKey, ENCRYPTION) {}
};
class DESDecryption : public DES
{
public:
DESDecryption(const byte * userKey)
DESDecryption(const uint8_t * userKey)
: DES (userKey, DECRYPTION) {}
};
class DES_EDE_Encryption : public BlockTransformation
{
public:
DES_EDE_Encryption(const byte * userKey)
DES_EDE_Encryption(const uint8_t * userKey)
: e(userKey, ENCRYPTION), d(userKey + DES::KEYLENGTH, DECRYPTION) {}
void ProcessBlock(const byte *inBlock, byte * outBlock);
void ProcessBlock(byte * inoutBlock);
void ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock);
void ProcessBlock(uint8_t * inoutBlock);
enum {KEYLENGTH=16, BLOCKSIZE=8};
unsigned int BlockSize() const {return BLOCKSIZE;}
@ -55,11 +55,11 @@ private:
class DES_EDE_Decryption : public BlockTransformation
{
public:
DES_EDE_Decryption(const byte * userKey)
DES_EDE_Decryption(const uint8_t * userKey)
: d(userKey, DECRYPTION), e(userKey + DES::KEYLENGTH, ENCRYPTION) {}
void ProcessBlock(const byte *inBlock, byte * outBlock);
void ProcessBlock(byte * inoutBlock);
void ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock);
void ProcessBlock(uint8_t * inoutBlock);
enum {KEYLENGTH=16, BLOCKSIZE=8};
unsigned int BlockSize() const {return BLOCKSIZE;}
@ -71,12 +71,12 @@ private:
class TripleDES_Encryption : public BlockTransformation
{
public:
TripleDES_Encryption(const byte * userKey)
TripleDES_Encryption(const uint8_t * userKey)
: e1(userKey, ENCRYPTION), d(userKey + DES::KEYLENGTH, DECRYPTION),
e2(userKey + 2*DES::KEYLENGTH, ENCRYPTION) {}
void ProcessBlock(const byte *inBlock, byte * outBlock);
void ProcessBlock(byte * inoutBlock);
void ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock);
void ProcessBlock(uint8_t * inoutBlock);
enum {KEYLENGTH=24, BLOCKSIZE=8};
unsigned int BlockSize() const {return BLOCKSIZE;}
@ -88,12 +88,12 @@ private:
class TripleDES_Decryption : public BlockTransformation
{
public:
TripleDES_Decryption(const byte * userKey)
TripleDES_Decryption(const uint8_t * userKey)
: d1(userKey + 2*DES::KEYLENGTH, DECRYPTION), e(userKey + DES::KEYLENGTH, ENCRYPTION),
d2(userKey, DECRYPTION) {}
void ProcessBlock(const byte *inBlock, byte * outBlock);
void ProcessBlock(byte * inoutBlock);
void ProcessBlock(const uint8_t *inBlock, uint8_t * outBlock);
void ProcessBlock(uint8_t * inoutBlock);
enum {KEYLENGTH=24, BLOCKSIZE=8};
unsigned int BlockSize() const {return BLOCKSIZE;}

View File

@ -53,7 +53,7 @@ void ElGamalCryptoPublicKey::SavePrecomputation(BufferedTransformation &bt) cons
ypc.Save(bt);
}
void ElGamalCryptoPublicKey::Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText)
void ElGamalCryptoPublicKey::Encrypt(RandomNumberGenerator &rng, const uint8_t *plainText, unsigned int plainTextLength, uint8_t *cipherText)
{
assert(plainTextLength <= MaxPlainTextLength());
@ -140,7 +140,7 @@ void ElGamalCryptoPrivateKey::DEREncode(BufferedTransformation &bt) const
x.DEREncode(seq);
}
unsigned int ElGamalCryptoPrivateKey::Decrypt(const byte *cipherText, byte *plainText)
unsigned int ElGamalCryptoPrivateKey::Decrypt(const uint8_t *cipherText, uint8_t *plainText)
{
Integer a(cipherText, modulusLen);
Integer b(cipherText+modulusLen, modulusLen);
@ -211,7 +211,7 @@ void ElGamalSigPublicKey::SavePrecomputation(BufferedTransformation &bt) const
ypc.Save(bt);
}
bool ElGamalSigPublicKey::Verify(const byte *message, unsigned int messageLen, const byte *signature)
bool ElGamalSigPublicKey::Verify(const uint8_t *message, unsigned int messageLen, const uint8_t *signature)
{
assert(messageLen <= MaxMessageLength());
@ -287,7 +287,7 @@ void ElGamalSigPrivateKey::DEREncode(BufferedTransformation &bt) const
x.DEREncode(seq);
}
void ElGamalSigPrivateKey::Sign(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature)
void ElGamalSigPrivateKey::Sign(RandomNumberGenerator &rng, const uint8_t *message, unsigned int messageLen, uint8_t *signature)
{
assert(messageLen <= MaxMessageLength());

View File

@ -17,7 +17,7 @@ public:
void LoadPrecomputation(BufferedTransformation &storedPrecomputation);
void SavePrecomputation(BufferedTransformation &storedPrecomputation) const;
void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText);
void Encrypt(RandomNumberGenerator &rng, const uint8_t *plainText, unsigned int plainTextLength, uint8_t *cipherText);
unsigned int MaxPlainTextLength() const {return STDMIN(255U, modulusLen-3);}
unsigned int CipherTextLength() const {return 2*modulusLen;}
@ -45,7 +45,7 @@ public:
ElGamalCryptoPrivateKey(BufferedTransformation &bt);
void DEREncode(BufferedTransformation &bt) const;
unsigned int Decrypt(const byte *cipherText, byte *plainText);
unsigned int Decrypt(const uint8_t *cipherText, uint8_t *plainText);
protected:
void RawDecrypt(const Integer &a, const Integer &b, Integer &m) const;
@ -65,7 +65,7 @@ public:
void LoadPrecomputation(BufferedTransformation &storedPrecomputation);
void SavePrecomputation(BufferedTransformation &storedPrecomputation) const;
bool Verify(const byte *message, unsigned int messageLen, const byte *signature);
bool Verify(const uint8_t *message, unsigned int messageLen, const uint8_t *signature);
// message length for signature is unlimited, but only message digests should be signed
unsigned int MaxMessageLength() const {return 0xffff;}
@ -97,7 +97,7 @@ public:
ElGamalSigPrivateKey(BufferedTransformation &bt);
void DEREncode(BufferedTransformation &bt) const;
void Sign(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature);
void Sign(RandomNumberGenerator &rng, const uint8_t *message, unsigned int messageLen, uint8_t *signature);
const Integer& GetParameterX() { return x; }

View File

@ -51,7 +51,7 @@ void BlockFilterBase::ProcessBuf()
inBufSize=0;
}
void BlockFilterBase::Put(const byte *inString, unsigned int length)
void BlockFilterBase::Put(const uint8_t *inString, unsigned int length)
{
while (length--)
BlockFilterBase::Put(*inString++);
@ -75,7 +75,7 @@ void BlockDecryptionFilter::InputFinished()
inBufSize=0;
}
void StreamCipherFilter::Put(const byte *inString, unsigned int length)
void StreamCipherFilter::Put(const uint8_t *inString, unsigned int length)
{
SecByteBlock temp(length);
cipher.ProcessString(temp, inString, length);
@ -89,13 +89,13 @@ void HashFilter::InputFinished()
outQueue->Put(buf, hash.DigestSize());
}
BufferedTransformation *Insert(const byte *in, unsigned int length, BufferedTransformation *outQueue)
BufferedTransformation *Insert(const uint8_t *in, unsigned int length, BufferedTransformation *outQueue)
{
outQueue->Put(in, length);
return outQueue;
}
unsigned int Extract(Source *source, byte *out, unsigned int length)
unsigned int Extract(Source *source, uint8_t *out, unsigned int length)
{
while (source->MaxRetrieveable() < length && source->Pump(1));
return source->Get(out, length);

View File

@ -20,12 +20,12 @@ public:
unsigned long MaxRetrieveable()
{return outQueue->MaxRetrieveable();}
unsigned int Get(byte &outByte)
unsigned int Get(uint8_t &outByte)
{return outQueue->Get(outByte);}
unsigned int Get(byte *outString, unsigned int getMax)
unsigned int Get(uint8_t *outString, unsigned int getMax)
{return outQueue->Get(outString, getMax);}
unsigned int Peek(byte &outByte) const
unsigned int Peek(uint8_t &outByte) const
{return outQueue->Peek(outByte);}
BufferedTransformation *OutQueue() {return outQueue.get();}
@ -44,14 +44,14 @@ public:
BufferedTransformation *outQueue);
virtual ~BlockFilterBase() {}
void Put(byte inByte)
void Put(uint8_t inByte)
{
if (inBufSize == S)
ProcessBuf();
inBuf[inBufSize++]=inByte;
}
void Put(const byte *inString, unsigned int length);
void Put(const uint8_t *inString, unsigned int length);
protected:
void ProcessBuf();
@ -89,10 +89,10 @@ public:
BufferedTransformation *outQueue = NULL)
: Filter(outQueue), cipher(c) {}
void Put(byte inByte)
void Put(uint8_t inByte)
{outQueue->Put(cipher.ProcessByte(inByte));}
void Put(const byte *inString, unsigned int length);
void Put(const uint8_t *inString, unsigned int length);
private:
StreamCipher &cipher;
@ -106,10 +106,10 @@ public:
void InputFinished();
void Put(byte inByte)
void Put(uint8_t inByte)
{hash.Update(&inByte, 1);}
void Put(const byte *inString, unsigned int length)
void Put(const uint8_t *inString, unsigned int length)
{hash.Update(inString, length);}
private:
@ -122,9 +122,9 @@ public:
Source(BufferedTransformation *outQ = NULL)
: Filter(outQ) {}
void Put(byte)
void Put(uint8_t)
{Pump(1);}
void Put(const byte *, unsigned int length)
void Put(const uint8_t *, unsigned int length)
{Pump(length);}
void InputFinished()
{PumpAll();}
@ -138,22 +138,22 @@ class Sink : public BufferedTransformation
public:
unsigned long MaxRetrieveable()
{return 0;}
unsigned int Get(byte &)
unsigned int Get(uint8_t &)
{return 0;}
unsigned int Get(byte *, unsigned int)
unsigned int Get(uint8_t *, unsigned int)
{return 0;}
unsigned int Peek(byte &) const
unsigned int Peek(uint8_t &) const
{return 0;}
};
class BitBucket : public Sink
{
public:
void Put(byte) {}
void Put(const byte *, unsigned int) {}
void Put(uint8_t) {}
void Put(const uint8_t *, unsigned int) {}
};
BufferedTransformation *Insert(const byte *in, unsigned int length, BufferedTransformation *outQueue);
unsigned int Extract(Source *source, byte *out, unsigned int length);
BufferedTransformation *Insert(const uint8_t *in, unsigned int length, BufferedTransformation *outQueue);
unsigned int Extract(Source *source, uint8_t *out, unsigned int length);
#endif

View File

@ -49,13 +49,13 @@ void Fork::Close()
outPorts[i]->Close();
}
void Fork::Put(byte inByte)
void Fork::Put(uint8_t inByte)
{
for (unsigned int i=0; i<numberOfPorts; i++)
outPorts[i]->Put(inByte);
}
void Fork::Put(const byte *inString, unsigned int length)
void Fork::Put(const uint8_t *inString, unsigned int length)
{
for (unsigned int i=0; i<numberOfPorts; i++)
outPorts[i]->Put(inString, length);
@ -95,13 +95,13 @@ void Join::NotifyClose(unsigned int /* id */)
// ********************************************************
void Interface::Put(byte inByte)
void Interface::Put(uint8_t inByte)
{
bq.Put(inByte);
parent.NotifyInput(id, 1);
}
void Interface::Put(const byte *inString, unsigned int length)
void Interface::Put(const uint8_t *inString, unsigned int length)
{
bq.Put(inString, length);
parent.NotifyInput(id, length);
@ -127,17 +127,17 @@ void Interface::Attach(BufferedTransformation *bt)
parent.Attach(bt);
}
unsigned int Interface::Get(byte &outByte)
unsigned int Interface::Get(uint8_t &outByte)
{
return parent.Get(outByte);
}
unsigned int Interface::Get(byte *outString, unsigned int getMax)
unsigned int Interface::Get(uint8_t *outString, unsigned int getMax)
{
return parent.Get(outString, getMax);
}
unsigned int Interface::Peek(byte &outByte) const
unsigned int Interface::Peek(uint8_t &outByte) const
{
return parent.Peek(outByte);
}

View File

@ -22,15 +22,15 @@ public:
// virtual void InputFinished()
// {outPorts[currentPort]->InputFinished();}
unsigned int Get(byte &outByte)
unsigned int Get(uint8_t &outByte)
{return outPorts[currentPort]->Get(outByte);}
unsigned int Get(byte *outString, unsigned int getMax)
unsigned int Get(uint8_t *outString, unsigned int getMax)
{return outPorts[currentPort]->Get(outString, getMax);}
unsigned int Peek(byte &outByte) const
unsigned int Peek(uint8_t &outByte) const
{return outPorts[currentPort]->Peek(outByte);}
virtual void Put(byte inByte);
virtual void Put(const byte *inString, unsigned int length);
virtual void Put(uint8_t inByte);
virtual void Put(const uint8_t *inString, unsigned int length);
protected:
unsigned int NumberOfPorts() const {return numberOfPorts;}
@ -57,11 +57,11 @@ public:
void Detach(BufferedTransformation *bt);
void Attach(BufferedTransformation *bt);
void Put(byte inByte);
void Put(const byte *inString, unsigned int length);
unsigned int Get(byte &outByte);
unsigned int Get(byte *outString, unsigned int getMax);
unsigned int Peek(byte &outByte) const;
void Put(uint8_t inByte);
void Put(const uint8_t *inString, unsigned int length);
unsigned int Get(uint8_t &outByte);
unsigned int Get(uint8_t *outString, unsigned int getMax);
unsigned int Peek(uint8_t &outByte) const;
private:
Join &parent;
@ -83,8 +83,8 @@ public:
virtual void NotifyInput(unsigned int interfaceId, unsigned int length);
virtual void NotifyClose(unsigned int interfaceId);
void Put(byte inByte) {outQueue->Put(inByte);}
void Put(const byte *inString, unsigned int length)
void Put(uint8_t inByte) {outQueue->Put(inByte);}
void Put(const uint8_t *inString, unsigned int length)
{outQueue->Put(inString, length);}
protected:

View File

@ -1159,12 +1159,12 @@ long Integer::ConvertToLong() const
return sign==POSITIVE ? value : -long(value);
}
Integer::Integer(const byte *encodedInteger, unsigned int byteCount, Signedness s)
Integer::Integer(const uint8_t *encodedInteger, unsigned int byteCount, Signedness s)
{
Decode(encodedInteger, byteCount, s);
}
Integer::Integer(const byte *BEREncodedInteger)
Integer::Integer(const uint8_t *BEREncodedInteger)
{
BERDecode(BEREncodedInteger);
}
@ -1241,15 +1241,15 @@ void Integer::SetBit(unsigned int n, bool value)
}
}
byte Integer::GetByte(unsigned int n) const
uint8_t Integer::GetByte(unsigned int n) const
{
if (n/WORD_SIZE >= reg.size)
return 0;
else
return byte(reg[n/WORD_SIZE] >> ((n%WORD_SIZE)*8));
return uint8_t(reg[n/WORD_SIZE] >> ((n%WORD_SIZE)*8));
}
void Integer::SetByte(unsigned int n, byte value)
void Integer::SetByte(unsigned int n, uint8_t value)
{
reg.CleanGrow(RoundupSize(bytesToWords(n+1)));
reg[n/WORD_SIZE] &= ~(word(0xff) << 8*(n%WORD_SIZE));
@ -1360,7 +1360,7 @@ unsigned int Integer::BitCount() const
return 0;
}
void Integer::Decode(const byte *input, unsigned int inputLen, Signedness s)
void Integer::Decode(const uint8_t *input, unsigned int inputLen, Signedness s)
{
sign = ((s==SIGNED) && (input[0] & 0x80)) ? NEGATIVE : POSITIVE;
@ -1395,7 +1395,7 @@ unsigned int Integer::MinEncodedSize(Signedness signedness) const
return outputLen;
}
unsigned int Integer::Encode(byte *output, unsigned int outputLen, Signedness signedness) const
unsigned int Integer::Encode(uint8_t *output, unsigned int outputLen, Signedness signedness) const
{
if (signedness == UNSIGNED || NotNegative())
{
@ -1412,7 +1412,7 @@ unsigned int Integer::Encode(byte *output, unsigned int outputLen, Signedness si
return outputLen;
}
unsigned int Integer::DEREncode(byte *output) const
unsigned int Integer::DEREncode(uint8_t *output) const
{
unsigned int i=0;
output[i++] = INTEGER;
@ -1435,7 +1435,7 @@ unsigned int Integer::DEREncode(BufferedTransformation &bt) const
return 1+lengthBytes+bc;
}
void Integer::BERDecode(const byte *input)
void Integer::BERDecode(const uint8_t *input)
{
if (*input++ != INTEGER)
BERDecodeError();
@ -1456,7 +1456,7 @@ void Integer::BERDecode(const byte *input)
void Integer::BERDecode(BufferedTransformation &bt)
{
byte b;
uint8_t b;
if (!bt.Get(b) || b != INTEGER)
BERDecodeError();
@ -1475,7 +1475,7 @@ void Integer::Randomize(RandomNumberGenerator &rng, unsigned int nbits)
const unsigned int nbytes = nbits/8 + 1;
SecByteBlock buf(nbytes);
rng.GetBlock(buf, nbytes);
buf[(unsigned int)0] = (byte)Crop(buf[(unsigned int)0], nbits % 8);
buf[(unsigned int)0] = (uint8_t)Crop(buf[(unsigned int)0], nbits % 8);
Decode(buf, nbytes, UNSIGNED);
}

View File

@ -62,10 +62,10 @@ public:
Integer(const char *str);
/// convert from big-endian byte array
Integer(const byte *encodedInteger, unsigned int byteCount, Signedness s=UNSIGNED);
Integer(const uint8_t *encodedInteger, unsigned int byteCount, Signedness s=UNSIGNED);
/// convert from Basic Encoding Rules encoded byte array
Integer(const byte *BEREncodedInteger);
Integer(const uint8_t *BEREncodedInteger);
/// convert from BER encoded byte array stored in a BufferedTransformation object
Integer(BufferedTransformation &bt);
@ -104,10 +104,10 @@ public:
if outputLen < MinEncodedSize, the most significant bytes will be dropped
if outputLen > MinEncodedSize, the most significant bytes will be padded
*/
unsigned int Encode(byte *output, unsigned int outputLen, Signedness=UNSIGNED) const;
unsigned int Encode(uint8_t *output, unsigned int outputLen, Signedness=UNSIGNED) const;
/// encode integer using Distinguished Encoding Rules, returns size of output
unsigned int DEREncode(byte *output) const;
unsigned int DEREncode(uint8_t *output) const;
/// encode using DER, put result into a BufferedTransformation object
unsigned int DEREncode(BufferedTransformation &bt) const;
@ -121,7 +121,7 @@ public:
/// return the n-th bit, n=0 being the least significant bit
bool GetBit(unsigned int n) const;
/// return the n-th byte
byte GetByte(unsigned int n) const;
uint8_t GetByte(unsigned int n) const;
///
bool IsNegative() const {return sign == NEGATIVE;}
@ -161,10 +161,10 @@ public:
Integer& operator>>=(unsigned int);
///
void Decode(const byte *input, unsigned int inputLen, Signedness=UNSIGNED);
void Decode(const uint8_t *input, unsigned int inputLen, Signedness=UNSIGNED);
///
void BERDecode(const byte *input);
void BERDecode(const uint8_t *input);
///
void BERDecode(BufferedTransformation &bt);
@ -178,7 +178,7 @@ public:
/// set the n-th bit to value
void SetBit(unsigned int n, bool value=1);
/// set the n-th byte to value
void SetByte(unsigned int n, byte value);
void SetByte(unsigned int n, uint8_t value);
///
void Negate();

View File

@ -15,12 +15,12 @@ template <class T> class IteratedHash : public virtual HashModule
public:
IteratedHash(unsigned int blockSize, unsigned int digestSize);
~IteratedHash();
void Update(const byte *input, unsigned int length);
void Update(const uint8_t *input, unsigned int length);
typedef T HashWordType;
protected:
void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
void PadLastBlock(unsigned int lastBlockSize, uint8_t padFirst=0x80);
virtual void Init() =0;
virtual void HashBlock(const T *input) =0;
@ -39,7 +39,7 @@ template <class T> IteratedHash<T>::~IteratedHash()
{
}
template <class T> void IteratedHash<T>::Update(const byte *input, unsigned int len)
template <class T> void IteratedHash<T>::Update(const uint8_t *input, unsigned int len)
{
word32 tmp = countLo;
if ((countLo = tmp + ((word32)len << 3)) < tmp)
@ -53,7 +53,7 @@ template <class T> void IteratedHash<T>::Update(const byte *input, unsigned int
{
if ((num+len) >= blockSize)
{
memcpy((byte *)data.ptr+num, input, blockSize-num);
memcpy((uint8_t *)data.ptr+num, input, blockSize-num);
HashBlock(data);
input += (blockSize-num);
len-=(blockSize - num);
@ -62,7 +62,7 @@ template <class T> void IteratedHash<T>::Update(const byte *input, unsigned int
}
else
{
memcpy((byte *)data.ptr+num, input, len);
memcpy((uint8_t *)data.ptr+num, input, len);
return;
}
}
@ -91,16 +91,16 @@ template <class T> void IteratedHash<T>::Update(const byte *input, unsigned int
memcpy(data, input, len);
}
template <class T> void IteratedHash<T>::PadLastBlock(unsigned int lastBlockSize, byte padFirst)
template <class T> void IteratedHash<T>::PadLastBlock(unsigned int lastBlockSize, uint8_t padFirst)
{
unsigned int num = (unsigned int)(countLo >> 3) & (blockSize-1);
assert(num < blockSize);
((byte *)data.ptr)[num++]=padFirst;
((uint8_t *)data.ptr)[num++]=padFirst;
if (num <= lastBlockSize)
memset((byte *)data.ptr+num, 0, lastBlockSize-num);
memset((uint8_t *)data.ptr+num, 0, lastBlockSize-num);
else
{
memset((byte *)data.ptr+num, 0, blockSize-num);
memset((uint8_t *)data.ptr+num, 0, blockSize-num);
HashBlock(data);
memset(data, 0, lastBlockSize);
}

View File

@ -4,7 +4,7 @@
#include "misc.h"
#include "words.h"
void xorbuf(byte *buf, const byte *mask, unsigned int count)
void xorbuf(uint8_t *buf, const uint8_t *mask, unsigned int count)
{
if (((ptr_size_type)buf | (ptr_size_type)mask | count) % WORD_SIZE == 0)
XorWords((word *)buf, (const word *)mask, count/WORD_SIZE);
@ -15,7 +15,7 @@ void xorbuf(byte *buf, const byte *mask, unsigned int count)
}
}
void xorbuf(byte *output, const byte *input, const byte *mask, unsigned int count)
void xorbuf(uint8_t *output, const uint8_t *input, const uint8_t *mask, unsigned int count)
{
if (((ptr_size_type)output | (ptr_size_type)input | (ptr_size_type)mask | count) % WORD_SIZE == 0)
XorWords((word *)output, (const word *)input, (const word *)mask, count/WORD_SIZE);

View File

@ -31,8 +31,8 @@ inline unsigned int bitsToWords(unsigned int bitCount)
return ((bitCount+WORD_BITS-1)/(WORD_BITS));
}
void xorbuf(byte *buf, const byte *mask, unsigned int count);
void xorbuf(byte *output, const byte *input, const byte *mask, unsigned int count);
void xorbuf(uint8_t *buf, const uint8_t *mask, unsigned int count);
void xorbuf(uint8_t *output, const uint8_t *input, const uint8_t *mask, unsigned int count);
template <class T> inline T rotl(T x, unsigned int y)
{
@ -262,7 +262,7 @@ template <class T> void SecBlock<T>::swap(SecBlock<T> &b)
std::swap(ptr, b.ptr);
}
typedef SecBlock<byte> SecByteBlock;
typedef SecBlock<uint8_t> SecByteBlock;
typedef SecBlock<word> SecWordBlock;
#endif // MISC_H

View File

@ -15,20 +15,20 @@ public:
unsigned int UsedUp() const
{return (head==MaxSize());}
unsigned int Put(byte inByte);
unsigned int Put(const byte *inString, unsigned int length);
unsigned int Put(uint8_t inByte);
unsigned int Put(const uint8_t *inString, unsigned int length);
unsigned int Get(byte &outByte);
unsigned int Get(byte *outString, unsigned int getMax);
unsigned int Get(uint8_t &outByte);
unsigned int Get(uint8_t *outString, unsigned int getMax);
unsigned int Peek(byte &outByte) const;
unsigned int Peek(uint8_t &outByte) const;
void CopyTo(BufferedTransformation &target) const
{target.Put(buf+head, tail-head);}
void CopyTo(byte *target) const
void CopyTo(uint8_t *target) const
{memcpy(target, buf+head, tail-head);}
byte operator[](unsigned int i) const
uint8_t operator[](unsigned int i) const
{return buf[i-head];}
ByteQueueNode *next;
@ -48,7 +48,7 @@ ByteQueueNode::ByteQueueNode(unsigned int maxSize)
next = 0;
}
unsigned int ByteQueueNode::Put(byte inByte)
unsigned int ByteQueueNode::Put(uint8_t inByte)
{
if (MaxSize()==tail)
return 0;
@ -57,7 +57,7 @@ unsigned int ByteQueueNode::Put(byte inByte)
return 1;
}
unsigned int ByteQueueNode::Put(const byte *inString, unsigned int length)
unsigned int ByteQueueNode::Put(const uint8_t *inString, unsigned int length)
{
unsigned int l = STDMIN(length, MaxSize()-tail);
memcpy(buf+tail, inString, l);
@ -65,7 +65,7 @@ unsigned int ByteQueueNode::Put(const byte *inString, unsigned int length)
return l;
}
unsigned int ByteQueueNode::Get(byte &outByte)
unsigned int ByteQueueNode::Get(uint8_t &outByte)
{
if (tail==head)
return 0;
@ -74,7 +74,7 @@ unsigned int ByteQueueNode::Get(byte &outByte)
return 1;
}
unsigned int ByteQueueNode::Get(byte *outString, unsigned int getMax)
unsigned int ByteQueueNode::Get(uint8_t *outString, unsigned int getMax)
{
unsigned int l = STDMIN(getMax, tail-head);
memcpy(outString, buf+head, l);
@ -82,7 +82,7 @@ unsigned int ByteQueueNode::Get(byte *outString, unsigned int getMax)
return l;
}
unsigned int ByteQueueNode::Peek(byte &outByte) const
unsigned int ByteQueueNode::Peek(uint8_t &outByte) const
{
if (tail==head)
return 0;
@ -140,7 +140,7 @@ void ByteQueue::CopyTo(BufferedTransformation &target) const
current->CopyTo(target);
}
void ByteQueue::CopyTo(byte *target) const
void ByteQueue::CopyTo(uint8_t *target) const
{
for (ByteQueueNode *current=head; current; current=current->next)
{
@ -159,7 +159,7 @@ unsigned long ByteQueue::CurrentSize() const
return size;
}
void ByteQueue::Put(byte inByte)
void ByteQueue::Put(uint8_t inByte)
{
if (!tail->Put(inByte))
{
@ -169,7 +169,7 @@ void ByteQueue::Put(byte inByte)
}
}
void ByteQueue::Put(const byte *inString, unsigned int length)
void ByteQueue::Put(const uint8_t *inString, unsigned int length)
{
unsigned int l;
@ -182,7 +182,7 @@ void ByteQueue::Put(const byte *inString, unsigned int length)
}
}
unsigned int ByteQueue::Get(byte &outByte)
unsigned int ByteQueue::Get(uint8_t &outByte)
{
int l = head->Get(outByte);
if (head->UsedUp())
@ -196,7 +196,7 @@ unsigned int ByteQueue::Get(byte &outByte)
return l;
}
unsigned int ByteQueue::Get(byte *outString, unsigned int getMax)
unsigned int ByteQueue::Get(uint8_t *outString, unsigned int getMax)
{
unsigned int getMaxSave=getMax;
ByteQueueNode *current=head;
@ -224,7 +224,7 @@ unsigned int ByteQueue::Get(byte *outString, unsigned int getMax)
return (getMaxSave-getMax);
}
unsigned int ByteQueue::Peek(byte &outByte) const
unsigned int ByteQueue::Peek(uint8_t &outByte) const
{
return head->Peek(outByte);
}
@ -250,7 +250,7 @@ bool ByteQueue::operator==(const ByteQueue &rhs) const
return true;
}
byte ByteQueue::operator[](unsigned long i) const
uint8_t ByteQueue::operator[](unsigned long i) const
{
for (ByteQueueNode *current=head; current; current=current->next)
{

View File

@ -21,21 +21,21 @@ public:
unsigned long MaxRetrieveable()
{return CurrentSize();}
void Put(byte inByte);
void Put(const byte *inString, unsigned int length);
void Put(uint8_t inByte);
void Put(const uint8_t *inString, unsigned int length);
// both functions returns the number of bytes actually retrived
unsigned int Get(byte &outByte);
unsigned int Get(byte *outString, unsigned int getMax);
unsigned int Get(uint8_t &outByte);
unsigned int Get(uint8_t *outString, unsigned int getMax);
unsigned int Peek(byte &outByte) const;
unsigned int Peek(uint8_t &outByte) const;
void CopyTo(BufferedTransformation &target) const;
void CopyTo(byte *target) const;
void CopyTo(uint8_t *target) const;
ByteQueue & operator=(const ByteQueue &rhs);
bool operator==(const ByteQueue &rhs) const;
byte operator[](unsigned long i) const;
uint8_t operator[](unsigned long i) const;
private:
void CopyFrom(const ByteQueue &copy);

View File

@ -32,7 +32,7 @@ const word16 LC_RNG::a=16807;
const word16 LC_RNG::r=2836;
#endif
byte LC_RNG::GetByte()
uint8_t LC_RNG::GetByte()
{
word32 hi = seed/q;
word32 lo = seed%q;
@ -49,7 +49,7 @@ byte LC_RNG::GetByte()
// ********************************************************
X917RNG::X917RNG(BlockTransformation *c, const byte *seed)
X917RNG::X917RNG(BlockTransformation *c, const uint8_t *seed)
: cipher(c),
S(cipher->BlockSize()),
dtbuf(S),
@ -58,20 +58,20 @@ X917RNG::X917RNG(BlockTransformation *c, const byte *seed)
randbuf_counter(0)
{
time_t tstamp1 = time(0);
xorbuf(dtbuf, (byte *)&tstamp1, STDMIN((int)sizeof(tstamp1), S));
xorbuf(dtbuf, (uint8_t *)&tstamp1, STDMIN((int)sizeof(tstamp1), S));
cipher->ProcessBlock(dtbuf);
clock_t tstamp2 = clock();
xorbuf(dtbuf, (byte *)&tstamp2, STDMIN((int)sizeof(tstamp2), S));
xorbuf(dtbuf, (uint8_t *)&tstamp2, STDMIN((int)sizeof(tstamp2), S));
cipher->ProcessBlock(dtbuf);
}
byte X917RNG::GetByte()
uint8_t X917RNG::GetByte()
{
if (randbuf_counter==0)
{
// calculate new enciphered timestamp
clock_t tstamp = clock();
xorbuf(dtbuf, (byte *)&tstamp, STDMIN((int)sizeof(tstamp), S));
xorbuf(dtbuf, (uint8_t *)&tstamp, STDMIN((int)sizeof(tstamp), S));
cipher->ProcessBlock(dtbuf);
// combine enciphered timestamp with seed
@ -97,7 +97,7 @@ MaurerRandomnessTest::MaurerRandomnessTest()
tab[i] = 0;
}
inline void MaurerRandomnessTest::Put(byte inByte)
inline void MaurerRandomnessTest::Put(uint8_t inByte)
{
if (n >= Q)
sum += log(double(n - tab[inByte]));
@ -105,7 +105,7 @@ inline void MaurerRandomnessTest::Put(byte inByte)
n++;
}
void MaurerRandomnessTest::Put(const byte *inString, unsigned int length)
void MaurerRandomnessTest::Put(const uint8_t *inString, unsigned int length)
{
while (length--)
Put(*inString++);

View File

@ -13,15 +13,15 @@ class LC_RNG : public RandomNumberGenerator
{
public:
LC_RNG(word32 init_seed)
: seedBytes((byte *)&seed) {seed=init_seed;}
: seedBytes((uint8_t *)&seed) {seed=init_seed;}
byte GetByte();
uint8_t GetByte();
word32 GetSeed() {return seed;}
private:
word32 seed;
byte *const seedBytes;
uint8_t *const seedBytes;
static const word32 m;
static const word32 q;
@ -35,9 +35,9 @@ class X917RNG : public RandomNumberGenerator
{
public:
// cipher will be deleted by destructor
X917RNG(BlockTransformation *cipher, const byte *seed);
X917RNG(BlockTransformation *cipher, const uint8_t *seed);
byte GetByte();
uint8_t GetByte();
private:
member_ptr<BlockTransformation> cipher;
@ -56,8 +56,8 @@ class MaurerRandomnessTest : public Sink
public:
MaurerRandomnessTest();
void Put(byte inByte);
void Put(const byte *inString, unsigned int length);
void Put(uint8_t inByte);
void Put(const uint8_t *inString, unsigned int length);
// BytesNeeded() returns how many more bytes of input is needed by the test
// GetTestValue() should not be called before BytesNeeded()==0

View File

@ -31,7 +31,7 @@ void SHA::HashBlock(const word32 *input)
#endif
}
void SHA::Final(byte *hash)
void SHA::Final(uint8_t *hash)
{
PadLastBlock(56);
CorrectEndianess(data, data, 56);
@ -115,7 +115,7 @@ void SHA::Transform( word32 *digest, const word32 *data )
word32 eData[16];
memcpy( eData, data, DATASIZE );
register word32 A, B, C, D, E;
word32 A, B, C, D, E;
A = digest[0];
B = digest[1];
C = digest[2];

View File

@ -7,7 +7,7 @@ class SHA : public IteratedHash<word32>
{
public:
SHA();
void Final(byte *hash);
void Final(uint8_t *hash);
unsigned int DigestSize() const {return DIGESTSIZE;};
static void CorrectEndianess(word32 *out, const word32 *in, unsigned int byteCount)

View File

@ -63,13 +63,13 @@ void BitOutput::bi_windup()
void BitOutput::bi_putsh(word16 x)
{
outQ.Put((byte)x);
outQ.Put(byte(x>>8));
outQ.Put((uint8_t)x);
outQ.Put(uint8_t(x>>8));
}
/* Copy a stored block to the zip file, storing first the length and its
one's complement if requested. */
void BitOutput::copy_block(byte *buf, unsigned int len, int header)
void BitOutput::copy_block(uint8_t *buf, unsigned int len, int header)
{
/* align on byte boundary */
bi_windup();

View File

@ -11,7 +11,7 @@ public:
void send_bits (unsigned value, int length);
void bi_windup (void);
void bi_putsh (unsigned short);
void copy_block (byte *buf, unsigned len, int header);
void copy_block (uint8_t *buf, unsigned len, int header);
private:
BufferedTransformation &outQ;

View File

@ -142,7 +142,7 @@ const Deflator::config Deflator::configuration_table[10] = {
void Deflator::init_hash()
{
register unsigned j;
unsigned j;
for (ins_h=0, j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(ins_h, window[j]);
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
@ -175,7 +175,7 @@ Deflator::Deflator(int deflate_level, BufferedTransformation *outQ)
prev_length = MIN_MATCH-1;
}
void Deflator::Put(const byte *inString, unsigned int length)
void Deflator::Put(const uint8_t *inString, unsigned int length)
{
if (deflate_level <= 3)
fast_deflate(inString, length);
@ -205,9 +205,9 @@ void Deflator::InputFinished()
int Deflator::longest_match(IPos cur_match)
{
unsigned chain_length = max_chain_length; /* max hash chain length */
register byte *scan = window + strstart; /* current string */
register byte *match; /* matched string */
register int len; /* length of current match */
uint8_t *scan = window + strstart; /* current string */
uint8_t *match; /* matched string */
int len; /* length of current match */
int best_len = prev_length; /* best match length so far */
IPos limit = strstart > (IPos)MAX_DIST ? strstart - (IPos)MAX_DIST : NIL;
/* Stop when cur_match becomes <= limit. To simplify the code,
@ -223,13 +223,13 @@ int Deflator::longest_match(IPos cur_match)
#ifdef UNALIGNED_OK
/* Compare two bytes at a time. Note: this is not always beneficial.
Try with and without -DUNALIGNED_OK to check. */
register byte *strend = window + strstart + MAX_MATCH - 1;
register word16 scan_start = *(word16*)scan;
register word16 scan_end = *(word16*)(scan+best_len-1);
uint8_t *strend = window + strstart + MAX_MATCH - 1;
word16 scan_start = *(word16*)scan;
word16 scan_end = *(word16*)(scan+best_len-1);
#else
register byte *strend = window + strstart + MAX_MATCH;
register byte scan_end1 = scan[best_len-1];
register byte scan_end = scan[best_len];
uint8_t *strend = window + strstart + MAX_MATCH;
uint8_t scan_end1 = scan[best_len-1];
uint8_t scan_end = scan[best_len];
#endif
/* Do not waste too much time if we already have a good match: */
@ -350,9 +350,9 @@ int length;
* IN assertion: lookahead < MIN_LOOKAHEAD.
* Note: call with either lookahead == 0 or length == 0 is valid
*/
unsigned Deflator::fill_window(const byte *buffer, unsigned int length)
unsigned Deflator::fill_window(const uint8_t *buffer, unsigned int length)
{
register unsigned n, m;
unsigned n, m;
unsigned more = length;
/* Amount of free space at the end of the window. */
@ -382,7 +382,7 @@ unsigned Deflator::fill_window(const byte *buffer, unsigned int length)
if ((more += WSIZE) > length) more = length;
}
if (more) {
memcpy((byte*)window+strstart+lookahead, buffer, more);
memcpy((uint8_t*)window+strstart+lookahead, buffer, more);
lookahead += more;
}
return more;
@ -392,13 +392,13 @@ unsigned Deflator::fill_window(const byte *buffer, unsigned int length)
IN assertion: strstart is set to the end of the current match. */
#define FLUSH_BLOCK(eof) flush_block(block_start >= 0L ?\
window+block_start : \
(byte *)0, (long)strstart - block_start, (eof))
(uint8_t *)0, (long)strstart - block_start, (eof))
/* Processes a new input block.
* This function does not perform lazy evaluationof matches and inserts
* new strings in the dictionary only for unmatched strings or for short
* matches. It is used only for the fast compression options. */
int Deflator::fast_deflate(const byte *buffer, unsigned int length)
int Deflator::fast_deflate(const uint8_t *buffer, unsigned int length)
{
IPos hash_head; /* head of the hash chain */
int flush; /* set if current block must be flushed */
@ -486,12 +486,12 @@ int Deflator::fast_deflate(const byte *buffer, unsigned int length)
/* Same as above, but achieves better compression. We use a lazy
* evaluation for matches: a match is finally adopted only if there is
* no better match at the next window position. */
int Deflator::lazy_deflate(const byte *buffer, unsigned int length)
int Deflator::lazy_deflate(const uint8_t *buffer, unsigned int length)
{
IPos hash_head; /* head of hash chain */
IPos prev_match; /* previous match */
int flush; /* set if current block must be flushed */
register unsigned ml = match_length; /* length of best match */
unsigned ml = match_length; /* length of best match */
#ifdef DEBUG
extern word32 isize; /* byte length of input file, for debug only */
#endif

View File

@ -13,9 +13,9 @@ public:
// default for the gzip program is 6
Deflator(int deflate_level, BufferedTransformation *outQ = NULL);
void Put(byte inByte)
void Put(uint8_t inByte)
{Deflator::Put(&inByte, 1);}
void Put(const byte *inString, unsigned int length);
void Put(const uint8_t *inString, unsigned int length);
void InputFinished();
@ -52,13 +52,13 @@ private:
SecByteBlock window;
SecBlock<Pos> prev, head;
unsigned fill_window (const byte*, unsigned);
unsigned fill_window (const uint8_t*, unsigned);
void init_hash ();
int longest_match (IPos cur_match);
int fast_deflate(const byte *buffer, unsigned int length);
int lazy_deflate(const byte *buffer, unsigned int length);
int fast_deflate(const uint8_t *buffer, unsigned int length);
int lazy_deflate(const uint8_t *buffer, unsigned int length);
unsigned ins_h; /* hash index of string to be inserted */
char uptodate; /* hash preparation flag */

View File

@ -74,7 +74,7 @@ Inflator::Inflator(BufferedTransformation *output, BufferedTransformation *bypas
afterEnd = false;
}
void Inflator::Put(const byte *inString, unsigned int length)
void Inflator::Put(const uint8_t *inString, unsigned int length)
{
if (afterEnd)
AccessPort(1).Put(inString, length);
@ -89,7 +89,7 @@ void Inflator::Put(const byte *inString, unsigned int length)
{
flush_output(wp);
if (bk>=8) // undo too much lookahead
AccessPort(1).Put(byte(bb>>(bk-=8)));
AccessPort(1).Put(uint8_t(bb>>(bk-=8)));
inQueue.TransferTo(AccessPort(1));
}
@ -104,7 +104,7 @@ void Inflator::InputFinished()
flush_output(wp);
if (bk>=8) // undo too much lookahead
AccessPort(1).Put(byte(bb>>(bk-=8)));
AccessPort(1).Put(uint8_t(bb>>(bk-=8)));
inQueue.TransferTo(AccessPort(1));
}
@ -183,9 +183,9 @@ const word16 Inflator::mask_bits[] = {
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
byte Inflator::NEXTBYTE()
uint8_t Inflator::NEXTBYTE()
{
byte b;
uint8_t b;
if (!inQueue.Get(b))
#ifdef THROW_EXCEPTIONS
throw UnexpectedEndErr();
@ -252,16 +252,16 @@ int Inflator::huft_build(unsigned *b, unsigned n, unsigned s, const word16 *d, c
unsigned f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register unsigned i; /* counter, current code */
register unsigned j; /* counter */
register int k; /* number of bits in current code */
unsigned i; /* counter, current code */
unsigned j; /* counter */
int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
register unsigned *p; /* pointer into c[], b[], or v[] */
register huft *q; /* points to current table */
unsigned *p; /* pointer into c[], b[], or v[] */
huft *q; /* points to current table */
huft r; /* table entry for structure assignment */
huft *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
register int w; /* bits before this table == (l * h) */
int w; /* bits before this table == (l * h) */
unsigned x[BMAX+1]; /* bit offsets, then code stack */
unsigned *xp; /* pointer into x */
int y; /* number of dummy codes added */
@ -380,8 +380,8 @@ int Inflator::huft_build(unsigned *b, unsigned n, unsigned s, const word16 *d, c
if (h)
{
x[h] = i; /* save pattern for backing up */
r.b = (byte)l; /* bits to dump before this table */
r.e = (byte)(16 + j); /* bits in this table */
r.b = (uint8_t)l; /* bits to dump before this table */
r.e = (uint8_t)(16 + j); /* bits in this table */
r.v.t = q; /* pointer to this table */
j = i >> (w - l); /* (get around Turbo C bug) */
u[h-1][j] = r; /* connect to last table */
@ -389,18 +389,18 @@ int Inflator::huft_build(unsigned *b, unsigned n, unsigned s, const word16 *d, c
}
/* set up table entry in r */
r.b = (byte)(k - w);
r.b = (uint8_t)(k - w);
if (p >= v + n)
r.e = 99; /* out of values--invalid code */
else if (*p < s)
{
r.e = (byte)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
r.e = (uint8_t)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
r.v.n = (word16)(*p); /* simple code is just the value */
p++; /* one compiler does not like *p++ */
}
else
{
r.e = (byte)e[*p - s]; /* non-simple--look up in lists */
r.e = (uint8_t)e[*p - s]; /* non-simple--look up in lists */
r.v.n = d[*p++ - s];
}
@ -435,7 +435,7 @@ int Inflator::huft_free(huft *t)
list of the tables it made, with the links in a dummy first entry of
each table. */
{
register huft *p, *q;
huft *p, *q;
/* Go through linked list, freeing from the malloced (t[-1]) address. */
@ -454,13 +454,13 @@ int Inflator::inflate_codes(huft *tl, huft *td, int bl, int bd)
/* inflate (decompress) the codes in a deflated (compressed) block.
Return an error code or zero if it all goes ok. */
{
register unsigned e; /* table entry flag/number of extra bits */
unsigned e; /* table entry flag/number of extra bits */
unsigned n, d; /* length and index for copy */
unsigned w; /* current window position */
huft *t; /* pointer to table entry */
unsigned ml, md; /* masks for bl and bd bits */
register word32 b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
word32 b; /* bit buffer */
unsigned k; /* number of bits in bit buffer */
/* make local copies of globals */
@ -485,7 +485,7 @@ int Inflator::inflate_codes(huft *tl, huft *td, int bl, int bd)
DUMPBITS(t->b)
if (e == 16) /* then it's a literal */
{
slide[w++] = (byte)t->v.n;
slide[w++] = (uint8_t)t->v.n;
Tracevv((stderr, "%c", slide[w-1]));
if (w == WSIZE)
{
@ -562,8 +562,8 @@ int Inflator::inflate_stored()
{
unsigned n; /* number of bytes in block */
unsigned w; /* current window position */
register word32 b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
word32 b; /* bit buffer */
unsigned k; /* number of bits in bit buffer */
/* make local copies of globals */
@ -591,7 +591,7 @@ int Inflator::inflate_stored()
while (n--)
{
NEEDBITS(8)
slide[w++] = (byte)b;
slide[w++] = (uint8_t)b;
if (w == WSIZE)
{
flush_output(w);
@ -681,8 +681,8 @@ int Inflator::inflate_dynamic()
#else
unsigned ll[286+30]; /* literal/length and distance code lengths */
#endif
register word32 b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
word32 b; /* bit buffer */
unsigned k; /* number of bits in bit buffer */
/* make local bit buffer */
@ -829,8 +829,8 @@ int Inflator::inflate_block(bool &e)
/* decompress an inflated block */
{
unsigned t; /* block type */
register word32 b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
word32 b; /* bit buffer */
unsigned k; /* number of bits in bit buffer */
/* make local bit buffer */

View File

@ -14,16 +14,16 @@ public:
Inflator(BufferedTransformation *output = NULL,
BufferedTransformation *bypassed = NULL);
void Put(byte b)
void Put(uint8_t b)
{Inflator::Put(&b, 1);}
void Put(const byte *inString, unsigned int length);
void Put(const uint8_t *inString, unsigned int length);
void InputFinished();
private:
struct huft {
byte e; /* number of extra bits or operation */
byte b; /* number of bits in this code or subcode */
uint8_t e; /* number of extra bits or operation */
uint8_t b; /* number of bits in this code or subcode */
union {
word16 n; /* literal, length base, or distance base */
struct huft *t; /* pointer to next level of table */
@ -49,7 +49,7 @@ private:
static const word16 mask_bits[18];
ByteQueue inQueue;
byte NEXTBYTE();
uint8_t NEXTBYTE();
SecByteBlock slide;
unsigned int wp;

View File

@ -75,7 +75,7 @@ const int CodeTree::extra_dbits[] /* extra bits for each distance code */
const int CodeTree::extra_blbits[]/* extra bits for each bit length code */
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
const byte CodeTree::bl_order[]
const uint8_t CodeTree::bl_order[]
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
/* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes.
@ -97,7 +97,7 @@ const byte CodeTree::bl_order[]
static unsigned reverse(unsigned int code, int len)
/* Reverse the first len bits of a code. */
{
register unsigned res = 0;
unsigned res = 0;
do res = (res << 1) | (code & 1), code>>=1; while (--len);
return res;
}
@ -126,7 +126,7 @@ CodeTree::CodeTree(int deflate_level, BufferedTransformation &outQ)
unsigned int n; /* iterates over tree elements */
unsigned int bits; /* bit counter */
unsigned int length; /* length value */
register unsigned int code; /* code value */
unsigned int code; /* code value */
unsigned int dist; /* distance index */
compressed_len = input_len = 0L;
@ -136,21 +136,21 @@ CodeTree::CodeTree(int deflate_level, BufferedTransformation &outQ)
for (code=0; code < LENGTH_CODES-1; code++) {
base_length[code] = length;
for (n=0; n < (1U<<extra_lbits[code]); n++) {
length_code[length++] = (byte)code;
length_code[length++] = (uint8_t)code;
}
}
assert (length == 256);
/* Note that the length 255 (match length 258) can be represented
in two different ways: code 284 + 5 bits or code 285, so we
overwrite length_code[255] to use the best encoding: */
length_code[length-1] = (byte)code;
length_code[length-1] = (uint8_t)code;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0;
for (code=0 ; code < 16; code++) {
base_dist[code] = dist;
for (n=0; n < (1U<<extra_dbits[code]); n++) {
dist_code[dist++] = (byte)code;
dist_code[dist++] = (uint8_t)code;
}
}
assert (dist == 256);
@ -158,7 +158,7 @@ CodeTree::CodeTree(int deflate_level, BufferedTransformation &outQ)
for (; code < D_CODES; code++) {
base_dist[code] = dist << 7;
for (n=0; n < (1U<<(extra_dbits[code]-7)); n++) {
dist_code[256 + dist++] = (byte)code;
dist_code[256 + dist++] = (uint8_t)code;
}
}
assert (dist == 256);
@ -191,7 +191,7 @@ CodeTree::CodeTree(int deflate_level, BufferedTransformation &outQ)
/* Initialize a new block. */
void CodeTree::init_block()
{
register unsigned int n; /* iterates over tree elements */
unsigned int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n=0; n < L_CODES; n++) dyn_ltree[n].Freq = 0;
@ -444,7 +444,7 @@ void CodeTree::build_tree(tree_desc *desc)
/* Create a new node father of n and m */
tree[node].Freq = tree[n].Freq + tree[m].Freq;
depth[(unsigned int)node] = (byte) (MAX(depth[(unsigned int)n], depth[(unsigned int)m]) + 1);
depth[(unsigned int)node] = (uint8_t) (MAX(depth[(unsigned int)n], depth[(unsigned int)m]) + 1);
tree[n].Dad = tree[m].Dad = node;
#ifdef DUMP_BL_TREE
if (tree == bl_tree) {
@ -627,7 +627,7 @@ void CodeTree::send_all_trees(int lcodes, int dcodes, int blcodes)
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
*/
word32 CodeTree::flush_block(byte *buf, word32 stored_len, int eof)
word32 CodeTree::flush_block(uint8_t *buf, word32 stored_len, int eof)
{
word32 opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex; /* index of last bit length code of non zero freq */
@ -712,7 +712,7 @@ word32 CodeTree::flush_block(byte *buf, word32 stored_len, int eof)
Return true if the current block must be flushed. */
int CodeTree::ct_tally (int dist, int lc)
{
l_buf[last_lit++] = (byte)lc;
l_buf[last_lit++] = (uint8_t)lc;
if (dist == 0) {
/* lc is the unmatched char */
dyn_ltree[(unsigned int)lc].Freq++;
@ -765,7 +765,7 @@ void CodeTree::compress_block(ct_data *ltree, ct_data *dtree)
unsigned lx = 0; /* running index in l_buf */
unsigned dx = 0; /* running index in d_buf */
unsigned fx = 0; /* running index in flag_buf */
byte flag = 0; /* current flags */
uint8_t flag = 0; /* current flags */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */

View File

@ -10,7 +10,7 @@ public:
CodeTree(int deflate_level, BufferedTransformation &outQ);
int ct_tally (int dist, int lc);
word32 flush_block (byte *buf, word32 stored_len, int eof);
word32 flush_block (uint8_t *buf, word32 stored_len, int eof);
long block_start; /* window offset of current block */
unsigned int strstart; /* window offset of current string */
@ -73,7 +73,7 @@ private:
static const int extra_lbits[LENGTH_CODES];
static const int extra_dbits[D_CODES];
static const int extra_blbits[BL_CODES];
static const byte bl_order[BL_CODES];
static const uint8_t bl_order[BL_CODES];
public:
// Data structure describing a single value and its code string. */
@ -168,8 +168,8 @@ private:
unsigned last_lit; /* running index in l_buf */
unsigned last_dist; /* running index in d_buf */
unsigned last_flags; /* running index in flag_buf */
byte flags; /* current flags not yet saved in flag_buf */
byte flag_bit; /* current bit used in flags */
uint8_t flags; /* current flags not yet saved in flag_buf */
uint8_t flag_bit; /* current bit used in flags */
/* bits are filled in flags starting at bit 0 (least significant).
* Note: these flags are overkill in the current code since we don't
* take advantage of DIST_BUFSIZE == LIT_BUFSIZE.

View File

@ -107,10 +107,10 @@ void cArchiveSigGen::AddSig(iSignature* pSig)
void cArchiveSigGen::CalculateSignatures(cArchive& a)
{
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE * 2];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE * 2];
int cbRead;
container_type::size_type i;
byte* pBuf = abBuf;
uint8_t* pBuf = abBuf;
if (s_direct)
{
@ -154,13 +154,13 @@ void cArchiveSigGen::SetHex(bool hex)
// number of bits in the array
// ptr-to-str for return string val
///////////////////////////////////////////////////////////////////////////////
char* btob64(const register byte* pcbitvec, register char* pcout, int numbits)
char* btob64(const uint8_t* pcbitvec, char* pcout, int numbits)
{
register unsigned int val;
register int offset;
unsigned int val;
int offset;
uint8* pcorig = (uint8*)pcout;
ASSERT(sizeof(uint8) == sizeof(byte)); /* everything breaks otherwise */
ASSERT(sizeof(uint8) == sizeof(uint8_t)); /* everything breaks otherwise */
assert(numbits > 0);
val = *pcbitvec;
@ -200,8 +200,8 @@ char* btob64(const register byte* pcbitvec, register char* pcout, int numbits)
#define NUMTMPLONGS 1000
char* pltob64(uint32* pl, char* pcout, int numlongs)
{
register int i;
register uint32* plto;
int i;
uint32* plto;
uint32 larray[NUMTMPLONGS];
assert(numlongs < NUMTMPLONGS);
@ -214,7 +214,7 @@ char* pltob64(uint32* pl, char* pcout, int numlongs)
++plto;
}
return btob64((byte*)larray, (char*)pcout, numlongs * sizeof(uint32) * 8);
return btob64((uint8_t*)larray, (char*)pcout, numlongs * sizeof(uint32) * 8);
}
///////////////////////////////////////////////////////////////////////////////
@ -235,7 +235,7 @@ void cNullSignature::Init()
{
}
void cNullSignature::Update(const byte* const pbData, int cbDataLen)
void cNullSignature::Update(const uint8_t* const pbData, int cbDataLen)
{
}
@ -310,9 +310,9 @@ void cChecksumSignature::Init()
{
}
void cChecksumSignature::Update(const byte* const pbDataC, int cbDataLen)
void cChecksumSignature::Update(const uint8_t* const pbDataC, int cbDataLen)
{
byte* pbData = (byte*)pbDataC;
uint8_t* pbData = (uint8_t*)pbDataC;
for (int i = 0; i < cbDataLen; i++, pbData++)
mChecksum += *pbData;
}
@ -398,9 +398,9 @@ void cCRC32Signature::Init()
crcInit(mCRCInfo);
}
void cCRC32Signature::Update(const byte* const pbData, int cbDataLen)
void cCRC32Signature::Update(const uint8_t* const pbData, int cbDataLen)
{
ASSERT(sizeof(byte) == sizeof(uint8));
ASSERT(sizeof(uint8_t) == sizeof(uint8));
crcUpdate(mCRCInfo, (uint8*)pbData, cbDataLen);
}
@ -501,7 +501,7 @@ void cMD5Signature::Init()
#endif
}
void cMD5Signature::Update(const byte* const pbData, int cbDataLen)
void cMD5Signature::Update(const uint8_t* const pbData, int cbDataLen)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
CC_MD5_Update(&mMD5Info, (uint8*)pbData, cbDataLen);
@ -534,8 +534,8 @@ TSTRING cMD5Signature::AsString() const
TSTRING ret;
char buf[24];
ASSERT(sizeof(uint8) == sizeof(byte)); /* everything breaks otherwise */
btob64((byte*)md5_digest, buf, SIG_BYTE_SIZE * 8);
ASSERT(sizeof(uint8) == sizeof(uint8_t)); /* everything breaks otherwise */
btob64((uint8_t*)md5_digest, buf, SIG_BYTE_SIZE * 8);
//converting to base64 representation.
ret.append(buf);
@ -626,9 +626,9 @@ void cSHASignature::Init()
#endif
}
void cSHASignature::Update(const byte* const pbData, int cbDataLen)
void cSHASignature::Update(const uint8_t* const pbData, int cbDataLen)
{
ASSERT(sizeof(byte) == sizeof(uint8));
ASSERT(sizeof(uint8_t) == sizeof(uint8));
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
CC_SHA1_Update(&mSHAInfo, (uint8*)pbData, cbDataLen);
#elif HAVE_OPENSSL_SHA_H
@ -822,7 +822,7 @@ void cHAVALSignature::Init()
haval_start(&mHavalState);
}
void cHAVALSignature::Update(const byte* const pbData, int cbDataLen)
void cHAVALSignature::Update(const uint8_t* const pbData, int cbDataLen)
{
haval_hash(&mHavalState, (uint8*)pbData, cbDataLen);
}
@ -842,7 +842,7 @@ TSTRING cHAVALSignature::AsString() const
TSTRING ret;
char buf[24];
btob64((byte*)mSignature, buf, 128);
btob64((uint8_t*)mSignature, buf, 128);
//converting to base64 representation.
ret.append(buf);

View File

@ -108,7 +108,7 @@ public:
//
virtual void Init() = 0;
// call before beginning hashing
virtual void Update(const byte* const pbData, int cbDataLen) = 0;
virtual void Update(const uint8_t* const pbData, int cbDataLen) = 0;
// may be called multiple times -- best to call with blocks of size SUGGESTED_BLOCK_SIZE,
// but can handle any size data.
virtual void Finit() = 0;
@ -192,7 +192,7 @@ public:
virtual ~cNullSignature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
virtual TSTRING AsStringHex() const;
@ -219,7 +219,7 @@ public:
virtual ~cChecksumSignature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
virtual TSTRING AsStringHex() const;
@ -247,7 +247,7 @@ public:
virtual ~cCRC32Signature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
@ -276,7 +276,7 @@ public:
virtual ~cMD5Signature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
virtual TSTRING AsStringHex() const;
@ -313,7 +313,7 @@ public:
virtual ~cSHASignature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
virtual TSTRING AsStringHex() const;
@ -355,7 +355,7 @@ public:
virtual ~cHAVALSignature();
virtual void Init();
virtual void Update(const byte* const pbData, int cbDataLen);
virtual void Update(const uint8_t* const pbData, int cbDataLen);
virtual void Finit();
virtual TSTRING AsString() const;
virtual TSTRING AsStringHex() const;

View File

@ -177,7 +177,13 @@ void cFSParserUtil::AddSubTypeProps(cFCOPropVector& v) const
static inline void trim_leading_whitespace(std::string& str)
{
// C++17 removes std::ptr_fun and deprecates std::not1,
// so just use a lambda where available
#if __cplusplus < 201103L
str.erase(str.begin(), std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
#else
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](int c) {return !std::isspace(c);} ));
#endif
}
void cFSParserUtil::InterpretFCOName(const std::list<TSTRING>& l, cFCOName& nameOut) const

View File

@ -67,11 +67,13 @@ void tw_terminate_handler()
_exit(1);
}
#if __cplusplus < 201703L
void tw_unexpected_handler()
{
fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr);
_exit(1);
}
#endif
static void SiggenInit()
{
@ -112,8 +114,9 @@ int __cdecl _tmain(int argc, const TCHAR** argv)
// Note: we do this before Init() in case it attempts to call these handlers
// TODO: move this into the Init() routine
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
#if __cplusplus < 201703L
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
#endif
//cTWInit twInit( argv[0] );
SiggenInit();

View File

@ -526,7 +526,7 @@ std::string& cMailMessageUtil::LFToCRLF(std::string& sIn)
/*
static
std::string
util_Base64Encode( const byte b[3], int size )
util_Base64Encode( const uint8_t b[3], int size )
{
// TODO:BAM -- what about endianness?
ASSERT( size > 0 && size <= 3 );
@ -542,18 +542,18 @@ util_Base64Encode( const byte b[3], int size )
if( size >= 2 )
{
// encode B,C
s += v64[ ( ( b[0] & (byte)0x3 ) << 4 ) | ( b[1] >> 4 ) ];
s += v64[ ( ( b[0] & (uint8_t)0x3 ) << 4 ) | ( b[1] >> 4 ) ];
if( size == 3 )
s += v64[ ( ( b[1] & (byte)0xF ) << 2 ) | ( b[2] >> 6 ) ];
s += v64[ ( ( b[1] & (uint8_t)0xF ) << 2 ) | ( b[2] >> 6 ) ];
else
s += v64[ ( ( b[1] & (byte)0xF ) << 2 ) ];
s += v64[ ( ( b[1] & (uint8_t)0xF ) << 2 ) ];
}
if( size >= 3 )
{
// encode D
s += v64[ b[2] & (byte)0x3F ];
s += v64[ b[2] & (uint8_t)0x3F ];
}
// padding
@ -580,7 +580,7 @@ const T& MS_SUCKS_min( const T& a, const T& b )
const std::string::value_type*
cMailMessageUtil::ConvertBase64(
std::string& sEncode,
const byte* pchSrc,
const uint8_t* pchSrc,
size_t nchSrc )
{
sEncode.assign( ToBase64( pchSrc, nchSrc ) );
@ -589,9 +589,9 @@ cMailMessageUtil::ConvertBase64(
std::string
cMailMessageUtil::ToBase64( const byte* p, size_t size )
cMailMessageUtil::ToBase64( const uint8_t* p, size_t size )
{
ASSERT( sizeof( uint8 ) == sizeof( byte ) ); // everything breaks otherwise
ASSERT( sizeof( uint8 ) == sizeof( uint8_t ) ); // everything breaks otherwise
std::string s;
const int MAX_WORKING_BYTES = 3;
@ -599,8 +599,8 @@ cMailMessageUtil::ToBase64( const byte* p, size_t size )
const int MAX_CHARS_PER_BYTE = 2; // should be
ASSERT( MAX_CHARS_PER_BYTE > CHARS_PER_WORKING_BYTES/MAX_WORKING_BYTES );
const int NERVOUS_LINE_BUFFER = 10;
const byte* at = p;
byte buf[ MAX_WORKING_BYTES ];
const uint8_t* at = p;
uint8_t buf[ MAX_WORKING_BYTES ];
int nbLeft;
int nbWorking;
int nchCurLine;
@ -653,19 +653,18 @@ cMailMessageUtil::ToBase64( const byte* p, size_t size )
namespace /*Unique*/
{
typedef byte byte_t;
# ifdef TSS_MAKE_EOL_CRLF
const byte _aszEoL[] = "\r\n";
const uint8_t _aszEoL[] = "\r\n";
size_t _EOL_LEN = 2;
# else
const byte _aszEoL[] = "\n";
const uint8_t _aszEoL[] = "\n";
size_t _EOL_LEN = 1;
# endif
const byte_t _abBase64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const uint8_t _abBase64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
@ -697,7 +696,7 @@ inline size_t tss_encode_base64_size(size_t nchSource)
return nchOut + nchEol + 2;
}
void tss_encode_digit_base64(const byte_t*& pchSrc, size_t& nchSrcLeft, byte_t*& pchBuf, size_t& nchBufLeft)
void tss_encode_digit_base64(const uint8_t*& pchSrc, size_t& nchSrcLeft, uint8_t*& pchBuf, size_t& nchBufLeft)
{
// NOTE:RAD -- Redundant and ugly but very fast!!
@ -756,7 +755,7 @@ void tss_encode_digit_base64(const byte_t*& pchSrc, size_t& nchSrcLeft, byte_t*&
};
size_t tss_encode_base64(const byte_t* pchSource, size_t nchSource, byte_t* pchBuffer, size_t nchBuffer)
size_t tss_encode_base64(const uint8_t* pchSource, size_t nchSource, uint8_t* pchBuffer, size_t nchBuffer)
{
const size_t _ERROR = std::string::npos; // -1;
@ -780,8 +779,8 @@ size_t tss_encode_base64(const byte_t* pchSource, size_t nchSource, byte_t* pchB
//--Get three characters at a time and encode them (watching linelen)
byte_t* pchBuf = (pchBuffer + 0);
const byte_t* pchSrc = (pchSource + 0);
uint8_t* pchBuf = (pchBuffer + 0);
const uint8_t* pchSrc = (pchSource + 0);
const size_t _max_linelen = (_MAX_RFC822_LINE_LEN - _EOL_LEN);
@ -798,7 +797,7 @@ size_t tss_encode_base64(const byte_t* pchSource, size_t nchSource, byte_t* pchB
{
nLineLen = 0; // RESET:
const byte_t* pchEol = &_aszEoL[0];
const uint8_t* pchEol = &_aszEoL[0];
while (*pchEol)
*pchBuf++ = *pchEol++;
}
@ -812,7 +811,7 @@ size_t tss_encode_base64(const byte_t* pchSource, size_t nchSource, byte_t* pchB
const std::string::value_type*
cMailMessageUtil::ConvertBase64(std::string& sEncode, const byte_t* pchSrc, size_t nchSrc)
cMailMessageUtil::ConvertBase64(std::string& sEncode, const uint8_t* pchSrc, size_t nchSrc)
{
size_t nch = tss_encode_base64(pchSrc, nchSrc, 0, 0); // Like mbstowcs
@ -822,7 +821,7 @@ cMailMessageUtil::ConvertBase64(std::string& sEncode, const byte_t* pchSrc, size
const char* pch = sEncode.c_str(); // Get Pointer (won't change)
size_t nLength = // Action
tss_encode_base64(pchSrc, nchSrc, (byte_t*)pch, nch);
tss_encode_base64(pchSrc, nchSrc, (uint8_t*)pch, nch);
if (nLength == std::string::npos)
throw std::bad_alloc();
@ -833,7 +832,7 @@ cMailMessageUtil::ConvertBase64(std::string& sEncode, const byte_t* pchSrc, size
}
std::string cMailMessageUtil::ToBase64(const byte_t* pchSrc, size_t nchSrc)
std::string cMailMessageUtil::ToBase64(const uint8_t* pchSrc, size_t nchSrc)
{
// NOTE: It sucks to use std::string this way! Should be
// passed in by reference.

View File

@ -128,7 +128,7 @@ public:
_EOL_LEN = 2
};
static const std::string::value_type* ConvertBase64(std::string&, const byte*, size_t);
static const std::string::value_type* ConvertBase64(std::string&, const uint8_t*, size_t);
static bool HasNonAsciiChars(const std::string& s);
static std::string CreateEncodedText(const std::string& text);

View File

@ -95,11 +95,13 @@ void tw_terminate_handler()
_exit(8);
}
#if __cplusplus < 201703L
void tw_unexpected_handler()
{
fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr);
_exit(8);
}
#endif
///////////////////////////////////////////////////////////////////////////////
// main
@ -121,8 +123,9 @@ int __cdecl _tmain(int argc, const TCHAR* argv[], const TCHAR* envp[])
// Note: we do this before Init() in case it attempts to call these handlers
// TODO: move this into the Init() routine
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
#if __cplusplus < 201703L
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
#endif
// Initialization
//
twInit.Init(argv[0]);

View File

@ -661,7 +661,7 @@ void cTWUtil::ReadConfigText(const TCHAR* filename, TSTRING& configText, cArchiv
throw eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE);
// check 8 byte header
if (nstring.mString.compare(0, 8 * sizeof(byte), CONFIG_FILE_MAGIC_8BYTE) != 0)
if (nstring.mString.compare(0, 8 * sizeof(uint8_t), CONFIG_FILE_MAGIC_8BYTE) != 0)
ThrowAndAssert(eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE));
// remove 8 byte header
@ -716,7 +716,7 @@ void cTWUtil::ReadPolicyText(const TCHAR* filename, std::string& polText, const
ReadObject(filename, NULL, nstring, cPolicyFile::GetFileHeaderID(), pPublicKey, bEncrypted);
// check 8 byte header
if (nstring.mString.compare(0, 8 * sizeof(byte), POLICY_FILE_MAGIC_8BYTE) != 0)
if (nstring.mString.compare(0, 8 * sizeof(uint8_t), POLICY_FILE_MAGIC_8BYTE) != 0)
ThrowAndAssert(eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE));
// remove 8 byte header

View File

@ -61,11 +61,13 @@ void tw_terminate_handler()
_exit(1);
}
#if __cplusplus < 201703L
void tw_unexpected_handler()
{
fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr);
_exit(1);
}
#endif
int __cdecl _tmain(int argc, const TCHAR* argv[], const TCHAR* envp[])
{
@ -84,8 +86,9 @@ int __cdecl _tmain(int argc, const TCHAR* argv[], const TCHAR* envp[])
// Note: we do this before Init() in case it attempts to call these handlers
// TODO: move this into the Init() routine
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
#if __cplusplus < 201703L
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
#endif
twInit.Init(argv[0]);
TSS_Dependency(cTWAdmin);

View File

@ -57,24 +57,24 @@ public:
return (head == MaxSize());
}
unsigned int Put(byte inByte);
unsigned int Put(const byte* inString, unsigned int length);
unsigned int Put(uint8_t inByte);
unsigned int Put(const uint8_t* inString, unsigned int length);
unsigned int Get(byte& outByte);
unsigned int Get(byte* outString, unsigned int getMax);
unsigned int Get(uint8_t& outByte);
unsigned int Get(uint8_t* outString, unsigned int getMax);
unsigned int Peek(byte& outByte) const;
unsigned int Peek(uint8_t& outByte) const;
void CopyTo(BufferedTransformation& target) const
{
target.Put(buf + head, tail - head);
}
void CopyTo(byte* target) const
void CopyTo(uint8_t* target) const
{
memcpy(target, buf + head, tail - head);
}
byte operator[](unsigned int i) const
uint8_t operator[](unsigned int i) const
{
return buf[i - head];
}
@ -98,7 +98,7 @@ cByteQueueNode::cByteQueueNode(unsigned int maxSize) : buf(maxSize)
next = 0;
}
unsigned int cByteQueueNode::Put(byte inByte)
unsigned int cByteQueueNode::Put(uint8_t inByte)
{
if (MaxSize() == tail)
return 0;
@ -107,7 +107,7 @@ unsigned int cByteQueueNode::Put(byte inByte)
return 1;
}
unsigned int cByteQueueNode::Put(const byte* inString, unsigned int length)
unsigned int cByteQueueNode::Put(const uint8_t* inString, unsigned int length)
{
unsigned int l = STDMIN(length, MaxSize() - tail);
memcpy(buf + tail, inString, l);
@ -115,7 +115,7 @@ unsigned int cByteQueueNode::Put(const byte* inString, unsigned int length)
return l;
}
unsigned int cByteQueueNode::Get(byte& outByte)
unsigned int cByteQueueNode::Get(uint8_t& outByte)
{
if (tail == head)
return 0;
@ -124,7 +124,7 @@ unsigned int cByteQueueNode::Get(byte& outByte)
return 1;
}
unsigned int cByteQueueNode::Get(byte* outString, unsigned int getMax)
unsigned int cByteQueueNode::Get(uint8_t* outString, unsigned int getMax)
{
unsigned int l = STDMIN(getMax, tail - head);
memcpy(outString, buf + head, l);
@ -132,7 +132,7 @@ unsigned int cByteQueueNode::Get(byte* outString, unsigned int getMax)
return l;
}
unsigned int cByteQueueNode::Peek(byte& outByte) const
unsigned int cByteQueueNode::Peek(uint8_t& outByte) const
{
if (tail == head)
return 0;
@ -198,7 +198,7 @@ void cByteQueue::CopyTo(BufferedTransformation& target) const
current->CopyTo(target);
}
void cByteQueue::CopyTo(byte* target) const
void cByteQueue::CopyTo(uint8_t* target) const
{
for (cByteQueueNode* current = head; current; current = current->next)
{
@ -220,7 +220,7 @@ unsigned long cByteQueue::CurrentSize() const
*/
}
void cByteQueue::Put(byte inByte)
void cByteQueue::Put(uint8_t inByte)
{
if (!tail->Put(inByte))
{
@ -232,7 +232,7 @@ void cByteQueue::Put(byte inByte)
mCurrentSize++;
}
void cByteQueue::Put(const byte* inString, unsigned int length)
void cByteQueue::Put(const uint8_t* inString, unsigned int length)
{
unsigned int l;
@ -248,7 +248,7 @@ void cByteQueue::Put(const byte* inString, unsigned int length)
}
}
unsigned int cByteQueue::Get(byte& outByte)
unsigned int cByteQueue::Get(uint8_t& outByte)
{
int l = head->Get(outByte);
if (head->UsedUp())
@ -265,7 +265,7 @@ unsigned int cByteQueue::Get(byte& outByte)
return l;
}
unsigned int cByteQueue::Get(byte* outString, unsigned int getMax)
unsigned int cByteQueue::Get(uint8_t* outString, unsigned int getMax)
{
unsigned int getMaxSave = getMax;
cByteQueueNode* current = head;
@ -300,7 +300,7 @@ unsigned int cByteQueue::Get(byte* outString, unsigned int getMax)
return (rtn);
}
unsigned int cByteQueue::Peek(byte& outByte) const
unsigned int cByteQueue::Peek(uint8_t& outByte) const
{
return head->Peek(outByte);
}
@ -326,7 +326,7 @@ bool cByteQueue::operator==(const cByteQueue& rhs) const
return true;
}
byte cByteQueue::operator[](unsigned long i) const
uint8_t cByteQueue::operator[](unsigned long i) const
{
for (cByteQueueNode* current = head; current; current = current->next)
{

View File

@ -56,21 +56,21 @@ public:
return CurrentSize();
}
void Put(byte inByte);
void Put(const byte* inString, unsigned int length);
void Put(uint8_t inByte);
void Put(const uint8_t* inString, unsigned int length);
// both functions returns the number of bytes actually retrived
unsigned int Get(byte& outByte);
unsigned int Get(byte* outString, unsigned int getMax);
unsigned int Get(uint8_t& outByte);
unsigned int Get(uint8_t* outString, unsigned int getMax);
unsigned int Peek(byte& outByte) const;
unsigned int Peek(uint8_t& outByte) const;
void CopyTo(BufferedTransformation& target) const;
void CopyTo(byte* target) const;
void CopyTo(uint8_t* target) const;
cByteQueue& operator=(const cByteQueue& rhs);
bool operator==(const cByteQueue& rhs) const;
byte operator[](unsigned long i) const;
uint8_t operator[](unsigned long i) const;
private:
void CopyFrom(const cByteQueue& copy);

View File

@ -135,7 +135,7 @@ void cIDEA::SetKey(iCipher::EncryptionDir dir, const cHashedKey128& key)
ASSERT(mpData);
delete mpData->mpIDEA;
mpData->mpIDEA = new IDEA((byte*)key.GetKey(), dir == iCipher::ENCRYPT ? ENCRYPTION : DECRYPTION);
mpData->mpIDEA = new IDEA((uint8_t*)key.GetKey(), dir == iCipher::ENCRYPT ? ENCRYPTION : DECRYPTION);
}
// return the size of data block this crypter works on
@ -159,7 +159,7 @@ void cIDEA::ProcessBlock(const void* indata, void* outdata)
ThrowAndAssert(eInternal(_T("Key not set in symmetric encryption.")));
}
mpData->mpIDEA->ProcessBlock((byte*)indata, (byte*)outdata);
mpData->mpIDEA->ProcessBlock((uint8_t*)indata, (uint8_t*)outdata);
}
#endif // _IDEA_ENCRYPTION
@ -203,14 +203,14 @@ void cTripleDES::SetKey(iCipher::EncryptionDir dir, const cHashedKey192& key)
delete mpData->mpEncryptor;
delete mpData->mpDecryptor;
mpData->mpDecryptor = 0;
mpData->mpEncryptor = new TripleDES_Encryption((byte*)key.GetKey());
mpData->mpEncryptor = new TripleDES_Encryption((uint8_t*)key.GetKey());
}
else
{
delete mpData->mpEncryptor;
delete mpData->mpDecryptor;
mpData->mpEncryptor = 0;
mpData->mpDecryptor = new TripleDES_Decryption((byte*)key.GetKey());
mpData->mpDecryptor = new TripleDES_Decryption((uint8_t*)key.GetKey());
}
}
@ -240,9 +240,9 @@ void cTripleDES::ProcessBlock(const void* indata, void* outdata)
}
if (mpData->mpEncryptor)
mpData->mpEncryptor->ProcessBlock((byte*)indata, (byte*)outdata);
mpData->mpEncryptor->ProcessBlock((uint8_t*)indata, (uint8_t*)outdata);
else
mpData->mpDecryptor->ProcessBlock((byte*)indata, (byte*)outdata);
mpData->mpDecryptor->ProcessBlock((uint8_t*)indata, (uint8_t*)outdata);
}
///////////////////////////////////////////////////////////////////////////////
@ -274,7 +274,7 @@ cRSAPrivateKey::cRSAPrivateKey(void* pDataStream)
int32 i32;
int16 i16;
byte* pIn = (byte*)pDataStream;
uint8_t* pIn = (uint8_t*)pDataStream;
memcpy(&i16, pIn, sizeof(i16));
mpData->mKeyLength = tw_ntohs(i16);
@ -343,7 +343,7 @@ void cRSAPrivateKey::Write(void* pDataStream) const
ASSERT(mpData->mpKey->GetTrapdoorFunction().GetParameterDQ().IsPositive());
ASSERT(mpData->mpKey->GetTrapdoorFunction().GetParameterU().IsPositive());
byte* pOut = (byte*)pDataStream;
uint8_t* pOut = (uint8_t*)pDataStream;
int16 i16;
int32 i32;
@ -407,7 +407,7 @@ cRSAPublicKey::cRSAPublicKey(void* pDataStream)
int16 i16;
int32 i32;
byte* pIn = (byte*)pDataStream;
uint8_t* pIn = (uint8_t*)pDataStream;
memcpy(&i16, pIn, sizeof(i16));
mpData->mKeyLength = tw_ntohs(i16);
@ -465,7 +465,7 @@ void cRSAPublicKey::Write(void* pDataStream) const
int16 i16;
int32 i32;
byte* pOut = (byte*)pDataStream;
uint8_t* pOut = (uint8_t*)pDataStream;
i16 = tw_htons(mpData->mKeyLength);
memcpy(pOut, &i16, sizeof(i16));
@ -551,8 +551,8 @@ void cRSA::Init(KeySize keysize)
(keysize == KEY512) ? 512 : (keysize == KEY1024) ? 1024 : (keysize == KEY2048) ? 2048 : 256;
// Create a random seed and a key
byte seed[MD5::DATASIZE];
byte deskey[TripleDES_Encryption::KEYLENGTH];
uint8_t seed[MD5::DATASIZE];
uint8_t deskey[TripleDES_Encryption::KEYLENGTH];
RandomizeBytes((int8*)seed, MD5::DATASIZE);
RandomizeBytes((int8*)deskey, TripleDES_Encryption::KEYLENGTH);
@ -648,14 +648,14 @@ void cRSA::ProcessBlock(const void* indata, void* outdata)
ASSERT(mpData->mpPublicKey->mpData->mpKey->MaxPlainTextLength() == GetBlockSizePlain());
ASSERT(mpData->mpPublicKey->mpData->mpKey->CipherTextLength() == GetBlockSizeCipher());
mpData->mpPublicKey->mpData->mpKey->Encrypt(
*mpData->mpRNG, (const byte*)indata, GetBlockSizePlain(), (byte*)outdata);
*mpData->mpRNG, (const uint8_t*)indata, GetBlockSizePlain(), (uint8_t*)outdata);
break;
}
case cRSA_i::DECRYPT:
{
ASSERT(mpData->mpPrivateKey);
ASSERT(mpData->mpPrivateKey->mpData->mpKey->CipherTextLength() == GetBlockSizeCipher());
l = mpData->mpPrivateKey->mpData->mpKey->Decrypt((const byte*)indata, (byte*)outdata);
l = mpData->mpPrivateKey->mpData->mpKey->Decrypt((const uint8_t*)indata, (uint8_t*)outdata);
if (l != GetBlockSizePlain())
throw eArchiveCrypto();
break;
@ -666,14 +666,14 @@ void cRSA::ProcessBlock(const void* indata, void* outdata)
ASSERT(mpData->mpPrivateKey->mpData->mpKey->MaxMessageLength() == GetBlockSizePlain());
ASSERT(mpData->mpPrivateKey->mpData->mpKey->SignatureLength() == GetBlockSizeCipher());
mpData->mpPrivateKey->mpData->mpKey->Sign(
*mpData->mpRNG, (const byte*)indata, GetBlockSizePlain(), (byte*)outdata);
*mpData->mpRNG, (const uint8_t*)indata, GetBlockSizePlain(), (uint8_t*)outdata);
break;
}
case cRSA_i::VERIFY:
{
ASSERT(mpData->mpPublicKey);
ASSERT(mpData->mpPublicKey->mpData->mpKey->SignatureLength() == GetBlockSizeCipher());
l = mpData->mpPublicKey->mpData->mpKey->Recover((const byte*)indata, (byte*)outdata);
l = mpData->mpPublicKey->mpData->mpKey->Recover((const uint8_t*)indata, (uint8_t*)outdata);
if (l != GetBlockSizePlain())
throw eArchiveCrypto();
break;
@ -740,7 +740,7 @@ cElGamalSigPrivateKey::cElGamalSigPrivateKey(void* pDataStream)
int16 i16;
uint32 magicNum;
byte* pIn = (byte*)pDataStream;
uint8_t* pIn = (uint8_t*)pDataStream;
memcpy(&i16, pIn, sizeof(i16));
mpData->mKeyLength = tw_ntohs(i16);
@ -802,7 +802,7 @@ void cElGamalSigPrivateKey::Write(void* pDataStream) const
ASSERT(mpData->mpKey->GetParameterY().IsPositive());
ASSERT(mpData->mpKey->GetParameterX().IsPositive());
byte* pOut = (byte*)pDataStream;
uint8_t* pOut = (uint8_t*)pDataStream;
int16 i16;
int32 i32;
@ -857,7 +857,7 @@ cElGamalSigPublicKey::cElGamalSigPublicKey(void* pDataStream)
int32 i32;
uint32 magicNum;
byte* pIn = (byte*)pDataStream;
uint8_t* pIn = (uint8_t*)pDataStream;
memcpy(&i16, pIn, sizeof(i16));
mpData->mKeyLength = tw_ntohs(i16);
@ -927,7 +927,7 @@ void cElGamalSigPublicKey::Write(void* pDataStream) const
ASSERT(mpData->mpKey->GetParameterG().IsPositive());
ASSERT(mpData->mpKey->GetParameterY().IsPositive());
byte* pOut = (byte*)pDataStream;
uint8_t* pOut = (uint8_t*)pDataStream;
int16 i16;
int32 i32;
@ -1038,8 +1038,8 @@ void cElGamalSig::Init(KeySize keysize)
(keysize == KEY512) ? 512 : (keysize == KEY1024) ? 1024 : (keysize == KEY2048) ? 2048 : 256;
// Create a random seed and a key
byte seed[SHA::DATASIZE];
byte deskey[TripleDES_Encryption::KEYLENGTH];
uint8_t seed[SHA::DATASIZE];
uint8_t deskey[TripleDES_Encryption::KEYLENGTH];
RandomizeBytes((int8*)seed, SHA::DATASIZE);
RandomizeBytes((int8*)deskey, TripleDES_Encryption::KEYLENGTH);
@ -1109,19 +1109,19 @@ void cElGamalSig::ProcessBlock(const void* indata, void* outdata)
memmove(outdata, indata, PLAIN_BLOCK_SIZE);
mpData->mSHA.CalculateDigest((byte*)shaSig, (byte*)outdata, PLAIN_BLOCK_SIZE);
mpData->mSHA.CalculateDigest((uint8_t*)shaSig, (uint8_t*)outdata, PLAIN_BLOCK_SIZE);
RandomizeBytes((int8*)outdata + PLAIN_BLOCK_SIZE, GetBlockSizeCipher() - PLAIN_BLOCK_SIZE);
mpData->mpPrivateKey->mpData->mpKey->Sign(
*mpData->mpRNG, (const byte*)shaSig, SHA::DIGESTSIZE, (byte*)outdata + PLAIN_BLOCK_SIZE);
*mpData->mpRNG, (const uint8_t*)shaSig, SHA::DIGESTSIZE, (uint8_t*)outdata + PLAIN_BLOCK_SIZE);
/*
Integer m((const byte*)indata, PLAIN_BLOCK_SIZE);
Integer m((const uint8_t*)indata, PLAIN_BLOCK_SIZE);
std::cout << "Signing:\n";
std::cout << "M = " << m << std::endl;
const byte* signature = (const byte *)outdata + PLAIN_BLOCK_SIZE;
const uint8_t* signature = (const uint8_t *)outdata + PLAIN_BLOCK_SIZE;
int qLen = mpData->mpPrivateKey->mpData->mpKey->q.ByteCount();
Integer rs(signature, qLen);
Integer ss(signature+qLen, qLen);
@ -1136,12 +1136,12 @@ void cElGamalSig::ProcessBlock(const void* indata, void* outdata)
ASSERT(mpData->mpPublicKey != 0);
ASSERT((int)mpData->mpPublicKey->mpData->mpKey->SignatureLength() + PLAIN_BLOCK_SIZE <= GetBlockSizeCipher());
mpData->mSHA.CalculateDigest((byte*)shaSig, (byte*)indata, PLAIN_BLOCK_SIZE);
mpData->mSHA.CalculateDigest((uint8_t*)shaSig, (uint8_t*)indata, PLAIN_BLOCK_SIZE);
/*
const byte* signature = (const byte *)indata + PLAIN_BLOCK_SIZE;
const uint8_t* signature = (const uint8_t *)indata + PLAIN_BLOCK_SIZE;
int qLen = mpData->mpPublicKey->mpData->mpKey->q.ByteCount();
Integer m((const byte*)indata, PLAIN_BLOCK_SIZE);
Integer m((const uint8_t*)indata, PLAIN_BLOCK_SIZE);
Integer r(signature, qLen);
Integer s(signature+qLen, qLen);
std::cout << "Verifying:\n";
@ -1151,7 +1151,7 @@ void cElGamalSig::ProcessBlock(const void* indata, void* outdata)
*/
if (mpData->mpPublicKey->mpData->mpKey->Verify(
(const byte*)shaSig, SHA::DIGESTSIZE, (const byte*)indata + PLAIN_BLOCK_SIZE) == false)
(const uint8_t*)shaSig, SHA::DIGESTSIZE, (const uint8_t*)indata + PLAIN_BLOCK_SIZE) == false)
throw eArchiveCrypto();
memmove(outdata, indata, PLAIN_BLOCK_SIZE);
break;
@ -1194,7 +1194,7 @@ cHashedKey128::cHashedKey128(const TSTRING& data)
SHA sha;
ASSERT(SHA::DIGESTSIZE >= KEYLEN);
sha.CalculateDigest((byte*)mKey, (byte*)data.data(), data.length() * sizeof(TCHAR));
sha.CalculateDigest((uint8_t*)mKey, (uint8_t*)data.data(), data.length() * sizeof(TCHAR));
}
cHashedKey128::cHashedKey128(void* pData, int dataLen)
@ -1203,7 +1203,7 @@ cHashedKey128::cHashedKey128(void* pData, int dataLen)
ASSERT(SHA::DIGESTSIZE >= KEYLEN);
ASSERT(SHA::DIGESTSIZE <= BUFSIZE);
sha.CalculateDigest((byte*)mKey, (byte*)pData, dataLen);
sha.CalculateDigest((uint8_t*)mKey, (uint8_t*)pData, dataLen);
}
cHashedKey128::~cHashedKey128()
@ -1221,8 +1221,8 @@ cHashedKey192::cHashedKey192(const TSTRING& data)
ASSERT(SHA::DIGESTSIZE == 20);
ASSERT(40 >= KEYLEN);
byte localKey[40];
sha.CalculateDigest(localKey, (byte*)data.data(), data.length() * sizeof(TCHAR));
uint8_t localKey[40];
sha.CalculateDigest(localKey, (uint8_t*)data.data(), data.length() * sizeof(TCHAR));
sha.CalculateDigest(localKey + 20, localKey, 20);
memcpy(mKey, localKey, KEYLEN);
}
@ -1234,8 +1234,8 @@ cHashedKey192::cHashedKey192(void* pData, int dataLen)
ASSERT(SHA::DIGESTSIZE == 20);
ASSERT(40 >= KEYLEN);
byte localKey[40];
sha.CalculateDigest(localKey, (byte*)pData, dataLen);
uint8_t localKey[40];
sha.CalculateDigest(localKey, (uint8_t*)pData, dataLen);
sha.CalculateDigest(localKey + 20, localKey, 20);
memcpy(mKey, localKey, KEYLEN);
}
@ -1257,7 +1257,7 @@ static bool randomize_by_device(const char* device_name, int8* destbuf, int len)
if (rng_device >= 0)
{
int bytes_read = read(rng_device, destbuf, len);
int uint8_ts_read = read(rng_device, destbuf, len);
if (bytes_read == len)
return true;
}
@ -1303,6 +1303,6 @@ void RandomizeBytes(int8* destbuf, int len)
int i;
for (i = 0; i < len; ++i)
destbuf[i] = (byte)((rand() * 256 / RAND_MAX) ^ 0xdc); // 0xdc came from random.org
destbuf[i] = (uint8_t)((rand() * 256 / RAND_MAX) ^ 0xdc); // 0xdc came from random.org
#endif
}

View File

@ -66,10 +66,10 @@ public:
cCryptoSink(cArchive* pDestArchive, iCipher* pCipher);
~cCryptoSink();
virtual void Put(const byte* inString, unsigned int length);
virtual void Put(const uint8_t* inString, unsigned int length);
virtual void InputFinished();
virtual void Put(byte inByte)
virtual void Put(uint8_t inByte)
{
Put(&inByte, 1);
}
@ -171,7 +171,7 @@ int cCryptoArchive::Write(const void* pSrc, int count)
throw eArchiveInvalidOp();
}
mpDeflator->Put((byte*)pSrc, count);
mpDeflator->Put((uint8_t*)pSrc, count);
return count;
}
@ -210,13 +210,13 @@ int cCryptoArchive::Read(void* pDest, int count)
if ((int)mpInflatedBytes->CurrentSize() < count) // RAD: Cast to int
{
len = mpInflatedBytes->CurrentSize();
mpInflatedBytes->Get((byte*)pDest, len);
mpInflatedBytes->Get((uint8_t*)pDest, len);
return len;
}
}
}
len = mpInflatedBytes->Get((byte*)pDest, count);
len = mpInflatedBytes->Get((uint8_t*)pDest, count);
ASSERT(len == count);
return len;
@ -278,7 +278,7 @@ cCryptoSink::~cCryptoSink()
delete [] mpBuffer;
}
void cCryptoSink::Put(const byte* inString, unsigned int length)
void cCryptoSink::Put(const uint8_t* inString, unsigned int length)
{
if (mpBuffer == 0)
{
@ -400,7 +400,7 @@ unsigned int cCryptoSource::Pump(unsigned int size)
if (bytesToCopy > nSize - i)
bytesToCopy = nSize - i;
outQueue->Put((byte*)(mpBuffer + mBufferUsed), bytesToCopy);
outQueue->Put((uint8_t*)(mpBuffer + mBufferUsed), bytesToCopy);
mBufferUsed += bytesToCopy;
i += bytesToCopy;

View File

@ -679,8 +679,15 @@ void cParserUtil::CreatePropVector(const TSTRING& strPropListC, class cFCOPropVe
// clear out all spaces in the string
TSTRING strPropList = strPropListC;
strPropList.erase(std::remove_if(strPropList.begin(), strPropList.end(), std::ptr_fun<int, int>(std::isspace)),
strPropList.end());
// C++17 removes std::ptr_fun, so use a lambda where available
#if __cplusplus < 201103L
strPropList.erase(std::remove_if(strPropList.begin(), strPropList.end(),
std::ptr_fun<int, int>(std::isspace)), strPropList.end());
#else
strPropList.erase(std::remove_if(strPropList.begin(), strPropList.end(),
[](int c) {return std::isspace(c);}), strPropList.end());
#endif
// zero it out
v.Clear();

View File

@ -70,11 +70,14 @@ void tw_terminate_handler()
_exit(1);
}
// Exception specifications removed as a misfeature in C++17
#if __cplusplus < 201703L
void tw_unexpected_handler()
{
fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr);
_exit(1);
}
#endif
int __cdecl _tmain(int argc, const TCHAR* argv[])
{
@ -93,17 +96,16 @@ int __cdecl _tmain(int argc, const TCHAR* argv[])
// TODO: move this into the Init() routine
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
#if __cplusplus < 201703L
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
#endif
twInit.Init(argv[0]);
TSS_Dependency(cTWPrint);
// init twprint strings
//
cDebug::SetDebugLevel(cDebug::D_DEBUG);
// **** let's try a new way of doing things!
// first, process the command line
if (argc < 2)

View File

@ -68,7 +68,7 @@ public:
AlignMe();
private:
byte a[sizeof(int64) + ALIGN_SIZE]; // we want to be able to access a int64 at address [ALIGN_SIZE]
uint8_t a[sizeof(int64) + ALIGN_SIZE]; // we want to be able to access a int64 at address [ALIGN_SIZE]
};
/////////////////////////////////////////////////////////
@ -152,7 +152,7 @@ void TestAlignment()
// such accesses: it may have handled the
// hardware interrupt that might have occured.
// - - - - - - - - - - - - - - - - - - - - - -
byte a[sizeof(int32) + sizeof(byte)];
uint8_t a[sizeof(int32) + sizeof(uint8_t)];
// this should be fine
a[0] = 0xAB;
@ -177,7 +177,7 @@ void TestAlignment()
// if it works, then our BYTE_ALIGN value is large enough
// - - - - - - - - - - - - - - - - - - - - - -
byte b[2 * sizeof(BYTE_ALIGN)];
uint8_t b[2 * sizeof(BYTE_ALIGN)];
// this should be fine
b[0] = 0xAB;

View File

@ -54,7 +54,7 @@ public:
private:
int mNumber;
byte mData[20];
uint8_t mData[20];
TSTRING mString;
};

View File

@ -76,10 +76,10 @@ void TestSignatureBasic()
cCRC32Signature crcSig;
cDebug d("TestSignature1");
byte abData[64];
uint8_t abData[64];
int i;
for (i = 0; i < 64; i++)
abData[i] = static_cast<byte>(rand());
abData[i] = static_cast<uint8_t>(rand());
crcSig.Init();
crcSig.Update(&abData[0], 32);
@ -111,7 +111,7 @@ void TestChecksum()
// test begins here
// general signature & archive variables
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead;
@ -165,7 +165,7 @@ void TestCRC32()
cDebug d("TestCRC32");
// general signature & archive variables
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead;
@ -219,7 +219,7 @@ void TestMD5()
cDebug d("TestMD5");
// general signature & archive variables
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead;
@ -273,7 +273,7 @@ void TestSHA1()
cDebug d("TestSHA1");
// general signature & archive variables
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead;
@ -327,7 +327,7 @@ void TestHAVAL()
cDebug d("TestHAVAL");
// general signature & archive variables
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
uint8_t abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead;
@ -418,7 +418,7 @@ void assertMD5(const std::string& source, const std::string& expectedHex)
cMD5Signature md5Sig;
md5Sig.Init();
md5Sig.Update((const byte*)source.c_str(), source.length());
md5Sig.Update((const uint8_t*)source.c_str(), source.length());
md5Sig.Finit();
TEST(md5Sig.AsStringHex() == expectedHex);
@ -430,7 +430,7 @@ void assertSHA1(const std::string& source, const std::string& expectedHex)
cSHASignature shaSig;
shaSig.Init();
shaSig.Update((const byte*)source.c_str(), source.length());
shaSig.Update((const uint8_t*)source.c_str(), source.length());
shaSig.Finit();
TEST(shaSig.AsStringHex() == expectedHex);

View File

@ -431,11 +431,13 @@ void tw_terminate_handler()
exit(1);
}
#if __cplusplus < 201703L
void tw_unexpected_handler()
{
fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr);
exit(1);
}
#endif
int _tmain(int argc, TCHAR** argv)
{
@ -449,8 +451,9 @@ int _tmain(int argc, TCHAR** argv)
try
{
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
#if __cplusplus < 201703L
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
#endif
if (argc < 2)
{
Usage();