Package: tla / 1.3.5+dfsg1-2

0002-Fixes-alignment-errors-on-hppa-and-sparc.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
From: Martín Ferrari <martin.ferrari@gmail.com>
Date: Mon, 28 Aug 2006 07:06:06 +0200
Subject: Fixes alignment errors on hppa and sparc.

Bug-Debian: http://bugs.debian.org/382465
---
 src/hackerlab/hash/sha1.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/hackerlab/hash/sha1.c b/src/hackerlab/hash/sha1.c
index 47a7352..00556d4 100644
--- a/src/hackerlab/hash/sha1.c
+++ b/src/hackerlab/hash/sha1.c
@@ -39,11 +39,11 @@ struct sha1_context
 
   t_uint32 total[2];
   t_uint32 buflen;
-  t_uchar buffer[128];
+  t_uchar buffer[128] __attribute__((aligned(4)));
 };
 
 static void
-sha1_process_blocks (const void *buffer, size_t len, sha1_context_t ctx);
+sha1_process_blocks (const t_uchar *buffer, size_t len, sha1_context_t ctx);
 
 #if MACHINE_IS_BIGENDIAN
 # define NOTSWAP(n) (n)
@@ -124,7 +124,7 @@ sha1_scan (sha1_context_t ctx, const t_uchar *buffer, size_t len)
 {
   /* When we already have some bits in our internal buffer concatenate
      both inputs first.  */
-  if (ctx->buflen != 0)
+  while (len > 0)
     {
       size_t left_over = ctx->buflen;
       size_t add = 128 - left_over > len ? len : 128 - left_over;
@@ -147,14 +147,17 @@ sha1_scan (sha1_context_t ctx, const t_uchar *buffer, size_t len)
     }
 
   /* Process available complete blocks.  */
+  /*
   if (len >= 64)
     {
       sha1_process_blocks (buffer, len & ~63, ctx);
       buffer = (const t_uchar *) buffer + (len & ~63);
       len &= 63;
     }
+  */
 
   /* Move remaining bytes in internal buffer.  */
+  /*
   if (len > 0)
     {
       size_t left_over = ctx->buflen;
@@ -169,6 +172,7 @@ sha1_scan (sha1_context_t ctx, const t_uchar *buffer, size_t len)
 	}
       ctx->buflen = left_over;
     }
+  */
 }
 
 
@@ -191,6 +195,8 @@ sha1_final (t_uchar *result, sha1_context_t ctx)
   /* Take yet unprocessed bytes into account.  */
   t_uint32 bytes = ctx->buflen;
   size_t pad;
+  /* Temporary array for solving alignment issues */
+  t_uint32 tmp[5];
 
   /* Now count remaining bytes.  */
   ctx->total[0] += bytes;
@@ -208,11 +214,12 @@ sha1_final (t_uchar *result, sha1_context_t ctx)
   /* Process last bytes.  */
   sha1_process_blocks (ctx->buffer, bytes + pad + 8, ctx);
 
-  ((t_uint32 *) result)[0] = NOTSWAP (ctx->current_sha1.A);
-  ((t_uint32 *) result)[1] = NOTSWAP (ctx->current_sha1.B);
-  ((t_uint32 *) result)[2] = NOTSWAP (ctx->current_sha1.C);
-  ((t_uint32 *) result)[3] = NOTSWAP (ctx->current_sha1.D);
-  ((t_uint32 *) result)[4] = NOTSWAP (ctx->current_sha1.E);
+  tmp[0] = NOTSWAP (ctx->current_sha1.A);
+  tmp[1] = NOTSWAP (ctx->current_sha1.B);
+  tmp[2] = NOTSWAP (ctx->current_sha1.C);
+  tmp[3] = NOTSWAP (ctx->current_sha1.D);
+  tmp[4] = NOTSWAP (ctx->current_sha1.E);
+  mem_cpy (result, tmp, 20);
   
   sha1_context_reset (ctx);
 }
@@ -329,7 +336,7 @@ sha1_from_ascii (sha1_t * out, t_uchar const * ascii)
    It is assumed that LEN % 64 == 0.
    Most of this code comes from GnuPG's cipher/sha1.c.  */
 static void
-sha1_process_blocks (const void *buffer, size_t len, sha1_context_t ctx)
+sha1_process_blocks (const t_uchar *buffer, size_t len, sha1_context_t ctx)
 {
   const t_uint32 *words = buffer;
   size_t nwords = len / sizeof (t_uint32);