Imported Upstream version 0.7.19
[platform/upstream/libsolv.git] / src / sha1.c
index 74262a9..668331f 100644 (file)
@@ -78,7 +78,6 @@ A million repetitions of "a"
 
 #include <stdio.h>
 #include <string.h>
-#include <endian.h>
 #include "sha1.h"
 
 
@@ -89,14 +88,14 @@ static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
 /* blk0() and blk() perform the initial expand. */
 /* I got the idea of expanding during the round function from SSLeay */
 /* FIXME: can we do this in an endian-proof way? */
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define blk0(i) block->l[i]
+#ifdef WORDS_BIGENDIAN
+#define blk0(i) block.l[i]
 #else
-#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
-    |(rol(block->l[i],8)&0x00FF00FF))
+#define blk0(i) (block.l[i] = (rol(block.l[i],24)&0xFF00FF00) \
+    |(rol(block.l[i],8)&0x00FF00FF))
 #endif
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
-    ^block->l[(i+2)&15]^block->l[i&15],1))
+#define blk(i) (block.l[i&15] = rol(block.l[(i+13)&15]^block.l[(i+8)&15] \
+    ^block.l[(i+2)&15]^block.l[i&15],1))
 
 /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
 #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
@@ -114,9 +113,9 @@ static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
         uint8_t c[64];
         uint32_t l[16];
     } CHAR64LONG16;
-    CHAR64LONG16* block;
+    CHAR64LONG16 block;
 
-    block = (CHAR64LONG16*)buffer;
+    memcpy(&block, buffer, 64);
 
     /* Copy context->state[] to working vars */
     a = state[0];
@@ -160,7 +159,7 @@ static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
 
 
 /* SHA1Init - Initialize new context */
-void sat_SHA1_Init(SHA1_CTX* context)
+void solv_SHA1_Init(SHA1_CTX* context)
 {
     /* SHA1 initialization constants */
     context->state[0] = 0x67452301;
@@ -173,7 +172,7 @@ void sat_SHA1_Init(SHA1_CTX* context)
 
 
 /* Run your data through this. */
-void sat_SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
+void solv_SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
 {
     size_t i, j;
 
@@ -202,7 +201,7 @@ void sat_SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
 
 
 /* Add padding and return the message digest. */
-void sat_SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE])
+void solv_SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE])
 {
     uint32_t i;
     uint8_t  finalcount[8];
@@ -211,11 +210,11 @@ void sat_SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE])
         finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
          >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
     }
-    sat_SHA1_Update(context, (uint8_t *)"\200", 1);
+    solv_SHA1_Update(context, (uint8_t *)"\200", 1);
     while ((context->count[0] & 504) != 448) {
-        sat_SHA1_Update(context, (uint8_t *)"\0", 1);
+        solv_SHA1_Update(context, (uint8_t *)"\0", 1);
     }
-    sat_SHA1_Update(context, finalcount, 8);  /* Should cause a SHA1_Transform() */
+    solv_SHA1_Update(context, finalcount, 8);  /* Should cause a SHA1_Transform() */
     for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
         digest[i] = (uint8_t)
          ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);