summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/sha2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/sha2.c')
-rw-r--r--lib/libalpm/sha2.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/lib/libalpm/sha2.c b/lib/libalpm/sha2.c
index 3632c131..366dc650 100644
--- a/lib/libalpm/sha2.c
+++ b/lib/libalpm/sha2.c
@@ -38,28 +38,29 @@
* * removal of SELF_TEST code
* * removal of ipad and opad from the sha2_context struct in sha2.h
* * increase the size of buffer for performance reasons
- * * various static changes
+ * * change 'unsigned long' to uint32_t
*/
#include <stdio.h>
+#include <stdint.h>
#include "sha2.h"
/*
* 32-bit integer manipulation macros (big endian)
*/
-#ifndef GET_ULONG_BE
-#define GET_ULONG_BE(n,b,i) \
+#ifndef GET_U32_BE
+#define GET_U32_BE(n,b,i) \
{ \
- (n) = ( (unsigned long) (b)[(i) ] << 24 ) \
- | ( (unsigned long) (b)[(i) + 1] << 16 ) \
- | ( (unsigned long) (b)[(i) + 2] << 8 ) \
- | ( (unsigned long) (b)[(i) + 3] ); \
+ (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
+ | ( (uint32_t) (b)[(i) + 1] << 16 ) \
+ | ( (uint32_t) (b)[(i) + 2] << 8 ) \
+ | ( (uint32_t) (b)[(i) + 3] ); \
}
#endif
-#ifndef PUT_ULONG_BE
-#define PUT_ULONG_BE(n,b,i) \
+#ifndef PUT_U32_BE
+#define PUT_U32_BE(n,b,i) \
{ \
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
@@ -106,25 +107,25 @@ static void sha2_starts( sha2_context *ctx, int is224 )
static void sha2_process( sha2_context *ctx, const unsigned char data[64] )
{
- unsigned long temp1, temp2, W[64];
- unsigned long A, B, C, D, E, F, G, H;
-
- GET_ULONG_BE( W[ 0], data, 0 );
- GET_ULONG_BE( W[ 1], data, 4 );
- GET_ULONG_BE( W[ 2], data, 8 );
- GET_ULONG_BE( W[ 3], data, 12 );
- GET_ULONG_BE( W[ 4], data, 16 );
- GET_ULONG_BE( W[ 5], data, 20 );
- GET_ULONG_BE( W[ 6], data, 24 );
- GET_ULONG_BE( W[ 7], data, 28 );
- GET_ULONG_BE( W[ 8], data, 32 );
- GET_ULONG_BE( W[ 9], data, 36 );
- GET_ULONG_BE( W[10], data, 40 );
- GET_ULONG_BE( W[11], data, 44 );
- GET_ULONG_BE( W[12], data, 48 );
- GET_ULONG_BE( W[13], data, 52 );
- GET_ULONG_BE( W[14], data, 56 );
- GET_ULONG_BE( W[15], data, 60 );
+ uint32_t temp1, temp2, W[64];
+ uint32_t A, B, C, D, E, F, G, H;
+
+ GET_U32_BE( W[ 0], data, 0 );
+ GET_U32_BE( W[ 1], data, 4 );
+ GET_U32_BE( W[ 2], data, 8 );
+ GET_U32_BE( W[ 3], data, 12 );
+ GET_U32_BE( W[ 4], data, 16 );
+ GET_U32_BE( W[ 5], data, 20 );
+ GET_U32_BE( W[ 6], data, 24 );
+ GET_U32_BE( W[ 7], data, 28 );
+ GET_U32_BE( W[ 8], data, 32 );
+ GET_U32_BE( W[ 9], data, 36 );
+ GET_U32_BE( W[10], data, 40 );
+ GET_U32_BE( W[11], data, 44 );
+ GET_U32_BE( W[12], data, 48 );
+ GET_U32_BE( W[13], data, 52 );
+ GET_U32_BE( W[14], data, 56 );
+ GET_U32_BE( W[15], data, 60 );
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
@@ -241,7 +242,7 @@ static void sha2_process( sha2_context *ctx, const unsigned char data[64] )
static void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen )
{
size_t fill;
- unsigned long left;
+ uint32_t left;
if( ilen <= 0 )
return;
@@ -249,10 +250,10 @@ static void sha2_update( sha2_context *ctx, const unsigned char *input, size_t i
left = ctx->total[0] & 0x3F;
fill = 64 - left;
- ctx->total[0] += (unsigned long) ilen;
+ ctx->total[0] += (uint32_t) ilen;
ctx->total[0] &= 0xFFFFFFFF;
- if( ctx->total[0] < (unsigned long) ilen )
+ if( ctx->total[0] < (uint32_t) ilen )
ctx->total[1]++;
if( left && ilen >= fill )
@@ -292,16 +293,16 @@ static const unsigned char sha2_padding[64] =
*/
static void sha2_finish( sha2_context *ctx, unsigned char output[32] )
{
- unsigned long last, padn;
- unsigned long high, low;
+ uint32_t last, padn;
+ uint32_t high, low;
unsigned char msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 );
- PUT_ULONG_BE( high, msglen, 0 );
- PUT_ULONG_BE( low, msglen, 4 );
+ PUT_U32_BE( high, msglen, 0 );
+ PUT_U32_BE( low, msglen, 4 );
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
@@ -309,16 +310,16 @@ static void sha2_finish( sha2_context *ctx, unsigned char output[32] )
sha2_update( ctx, (unsigned char *) sha2_padding, padn );
sha2_update( ctx, msglen, 8 );
- PUT_ULONG_BE( ctx->state[0], output, 0 );
- PUT_ULONG_BE( ctx->state[1], output, 4 );
- PUT_ULONG_BE( ctx->state[2], output, 8 );
- PUT_ULONG_BE( ctx->state[3], output, 12 );
- PUT_ULONG_BE( ctx->state[4], output, 16 );
- PUT_ULONG_BE( ctx->state[5], output, 20 );
- PUT_ULONG_BE( ctx->state[6], output, 24 );
+ PUT_U32_BE( ctx->state[0], output, 0 );
+ PUT_U32_BE( ctx->state[1], output, 4 );
+ PUT_U32_BE( ctx->state[2], output, 8 );
+ PUT_U32_BE( ctx->state[3], output, 12 );
+ PUT_U32_BE( ctx->state[4], output, 16 );
+ PUT_U32_BE( ctx->state[5], output, 20 );
+ PUT_U32_BE( ctx->state[6], output, 24 );
if( ctx->is224 == 0 )
- PUT_ULONG_BE( ctx->state[7], output, 28 );
+ PUT_U32_BE( ctx->state[7], output, 28 );
}
/*