Browse Source

Remove the unused sha224 functions.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
deb9aec0ed
  1. 16
      cgminer.c
  2. 4
      driver-ztex.c
  3. 43
      sha2.c
  4. 11
      sha2.h

16
cgminer.c

@ -1345,8 +1345,8 @@ static void calc_midstate(struct work *work)
for (swapcounter = 0; swapcounter < 16; swapcounter++) for (swapcounter = 0; swapcounter < 16; swapcounter++)
data.i[swapcounter] = swab32(((uint32_t*) (work->data))[swapcounter]); data.i[swapcounter] = swab32(((uint32_t*) (work->data))[swapcounter]);
sha2_context ctx; sha2_context ctx;
sha2_starts( &ctx, 0 ); sha2_starts(&ctx);
sha2_update( &ctx, data.c, 64 ); sha2_update(&ctx, data.c, 64);
memcpy(work->midstate, ctx.state, sizeof(work->midstate)); memcpy(work->midstate, ctx.state, sizeof(work->midstate));
#if defined(__BIG_ENDIAN__) || defined(MIPSEB) #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
int i; int i;
@ -2156,8 +2156,8 @@ bool regeneratehash(const struct work *work)
for (i = 0; i < 80 / 4; i++) for (i = 0; i < 80 / 4; i++)
swap32[i] = swab32(data32[i]); swap32[i] = swab32(data32[i]);
sha2(swap, 80, hash1, false); sha2(swap, 80, hash1);
sha2(hash1, 32, (unsigned char *)(work->hash), false); sha2(hash1, 32, (unsigned char *)(work->hash));
difficulty = swab32(*((uint32_t *)(work->data + 72))); difficulty = swab32(*((uint32_t *)(work->data + 72)));
@ -4951,8 +4951,8 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
{ {
unsigned char hash1[32]; unsigned char hash1[32];
sha2(data, len, hash1, false); sha2(data, len, hash1);
sha2(hash1, 32, hash, false); sha2(hash1, 32, hash);
} }
/* Diff 1 is a 256 bit unsigned integer of /* Diff 1 is a 256 bit unsigned integer of
@ -5132,8 +5132,8 @@ static bool hashtest(struct thr_info *thr, struct work *work)
bool ret = false; bool ret = false;
flip80(swap32, data32); flip80(swap32, data32);
sha2(swap, 80, hash1, false); sha2(swap, 80, hash1);
sha2(hash1, 32, hash2, false); sha2(hash1, 32, hash2);
flip32(work->hash, hash2_32); flip32(work->hash, hash2_32);
/* Flipped or not, hash2_32[7] should be 0 */ /* Flipped or not, hash2_32[7] should be 0 */

4
driver-ztex.c

