Skip to content

Commit c922801

Browse files
authored
Fix data type conflict (#306) (#323)
1 parent b4e9c8b commit c922801

File tree

9 files changed

+76
-98
lines changed

9 files changed

+76
-98
lines changed

trantor/net/inner/FileBufferNodeWin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class FileBufferNode : public BufferNode
105105
DWORD n = 0;
106106
if (!ReadFile(sendHandle_,
107107
msgBufferPtr_->beginWrite(),
108-
msgBufferPtr_->writableBytes(),
108+
(uint32_t)msgBufferPtr_->writableBytes(),
109109
&n,
110110
nullptr))
111111
{

trantor/utils/Utilities.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ Hash128 md5(const void *data, size_t len)
366366
Hash160 sha1(const void *data, size_t len)
367367
{
368368
SHA1_CTX ctx;
369-
TrantorSHA1Init(&ctx);
370-
TrantorSHA1Update(&ctx, (const unsigned char *)data, len);
369+
trantor_sha1_init(&ctx);
370+
trantor_sha1_update(&ctx, (const unsigned char *)data, len);
371371
Hash160 hash;
372-
TrantorSHA1Final((unsigned char *)&hash, &ctx);
372+
trantor_sha1_final((unsigned char *)&hash, &ctx);
373373
return hash;
374374
}
375375

trantor/utils/crypto/md5.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ order.
4545
}
4646

4747
/*********************** FUNCTION DEFINITIONS ***********************/
48-
void trantor_md5_transform(MD5_CTX *ctx, const BYTE data[])
48+
void trantor_md5_transform(MD5_CTX *ctx, const uint8_t data[])
4949
{
50-
WORD a, b, c, d, m[16], i, j;
50+
uint32_t a, b, c, d, m[16], i, j;
5151

5252
// MD5 specifies big endian byte order, but this implementation assumes a
5353
// little endian byte order CPU. Reverse all the bytes upon input, and
@@ -145,7 +145,7 @@ void trantor_md5_init(MD5_CTX *ctx)
145145
ctx->state[3] = 0x10325476;
146146
}
147147

148-
void trantor_md5_update(MD5_CTX *ctx, const BYTE data[], size_t len)
148+
void trantor_md5_update(MD5_CTX *ctx, const uint8_t data[], size_t len)
149149
{
150150
size_t i;
151151

@@ -162,7 +162,7 @@ void trantor_md5_update(MD5_CTX *ctx, const BYTE data[], size_t len)
162162
}
163163
}
164164

