Skip to content

Commit

Permalink
Fix conflict with SHA1 function from openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
widgetii authored and azat committed Sep 14, 2022
1 parent e831308 commit 53f9c42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 14 additions & 5 deletions sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ A million repetitions of "a"
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);

static void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);

static void SHA1Init(SHA1_CTX *context);

static void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len);

static void SHA1Final(unsigned char digest[20], SHA1_CTX *context);


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

void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
static void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
uint32_t a, b, c, d, e;

typedef union {
Expand Down Expand Up @@ -184,7 +193,7 @@ void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {

/* SHA1Init - Initialize new context */

void SHA1Init(SHA1_CTX *context) {
static void SHA1Init(SHA1_CTX *context) {
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
Expand All @@ -196,7 +205,7 @@ void SHA1Init(SHA1_CTX *context) {

/* Run your data through this. */

void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len) {
static void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len) {
uint32_t i;

uint32_t j;
Expand All @@ -220,7 +229,7 @@ void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len) {

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

void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
static void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
unsigned i;

unsigned char finalcount[8];
Expand Down Expand Up @@ -267,7 +276,7 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
memset(&finalcount, '\0', sizeof(finalcount));
}

void SHA1(char *hash_out, const char *str, int len) {
void builtin_SHA1(char *hash_out, const char *str, int len) {
SHA1_CTX ctx;
int ii;

Expand Down
10 changes: 1 addition & 9 deletions sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ typedef struct {
unsigned char buffer[64];
} SHA1_CTX;

void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);

void SHA1Init(SHA1_CTX *context);

void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len);

void SHA1Final(unsigned char digest[20], SHA1_CTX *context);

void SHA1(char *hash_out, const char *str, int len);
void builtin_SHA1(char *hash_out, const char *str, int len);

#endif /* SHA1_H */
2 changes: 1 addition & 1 deletion ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ws_gen_accept_key(const char *ws_key, char out[32])

snprintf(buf, sizeof(buf), "%s" WS_UUID, ws_key);

SHA1(digest, buf, strlen(buf));
builtin_SHA1(digest, buf, strlen(buf));
Base64encode(out, digest, sizeof(digest));
return out;
}
Expand Down

0 comments on commit 53f9c42

Please sign in to comment.