Просмотр исходного кода

Fix alignment errors in sha1.inl

bel 8 лет назад
Родитель
Сommit
69fc50d794
1 измененных файлов с 7 добавлено и 2 удалено
  1. 7 2
      src/sha1.inl

+ 7 - 2
src/sha1.inl

@@ -72,6 +72,7 @@ move public api to sha1.h
   rename to sha1.inl
   remove unused #ifdef sections
   make endian independent
+  align buffer to 4 bytes
 */
 
 /*
@@ -152,7 +153,11 @@ SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
 	uint32_t a, b, c, d, e;
 	CHAR64LONG16 *block;
 
-	block = (CHAR64LONG16 *)buffer;
+	/* Must use an aligned buffer */
+	CHAR64LONG16 aligned_buf;
+	memcpy(&aligned_buf, &buffer, sizeof(aligned_buf));
+
+	block = &aligned_buf;
 
 	/* Copy context->state[] to working vars */
 	a = state[0];
@@ -271,7 +276,7 @@ SHA1_Init(SHA1_CTX *context)
 
 /* Run your data through this. */
 SHA_API void
-SHA1_Update(SHA1_CTX *context, const uint8_t *data, const size_t len)
+SHA1_Update(SHA1_CTX *context, const uint8_t *data, const uint32_t len)
 {
 	size_t i, j;