]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
SHA1: Use get_u32 and put_u32
authorPavel Tvrdík <pawel.tvrdik@gmail.cz>
Thu, 23 Apr 2015 09:27:36 +0000 (11:27 +0200)
committerPavel Tvrdík <pawel.tvrdik@gmail.cz>
Thu, 23 Apr 2015 09:27:36 +0000 (11:27 +0200)
lib/sha1.c
lib/unaligned.h

index f2b55f583577222fa95e0d9ee7dda1b47f33003c..2e2211199c6035922c819fac056377dc2b426c1c 100644 (file)
@@ -49,11 +49,9 @@ transform(sha1_context *hd, const byte *data)
 #ifdef CPU_BIG_ENDIAN
   memcpy(x, data, 64);
 #else
-  {
-    int i;
-    for (i=0; i<16; i++)
-      x[i] = htonl(*((u32*)(data+4*i)));
-  }
+  int i;
+  for (i = 0; i < 16; i++)
+    x[i] = get_u32(data+4*i);
 #endif
 
 
@@ -263,7 +261,7 @@ sha1_final(sha1_context *hd)
   transform(hd, hd->buf);
 
   p = (u32*) hd->buf;
-#define X(a) do { *(p++) = ntohl(hd->h##a); } while(0)
+#define X(a) do { put_u32(p, hd->h##a); p++; } while(0)
   X(0);
   X(1);
   X(2);
index e1d61aa08932b12465b29436dcfb68d938bf48f3..73fe2d8a83a40daa3216d492feece3c9398fc65a 100644 (file)
@@ -21,7 +21,7 @@
 #include <netinet/in.h>
 
 static inline u16
-get_u16(void *p)
+get_u16(const void *p)
 {
   u16 x;
   memcpy(&x, p, 2);
@@ -29,7 +29,7 @@ get_u16(void *p)
 }
 
 static inline u32
-get_u32(void *p)
+get_u32(const void *p)
 {
   u32 x;
   memcpy(&x, p, 4);