Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
extract block size and digest size as macros in ripemd160
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Nov 1, 2016
1 parent f4e4c29 commit a91e005
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions ripemd160.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void ripemd160_Init(RIPEMD160_CTX *ctx)
/*
* Process one block
*/
void ripemd160_process( RIPEMD160_CTX *ctx, const uint8_t data[64] )
void ripemd160_process( RIPEMD160_CTX *ctx, const uint8_t data[RIPEMD160_BLOCK_LENGTH] )
{
uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];

Expand Down Expand Up @@ -260,7 +260,7 @@ void ripemd160_Update( RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen )
return;

left = ctx->total[0] & 0x3F;
fill = 64 - left;
fill = RIPEMD160_BLOCK_LENGTH - left;

ctx->total[0] += (uint32_t) ilen;
ctx->total[0] &= 0xFFFFFFFF;
Expand All @@ -277,11 +277,11 @@ void ripemd160_Update( RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen )
left = 0;
}

while( ilen >= 64 )
while( ilen >= RIPEMD160_BLOCK_LENGTH )
{
ripemd160_process( ctx, input );
input += 64;
ilen -= 64;
input += RIPEMD160_BLOCK_LENGTH;
ilen -= RIPEMD160_BLOCK_LENGTH;
}

if( ilen > 0 )
Expand All @@ -290,7 +290,7 @@ void ripemd160_Update( RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen )
}
}

static const uint8_t ripemd160_padding[64] =
static const uint8_t ripemd160_padding[RIPEMD160_BLOCK_LENGTH] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand All @@ -301,7 +301,7 @@ static const uint8_t ripemd160_padding[64] =
/*
* RIPEMD-160 final digest
*/
void ripemd160_Final( RIPEMD160_CTX *ctx, uint8_t output[20] )
void ripemd160_Final( RIPEMD160_CTX *ctx, uint8_t output[RIPEMD160_DIGEST_LENGTH] )
{
uint32_t last, padn;
uint32_t high, low;
Expand Down Expand Up @@ -330,7 +330,7 @@ void ripemd160_Final( RIPEMD160_CTX *ctx, uint8_t output[20] )
/*
* output = RIPEMD-160( input buffer )
*/
void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[20])
void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[RIPEMD160_DIGEST_LENGTH])
{
RIPEMD160_CTX ctx;
ripemd160_Init( &ctx );
Expand Down
9 changes: 6 additions & 3 deletions ripemd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

#include <stdint.h>

#define RIPEMD160_BLOCK_LENGTH 64
#define RIPEMD160_DIGEST_LENGTH 20

typedef struct _RIPEMD160_CTX {
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[5]; /*!< intermediate digest state */
uint8_t buffer[64]; /*!< data block being processed */
uint8_t buffer[RIPEMD160_BLOCK_LENGTH]; /*!< data block being processed */
} RIPEMD160_CTX;

void ripemd160_Init(RIPEMD160_CTX *ctx);
void ripemd160_Update(RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen);
void ripemd160_Final(RIPEMD160_CTX *ctx, uint8_t output[20]);
void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[20]);
void ripemd160_Final(RIPEMD160_CTX *ctx, uint8_t output[RIPEMD160_DIGEST_LENGTH]);
void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[RIPEMD160_DIGEST_LENGTH]);

#endif

0 comments on commit a91e005

Please sign in to comment.