165-
void trantor_md5_final(MD5_CTX *ctx, BYTE hash[])
165+
void trantor_md5_final(MD5_CTX *ctx, uint8_t hash[])
166166
{
167167
size_t i;
168168

@@ -186,14 +186,14 @@ void trantor_md5_final(MD5_CTX *ctx, BYTE hash[])
186186

187187
// Append to the padding the total message's length in bits and transform.
188188
ctx->bitlen += ctx->datalen * 8;
189-
ctx->data[56] = ctx->bitlen;
190-
ctx->data[57] = ctx->bitlen >> 8;
191-
ctx->data[58] = ctx->bitlen >> 16;
192-
ctx->data[59] = ctx->bitlen >> 24;
193-
ctx->data[60] = ctx->bitlen >> 32;
194-
ctx->data[61] = ctx->bitlen >> 40;
195-
ctx->data[62] = ctx->bitlen >> 48;
196-
ctx->data[63] = ctx->bitlen >> 56;
189+
ctx->data[56] = (uint8_t)ctx->bitlen;
190+
ctx->data[57] = (uint8_t)(ctx->bitlen >> 8);
191+
ctx->data[58] = (uint8_t)(ctx->bitlen >> 16);
192+
ctx->data[59] = (uint8_t)(ctx->bitlen >> 24);
193+
ctx->data[60] = (uint8_t)(ctx->bitlen >> 32);
194+
ctx->data[61] = (uint8_t)(ctx->bitlen >> 40);
195+
ctx->data[62] = (uint8_t)(ctx->bitlen >> 48);
196+
ctx->data[63] = (uint8_t)(ctx->bitlen >> 56);
197197
trantor_md5_transform(ctx, ctx->data);
198198

199199
// Since this implementation uses little endian byte ordering and MD uses

trantor/utils/crypto/md5.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,22 @@
1111

1212
/*************************** HEADER FILES ***************************/
1313
#include <stddef.h>
14+
#include <stdint.h>
1415

1516
/****************************** MACROS ******************************/
16-
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
17-
18-
/**************************** DATA TYPES ****************************/
19-
20-
#ifndef _WIN32
21-
typedef unsigned char BYTE; // 8-bit byte
22-
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
23-
#else
24-
#include <windows.h>
25-
#endif
17+
#define MD5_BLOCK_SIZE 32 // MD5 outputs a 32 byte digest
2618

2719
typedef struct
2820
{
29-
BYTE data[64];
30-
WORD datalen;
31-
unsigned long long bitlen;
32-
WORD state[4];
21+
uint8_t data[64];
22+
uint32_t datalen;
23+
uint64_t bitlen;
24+
uint32_t state[4];
3325
} MD5_CTX;
3426

3527
/*********************** FUNCTION DECLARATIONS **********************/
3628
void trantor_md5_init(MD5_CTX *ctx);
37-
void trantor_md5_update(MD5_CTX *ctx, const BYTE data[], size_t len);
38-
void trantor_md5_final(MD5_CTX *ctx, BYTE hash[]);
29+
void trantor_md5_update(MD5_CTX *ctx, const uint8_t data[], size_t len);
30+
void trantor_md5_final(MD5_CTX *ctx, uint8_t hash[]);
3931

4032
#endif // MD5_H

trantor/utils/crypto/sha1.cc

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ A million repetitions of "a"
2121

2222
#include <stdio.h>
2323
#include <string.h>
24-
#include <sys/types.h> /* for u_int*_t */
2524
#if defined(__sun)
2625
#include "solarisfixes.h"
2726
#endif
@@ -114,17 +113,13 @@ A million repetitions of "a"
114113

115114
/* Hash a single 512-bit block. This is the core of the algorithm. */
116115

117-
#ifdef _WIN32
118-
using u_int32_t = uint32_t;
119-
#endif
120-
121-
void TrantorSHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
116+
void trantor_sha1_transform(uint32_t state[5], const unsigned char buffer[64])
122117
{
123-
u_int32_t a, b, c, d, e;
118+
uint32_t a, b, c, d, e;
124119
typedef union
125120
{
126121
unsigned char c[64];
127-
u_int32_t l[16];
122+
uint32_t l[16];
128123
} CHAR64LONG16;
129124
#ifdef SHA1HANDSOFF
130125
CHAR64LONG16 block[1]; /* use array to appear as a pointer */
@@ -237,9 +232,9 @@ void TrantorSHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
237232
#endif
238233
}
239234

240-
/* TrantorSHA1Init - Initialize new context */
235+
/* trantor_sha1_init - Initialize new context */
241236

242-
void TrantorSHA1Init(SHA1_CTX* context)
237+
void trantor_sha1_init(SHA1_CTX* context)
243238
{
244239
/* SHA1 initialization constants */
245240
context->state[0] = 0x67452301;
@@ -252,7 +247,9 @@ void TrantorSHA1Init(SHA1_CTX* context)
252247

253248
/* Run your data through this. */
254249

255-
void TrantorSHA1Update(SHA1_CTX* context, const unsigned char* data, size_t len)
250+
void trantor_sha1_update(SHA1_CTX* context,
251+
const unsigned char* data,
252+
size_t len)
256253
{
257254
size_t i;
258255
size_t j;
@@ -265,10 +262,10 @@ void TrantorSHA1Update(SHA1_CTX* context, const unsigned char* data, size_t len)
265262
if ((j + len) > 63)
266263
{
267264
memcpy(&context->buffer[j], data, (i = 64 - j));
268-
TrantorSHA1Transform(context->state, context->buffer);
265+
trantor_sha1_transform(context->state, context->buffer);
269266
for (; i + 63 < len; i += 64)
270267
{
271-
TrantorSHA1Transform(context->state, &data[i]);
268+
trantor_sha1_transform(context->state, &data[i]);
272269
}
273270
j = 0;
274271
}
@@ -279,7 +276,7 @@ void TrantorSHA1Update(SHA1_CTX* context, const unsigned char* data, size_t len)
279276

280277
/* Add padding and return the message digest. */
281278

282-
void TrantorSHA1Final(unsigned char digest[20], SHA1_CTX* context)
279+
void trantor_sha1_final(unsigned char digest[20], SHA1_CTX* context)
283280
{
284281
unsigned i;
285282
unsigned char finalcount[8];
@@ -295,7 +292,7 @@ void TrantorSHA1Final(unsigned char digest[20], SHA1_CTX* context)
295292

296293
for (i = 0; i < 2; i++)
297294
{
298-
u_int32_t t = context->count[i];
295+
uint32_t t = context->count[i];
299296
int j;
300297

301298
for (j = 0; j < 4; t >>= 8, j++)
@@ -310,15 +307,15 @@ void TrantorSHA1Final(unsigned char digest[20], SHA1_CTX* context)
310307
}
311308
#endif
312309
c = 0200;
313-
TrantorSHA1Update(context, &c, 1);
310+
trantor_sha1_update(context, &c, 1);
314311
while ((context->count[0] & 504) != 448)
315312
{
316313
c = 0000;
317-
TrantorSHA1Update(context, &c, 1);
314+
trantor_sha1_update(context, &c, 1);
318315
}
319-
TrantorSHA1Update(context,
320-
finalcount,
321-
8); /* Should cause a TrantorSHA1Transform() */
316+
trantor_sha1_update(context,
317+
finalcount,
318+
8); /* Should cause a TrantorSHA1Transform() */
322319
for (i = 0; i < 20; i++)
323320
{
324321
digest[i] =

trantor/utils/crypto/sha1.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ typedef struct
1818
unsigned char buffer[64];
1919
} SHA1_CTX;
2020

21-
void TrantorSHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
22-
void TrantorSHA1Init(SHA1_CTX* context);
23-
void TrantorSHA1Update(SHA1_CTX* context,
24-
const unsigned char* data,
25-
size_t len);
26-
void TrantorSHA1Final(unsigned char digest[20], SHA1_CTX* context);
21+
void trantor_sha1_transform(uint32_t state[5], const unsigned char buffer[64]);
22+
void trantor_sha1_init(SHA1_CTX* context);
23+
void trantor_sha1_update(SHA1_CTX* context,
24+
const unsigned char* data,
25+
size_t len);
26+
void trantor_sha1_final(unsigned char digest[20], SHA1_CTX* context);

trantor/utils/crypto/sha256.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define SIG1(x) (ROTRIGHT(x, 17) ^ ROTRIGHT(x, 19) ^ ((x) >> 10))
3030

3131
/**************************** VARIABLES *****************************/
32-
static const unsigned int k[64] = {
32+
static const uint32_t k[64] = {
3333
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
3434
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
3535
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
@@ -43,9 +43,9 @@ static const unsigned int k[64] = {
4343
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
4444

4545
/*********************** FUNCTION DEFINITIONS ***********************/
46-
void trantor_sha256_transform(SHA256_CTX *ctx, const BYTE data[])
46+
void trantor_sha256_transform(SHA256_CTX *ctx, const uint8_t data[])
4747
{
48-
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
48+
uint32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
4949

5050
for (i = 0, j = 0; i < 16; ++i, j += 4)
5151
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) |
@@ -100,9 +100,9 @@ void trantor_sha256_init(SHA256_CTX *ctx)
100100
ctx->state[7] = 0x5be0cd19;
101101
}
102102

103-
void trantor_sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
103+
void trantor_sha256_update(SHA256_CTX *ctx, const uint8_t data[], size_t len)
104104
{
105-
WORD i;
105+
uint32_t i;
106106

107107
for (i = 0; i < len; ++i)
108108
{
@@ -117,9 +117,9 @@ void trantor_sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
117117
}
118118
}
119119

120-
void trantor_sha256_final(SHA256_CTX *ctx, BYTE hash[])
120+
void trantor_sha256_final(SHA256_CTX *ctx, uint8_t hash[])
121121
{
122-
WORD i;
122+
uint32_t i;
123123

124124
i = ctx->datalen;
125125

@@ -141,14 +141,14 @@ void trantor_sha256_final(SHA256_CTX *ctx, BYTE hash[])
141141

142142
// Append to the padding the total message's length in bits and transform.
143143
ctx->bitlen += ctx->datalen * 8;
144-
ctx->data[63] = ctx->bitlen;
145-
ctx->data[62] = ctx->bitlen >> 8;
146-
ctx->data[61] = ctx->bitlen >> 16;
147-
ctx->data[60] = ctx->bitlen >> 24;
148-
ctx->data[59] = ctx->bitlen >> 32;
149-
ctx->data[58] = ctx->bitlen >> 40;
150-
ctx->data[57] = ctx->bitlen >> 48;
151-
ctx->data[56] = ctx->bitlen >> 56;
144+
ctx->data[63] = (uint8_t)ctx->bitlen;
145+
ctx->data[62] = (uint8_t)(ctx->bitlen >> 8);
146+
ctx->data[61] = (uint8_t)(ctx->bitlen >> 16);
147+
ctx->data[60] = (uint8_t)(ctx->bitlen >> 24);
148+
ctx->data[59] = (uint8_t)(ctx->bitlen >> 32);
149+
ctx->data[58] = (uint8_t)(ctx->bitlen >> 40);
150+
ctx->data[57] = (uint8_t)(ctx->bitlen >> 48);
151+
ctx->data[56] = (uint8_t)(ctx->bitlen >> 56);
152152
trantor_sha256_transform(ctx, ctx->data);
153153

154154
// Since this implementation uses little endian byte ordering and SHA uses

trantor/utils/crypto/sha256.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,22 @@
1010
#define SHA256_H
1111

1212
/*************************** HEADER FILES ***************************/
13-
#ifndef _WIN32
14-
#include <stddef.h>
15-
#else
16-
#include <windows.h>
17-
#endif
13+
#include <stdint.h>
1814

1915
/****************************** MACROS ******************************/
2016
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
2117

22-
/**************************** DATA TYPES ****************************/
23-
24-
#ifndef _WIN32
25-
typedef unsigned char BYTE; // 8-bit byte
26-
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
27-
#endif
28-
2918
typedef struct
3019
{
31-
BYTE data[64];
32-
WORD datalen;
33-
unsigned long long bitlen;
34-
WORD state[8];
20+
uint8_t data[64];
21+
uint32_t datalen;
22+
uint64_t bitlen;
23+
uint32_t state[8];
3524
} SHA256_CTX;
3625

3726
/*********************** FUNCTION DECLARATIONS **********************/
3827
void trantor_sha256_init(SHA256_CTX *ctx);
39-
void trantor_sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
40-
void trantor_sha256_final(SHA256_CTX *ctx, BYTE hash[]);
28+
void trantor_sha256_update(SHA256_CTX *ctx, const uint8_t data[], size_t len);
29+
void trantor_sha256_final(SHA256_CTX *ctx, uint8_t hash[]);
4130

4231
#endif // SHA256_H

trantor/utils/crypto/sha3.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ typedef struct
2727
} sha3_ctx_t;
2828

2929
// Compression function.
30-
void trnator_sha3_keccakf(uint64_t st[25]);
30+
void trantor_sha3_keccakf(uint64_t st[25]);
3131

32-
// OpenSSL - like interfece
32+
// OpenSSL - like interface
3333
int trantor_sha3_init(sha3_ctx_t *c,
3434
int mdlen); // mdlen = hash output in bytes
3535
int trantor_sha3_update(sha3_ctx_t *c, const void *data, size_t len);
@@ -39,11 +39,11 @@ int trantor_sha3_final(void *md, sha3_ctx_t *c); // digest goes to md
3939
void *trantor_sha3(const void *in, size_t inlen, void *md, int mdlen);
4040

4141
// SHAKE128 and SHAKE256 extensible-output functions
42-
#define trantor_shake128_init(c) trnator_sha3_init(c, 16)
43-
#define trantor_shake256_init(c) trnator_sha3_init(c, 32)
44-
#define trantor_shake_update trnator_sha3_update
42+
#define trantor_shake128_init(c) trantor_sha3_init(c, 16)
43+
#define trantor_shake256_init(c) trantor_sha3_init(c, 32)
44+
#define trantor_shake_update trantor_sha3_update
4545

46-
void trnator_shake_xof(sha3_ctx_t *c);
47-
void trnator_shake_out(sha3_ctx_t *c, void *out, size_t len);
46+
void trantor_shake_xof(sha3_ctx_t *c);
47+
void trantor_shake_out(sha3_ctx_t *c, void *out, size_t len);
4848

4949
#endif

0 commit comments

Comments
 (0)