Skip to content

Commit 8601bb9

Browse files
authored
Fix building built-in hashes on Windows (#258)
1 parent 60fb0a0 commit 8601bb9

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

trantor/utils/crypto/md5.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
1717

1818
/**************************** DATA TYPES ****************************/
19+
20+
#ifndef _WIN32
1921
typedef unsigned char BYTE; // 8-bit byte
2022
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
23+
#else
24+
#include <Windows.h>
25+
#endif
2126

2227
typedef struct
2328
{

trantor/utils/crypto/sha1.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ A million repetitions of "a"
3838
#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
3939
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
4040

41-
#if defined(vax) || defined(ns32000) || defined(sun386) || \
42-
defined(__i386__) || defined(MIPSEL) || defined(_MIPSEL) || \
43-
defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha)
41+
#if defined(vax) || defined(ns32000) || defined(sun386) || \
42+
defined(__i386__) || defined(MIPSEL) || defined(_MIPSEL) || \
43+
defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \
44+
defined(__CYGWIN32__) || defined(_WIN64) || defined(_WIN32)
4445
#define BYTE_ORDER LITTLE_ENDIAN
4546
#endif
4647

@@ -113,6 +114,10 @@ A million repetitions of "a"
113114

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

117+
#ifdef _WIN32
118+
using u_int32_t = uint32_t;
119+
#endif
120+
116121
void TrantorSHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
117122
{
118123
u_int32_t a, b, c, d, e;
@@ -247,12 +252,10 @@ void TrantorSHA1Init(SHA1_CTX* context)
247252

248253
/* Run your data through this. */
249254

250-
void TrantorSHA1Update(SHA1_CTX* context,
251-
const unsigned char* data,
252-
u_int32_t len)
255+
void TrantorSHA1Update(SHA1_CTX* context, const unsigned char* data, size_t len)
253256
{
254-
u_int32_t i;
255-
u_int32_t j;
257+
size_t i;
258+
size_t j;
256259

257260
j = context->count[0];
258261
if ((context->count[0] += len << 3) < j)

trantor/utils/crypto/sha1.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ Last modified by Martin Chang for the Trantor project
99

1010
#pragma once
1111

12+
#include <stdint.h>
13+
1214
typedef struct
1315
{
14-
u_int32_t state[5];
15-
u_int32_t count[2];
16+
uint32_t state[5];
17+
size_t count[2];
1618
unsigned char buffer[64];
1719
} SHA1_CTX;
1820

19-
void TrantorSHA1Transform(u_int32_t state[5], const unsigned char buffer[64]);
21+
void TrantorSHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
2022
void TrantorSHA1Init(SHA1_CTX* context);
2123
void TrantorSHA1Update(SHA1_CTX* context,
2224
const unsigned char* data,
23-
u_int32_t len);
25+
size_t len);
2426
void TrantorSHA1Final(unsigned char digest[20], SHA1_CTX* context);

trantor/utils/crypto/sha256.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@
1010
#define SHA256_H
1111

1212
/*************************** HEADER FILES ***************************/
13+
#ifndef _WIN32
1314
#include <stddef.h>
15+
#else
16+
#include <Windows.h>
17+
#endif
1418

1519
/****************************** MACROS ******************************/
1620
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
1721

1822
/**************************** DATA TYPES ****************************/
23+
24+
#ifndef _WIN32
1925
typedef unsigned char BYTE; // 8-bit byte
2026
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
27+
#endif
2128

2229
typedef struct
2330
{

0 commit comments

Comments
 (0)