0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-11 03:21:53 +00:00

SHA1: Use get_u32 and put_u32

This commit is contained in:
Pavel Tvrdík 2015-04-23 11:27:36 +02:00
parent dd78aae55c
commit 24ff638db2
2 changed files with 6 additions and 8 deletions

View File

@ -49,11 +49,9 @@ transform(sha1_context *hd, const byte *data)
#ifdef CPU_BIG_ENDIAN #ifdef CPU_BIG_ENDIAN
memcpy(x, data, 64); memcpy(x, data, 64);
#else #else
{ int i;
int i; for (i = 0; i < 16; i++)
for (i=0; i<16; i++) x[i] = get_u32(data+4*i);
x[i] = htonl(*((u32*)(data+4*i)));
}
#endif #endif
@ -263,7 +261,7 @@ sha1_final(sha1_context *hd)
transform(hd, hd->buf); transform(hd, hd->buf);
p = (u32*) 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(0);
X(1); X(1);
X(2); X(2);

View File

@ -21,7 +21,7 @@
#include <netinet/in.h> #include <netinet/in.h>
static inline u16 static inline u16
get_u16(void *p) get_u16(const void *p)
{ {
u16 x; u16 x;
memcpy(&x, p, 2); memcpy(&x, p, 2);
@ -29,7 +29,7 @@ get_u16(void *p)
} }
static inline u32 static inline u32
get_u32(void *p) get_u32(const void *p)
{ {
u32 x; u32 x;
memcpy(&x, p, 4); memcpy(&x, p, 4);