Skip to content

Commit

Permalink
fix: use C99 standard types instead of certain Unix types
Browse files Browse the repository at this point in the history
Signed-off-by: Chawye Hsu <chawyehsu@hotmail.com>
  • Loading branch information
chawyehsu committed Mar 30, 2021
1 parent 5b6c2b9 commit 63b5018
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
48 changes: 24 additions & 24 deletions rmd160/rmd160.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
initializes MDbuffer to "magic constants"
*/
static void
RMDinit (u_int32_t * MDbuf)
RMDinit (uint32_t * MDbuf)
{
MDbuf[0] = 0x67452301UL;
MDbuf[1] = 0xefcdab89UL;
Expand All @@ -107,11 +107,11 @@ RMDinit (u_int32_t * MDbuf)
transforms MDbuf using message bytes X[0] through X[15]
*/
static void
RMDcompress (u_int32_t * MDbuf, u_int32_t * X)
RMDcompress (uint32_t * MDbuf, uint32_t * X)
{
u_int32_t aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2],
uint32_t aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2],
dd = MDbuf[3], ee = MDbuf[4];
u_int32_t aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2],
uint32_t aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2],
ddd = MDbuf[3], eee = MDbuf[4];


Expand Down Expand Up @@ -312,29 +312,29 @@ RMDcompress (u_int32_t * MDbuf, u_int32_t * X)
note: there are (lswlen mod 64) bytes left in strptr.
*/
static void
RMDFinish (u_int32_t * MDbuf, u_int8_t * strptr, u_int32_t lswlen,
u_int32_t mswlen)
RMDFinish (uint32_t * MDbuf, uint8_t * strptr, uint32_t lswlen,
uint32_t mswlen)
{
u_int32_t i; /* counter */
u_int32_t X[16]; /* message words */
uint32_t i; /* counter */
uint32_t X[16]; /* message words */

memset (X, 0, 16 * sizeof (u_int32_t));
memset (X, 0, 16 * sizeof (uint32_t));

/* put bytes from strptr into X */
for (i = 0; i < (lswlen & 63); i++)
{
/* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */
X[i >> 2] ^= (u_int32_t) * strptr++ << (8 * (i & 3));
X[i >> 2] ^= (uint32_t) * strptr++ << (8 * (i & 3));
}

/* append the bit m_n == 1 */
X[(lswlen >> 2) & 15] ^= (u_int32_t) 1 << (8 * (lswlen & 3) + 7);
X[(lswlen >> 2) & 15] ^= (uint32_t) 1 << (8 * (lswlen & 3) + 7);

if ((lswlen & 63) > 55)
{
/* length goes to next block */
RMDcompress (MDbuf, X);
memset (X, 0, 16 * sizeof (u_int32_t));
memset (X, 0, 16 * sizeof (uint32_t));
}

/* append length in bits */
Expand All @@ -348,11 +348,11 @@ RMDFinish (u_int32_t * MDbuf, u_int8_t * strptr, u_int32_t lswlen,
RIPEMD-160 spec (which follows MD4 conventions).
*/
static void
rmd160ByteSwap (u_int32_t * dest, u_int8_t const *src, unsigned int words)
rmd160ByteSwap (uint32_t * dest, uint8_t const *src, unsigned int words)
{
do
{
*dest++ = (u_int32_t) ((unsigned) src[3] << 8 | src[2]) << 16 |
*dest++ = (uint32_t) ((unsigned) src[3] << 8 | src[2]) << 16 |
((unsigned) src[1] << 8 | src[0]);
src += 4;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ void RMD160Update(RMD160_CTX *ctx, const unsigned char *buf, unsigned int len)
unsigned i;

/* Update bitcount */
u_int32_t t = ctx->bytesLo;
uint32_t t = ctx->bytesLo;
if ((ctx->bytesLo = t + len) < t)
ctx->bytesHi++; /* Carry from low to high */

Expand All @@ -391,14 +391,14 @@ void RMD160Update(RMD160_CTX *ctx, const unsigned char *buf, unsigned int len)
/* i is always less than RIPEMD160_BLOCKBYTES. */
if (RIPEMD160_BLOCKBYTES - i > len)
{
memcpy ((u_int8_t *) ctx->key + i, buf, len);
memcpy ((uint8_t *) ctx->key + i, buf, len);
return;
}

if (i)
{ /* First chunk is an odd size */
memcpy ((u_int8_t *) ctx->key + i, buf, RIPEMD160_BLOCKBYTES - i);
rmd160ByteSwap (ctx->key, (u_int8_t *) ctx->key, RIPEMD160_BLOCKWORDS);
memcpy ((uint8_t *) ctx->key + i, buf, RIPEMD160_BLOCKBYTES - i);
rmd160ByteSwap (ctx->key, (uint8_t *) ctx->key, RIPEMD160_BLOCKWORDS);
RMDcompress (ctx->iv, ctx->key);
buf += RIPEMD160_BLOCKBYTES - i;
len -= RIPEMD160_BLOCKBYTES - i;
Expand Down Expand Up @@ -426,17 +426,17 @@ void
RMD160Final (unsigned char digest[20], RMD160_CTX * ctx)
{
int i;
u_int32_t t;
uint32_t t;

RMDFinish (ctx->iv, (u_int8_t *) ctx->key, ctx->bytesLo, ctx->bytesHi);
RMDFinish (ctx->iv, (uint8_t *) ctx->key, ctx->bytesLo, ctx->bytesHi);

for (i = 0; i < RIPEMD160_HASHWORDS; i++)
{
t = ctx->iv[i];
digest[i * 4 + 0] = (u_int8_t) t;
digest[i * 4 + 1] = (u_int8_t) (t >> 8);
digest[i * 4 + 2] = (u_int8_t) (t >> 16);
digest[i * 4 + 3] = (u_int8_t) (t >> 24);
digest[i * 4 + 0] = (uint8_t) t;
digest[i * 4 + 1] = (uint8_t) (t >> 8);
digest[i * 4 + 2] = (uint8_t) (t >> 16);
digest[i * 4 + 3] = (uint8_t) (t >> 24);
}

memset (ctx, 0, sizeof (RMD160_CTX)); /* In case it's sensitive */
Expand Down
7 changes: 4 additions & 3 deletions rmd160/rmd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef _RMD160_H_
#define _RMD160_H_

#include <stdint.h>
#include <sys/types.h>

#define RMD160_BLOCKBYTES 64
Expand All @@ -20,9 +21,9 @@

/* RIPEMD160 context. */
typedef struct RMD160Context {
u_int32_t key[RIPEMD160_BLOCKWORDS];
u_int32_t iv[RIPEMD160_HASHWORDS];
u_int32_t bytesHi, bytesLo;
uint32_t key[RIPEMD160_BLOCKWORDS];
uint32_t iv[RIPEMD160_HASHWORDS];
uint32_t bytesHi, bytesLo;
} RMD160_CTX;

#define RIPEMD160Context RMD160Context
Expand Down

0 comments on commit 63b5018

Please sign in to comment.