@ -171,8 +171,8 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
for (i = 0; i < 80 / 4; i++) for (i = 0; i < 80 / 4; i++)
swap32[i] = swab32(data32[i]); swap32[i] = swab32(data32[i]);
sha2(swap, 80, hash1, false); sha2(swap, 80, hash1);
sha2(hash1, 32, hash2, false); sha2(hash1, 32, hash2);
#if defined(__BIGENDIAN__) || defined(MIPSEB) #if defined(__BIGENDIAN__) || defined(MIPSEB)
if (hash2_32[7] != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) { if (hash2_32[7] != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
#else #else

43
sha2.c

@ -60,37 +60,19 @@
/* /*
* SHA-256 context setup * SHA-256 context setup
*/ */
void sha2_starts( sha2_context *ctx, int is224 ) void sha2_starts( sha2_context *ctx )
{ {
ctx->total[0] = 0; ctx->total[0] = 0;
ctx->total[1] = 0; ctx->total[1] = 0;
if( is224 == 0 ) ctx->state[0] = 0x6A09E667;
{ ctx->state[1] = 0xBB67AE85;
/* SHA-256 */ ctx->state[2] = 0x3C6EF372;
ctx->state[0] = 0x6A09E667; ctx->state[3] = 0xA54FF53A;
ctx->state[1] = 0xBB67AE85; ctx->state[4] = 0x510E527F;
ctx->state[2] = 0x3C6EF372; ctx->state[5] = 0x9B05688C;
ctx->state[3] = 0xA54FF53A; ctx->state[6] = 0x1F83D9AB;
ctx->state[4] = 0x510E527F; ctx->state[7] = 0x5BE0CD19;
ctx->state[5] = 0x9B05688C;
ctx->state[6] = 0x1F83D9AB;
ctx->state[7] = 0x5BE0CD19;
}
else
{
/* SHA-224 */
ctx->state[0] = 0xC1059ED8;
ctx->state[1] = 0x367CD507;
ctx->state[2] = 0x3070DD17;
ctx->state[3] = 0xF70E5939;
ctx->state[4] = 0xFFC00B31;
ctx->state[5] = 0x68581511;
ctx->state[6] = 0x64F98FA7;
ctx->state[7] = 0xBEFA4FA4;
}
ctx->is224 = is224;
} }
static void sha2_process( sha2_context *ctx, const unsigned char data[64] ) static void sha2_process( sha2_context *ctx, const unsigned char data[64] )
@ -306,19 +288,18 @@ void sha2_finish( sha2_context *ctx, unsigned char output[32] )
PUT_ULONG_BE( ctx->state[5], output, 20 ); PUT_ULONG_BE( ctx->state[5], output, 20 );
PUT_ULONG_BE( ctx->state[6], output, 24 ); PUT_ULONG_BE( ctx->state[6], output, 24 );
if( ctx->is224 == 0 ) PUT_ULONG_BE( ctx->state[7], output, 28 );
PUT_ULONG_BE( ctx->state[7], output, 28 );
} }
/* /*
* output = SHA-256( input buffer ) * output = SHA-256( input buffer )
*/ */
void sha2( const unsigned char *input, int ilen, void sha2( const unsigned char *input, int ilen,
unsigned char output[32], int is224 ) unsigned char output[32] )
{ {
sha2_context ctx; sha2_context ctx;
sha2_starts( &ctx, is224 ); sha2_starts( &ctx );
sha2_update( &ctx, input, ilen ); sha2_update( &ctx, input, ilen );
sha2_finish( &ctx, output ); sha2_finish( &ctx, output );

11
sha2.h

@ -39,7 +39,6 @@ typedef struct
unsigned char ipad[64]; /*!< HMAC: inner padding */ unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */ unsigned char opad[64]; /*!< HMAC: outer padding */
int is224; /*!< 0 => SHA-256, else SHA-224 */
} }
sha2_context; sha2_context;
@ -51,9 +50,8 @@ extern "C" {
* \brief SHA-256 context setup * \brief SHA-256 context setup
* *
* \param ctx context to be initialized * \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*/ */
void sha2_starts( sha2_context *ctx, int is224 ); void sha2_starts( sha2_context *ctx);
/** /**
* \brief SHA-256 process buffer * \brief SHA-256 process buffer
@ -68,7 +66,7 @@ void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen );
* \brief SHA-256 final digest * \brief SHA-256 final digest
* *
* \param ctx SHA-256 context * \param ctx SHA-256 context
* \param output SHA-224/256 checksum result * \param output SHA-256 checksum result
*/ */
void sha2_finish( sha2_context *ctx, unsigned char output[32] ); void sha2_finish( sha2_context *ctx, unsigned char output[32] );
@ -77,11 +75,10 @@ void sha2_finish( sha2_context *ctx, unsigned char output[32] );
* *
* \param input buffer holding the data * \param input buffer holding the data
* \param ilen length of the input data * \param ilen length of the input data
* \param output SHA-224/256 checksum result * \param output SHA-256 checksum result
* \param is224 0 = use SHA256, 1 = use SHA224
*/ */
void sha2( const unsigned char *input, int ilen, void sha2( const unsigned char *input, int ilen,
unsigned char output[32], int is224 ); unsigned char output[32]);
#ifdef __cplusplus #ifdef __cplusplus
} }

Loading…
Cancel
Save