Skip to content

Commit

Permalink
Move our SHA1 to XSHA1 to avoid OpenSSL conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Jan 18, 2011
1 parent d5fa08b commit 006f5a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
8 changes: 4 additions & 4 deletions vm/builtin/system.cpp
Expand Up @@ -1016,12 +1016,12 @@ namespace rubinius {
}

String* System::sha1_hash(STATE, String* str) {
SHA1_CTX ctx;
SHA1_Init(&ctx);
SHA1_Update(&ctx, str->byte_address(), str->size());
XSHA1_CTX ctx;
XSHA1_Init(&ctx);
XSHA1_Update(&ctx, str->byte_address(), str->size());

uint8_t digest[20];
SHA1_Finish(&ctx, digest);
XSHA1_Finish(&ctx, digest);

char buf[40];
static const char hex[] = {
Expand Down
20 changes: 10 additions & 10 deletions vm/util/sha1.c
Expand Up @@ -129,7 +129,7 @@ do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LON
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
void XSHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
CHAR64LONG16 *block;
Expand Down Expand Up @@ -197,9 +197,9 @@ void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])


/*
* SHA1_Init - Initialize new context
* XSHA1_Init - Initialize new context
*/
void SHA1_Init(SHA1_CTX *context)
void XSHA1_Init(XSHA1_CTX *context)
{

_DIAGASSERT(context != 0);
Expand All @@ -217,7 +217,7 @@ void SHA1_Init(SHA1_CTX *context)
/*
* Run your data through this.
*/
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
void XSHA1_Update(XSHA1_CTX *context, const uint8_t *data, size_t len)
{
uint32_t i, j;

Expand All @@ -232,9 +232,9 @@ void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
j = (j >> 3) & 63;
if ((j + len) > 63) {
(void)memcpy(&context->buffer[j], data, (i = 64-j));
SHA1_Transform(context->state, context->buffer);
XSHA1_Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1_Transform(context->state, &data[i]);
XSHA1_Transform(context->state, &data[i]);
}
j = 0;
} else {
Expand All @@ -248,7 +248,7 @@ void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
/*
* Add padding and return the message digest.
*/
void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
void XSHA1_Finish(XSHA1_CTX* context, uint8_t digest[20])
{
size_t i;
uint8_t finalcount[8];
Expand All @@ -260,11 +260,11 @@ void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
SHA1_Update(context, (const uint8_t *)"\200", 1);
XSHA1_Update(context, (const uint8_t *)"\200", 1);
while ((context->count[0] & 504) != 448) {
SHA1_Update(context, (const uint8_t *)"\0", 1);
XSHA1_Update(context, (const uint8_t *)"\0", 1);
}
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
XSHA1_Update(context, finalcount, 8); /* Should cause a XSHA1_Transform() */

if (digest) {
for (i = 0; i < 20; i++) {
Expand Down
26 changes: 11 additions & 15 deletions vm/util/sha1.h
@@ -1,15 +1,11 @@
/* $NetBSD: sha1.h,v 1.2 1998/05/29 22:55:44 thorpej Exp $ */
/* $RoughId: sha1.h,v 1.3 2002/02/24 08:14:32 knu Exp $ */
/* $Id: sha1.h 11708 2007-02-12 23:01:19Z shyouhei $ */

/*
* SHA-1 in C
* By Steve Reid <steve@edmweb.com>
* 100% Public Domain
*/

#ifndef _SYS_SHA1_H_
#define _SYS_SHA1_H_
#ifndef _SYS_XSHA1_H_
#define _SYS_XSHA1_H_

#include <stdint.h>
#include <sys/types.h>
Expand All @@ -22,20 +18,20 @@ typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} SHA1_CTX;
} XSHA1_CTX;

void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
void SHA1_Init(SHA1_CTX *context);
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len);
void SHA1_Finish(SHA1_CTX *context, uint8_t digest[20]);
void XSHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
void XSHA1_Init(XSHA1_CTX *context);
void XSHA1_Update(XSHA1_CTX *context, const uint8_t *data, size_t len);
void XSHA1_Finish(XSHA1_CTX *context, uint8_t digest[20]);

#define SHA1_BLOCK_LENGTH 64
#define SHA1_DIGEST_LENGTH 20
#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
#define XSHA1_BLOCK_LENGTH 64
#define XSHA1_DIGEST_LENGTH 20
#define XSHA1_DIGEST_STRING_LENGTH (XSHA1_DIGEST_LENGTH * 2 + 1)


#ifdef __cplusplus
}
#endif

#endif /* _SYS_SHA1_H_ */
#endif /* _SYS_XSHA1_H_ */

0 comments on commit 006f5a1

Please sign in to comment.