@@ -64,13 +64,13 @@ static int ltc_attribute_sha1 s_sha1_x86_compress(hash_state *md, const unsigned
6464
6565 LTC_ARGCHK (md != NULL );
6666 LTC_ARGCHK (buf != NULL );
67- LTC_ARGCHK (((uintptr_t )(& md -> sha1_x86 .state [0 ])) % 16 == 0 );
67+ LTC_ARGCHK (((uintptr_t )(& md -> sha1 .state [0 ])) % 16 == 0 );
6868 LTC_ARGCHK (sizeof (int ) == 4 );
6969
7070 reverse_8 = _mm_set_epi64x (0x0001020304050607ull , 0x08090a0b0c0d0e0full );
71- abcdx = _mm_load_si128 (((__m128i const * )(& md -> sha1_x86 .state [0 ])));
71+ abcdx = _mm_load_si128 (((__m128i const * )(& md -> sha1 .state [0 ])));
7272 abcdx = _mm_shuffle_epi32 (abcdx , k_reverse_32 );
73- e = _mm_set_epi32 (* ((int const * )(& md -> sha1_x86 .state [4 ])), 0 , 0 , 0 );
73+ e = _mm_set_epi32 (* ((int const * )(& md -> sha1 .state [4 ])), 0 , 0 , 0 );
7474
7575 old_abcd = abcdx ;
7676 old_e = e ;
@@ -176,8 +176,8 @@ static int ltc_attribute_sha1 s_sha1_x86_compress(hash_state *md, const unsigned
176176 e = _mm_add_epi32 (e , old_e );
177177
178178 abcdx = _mm_shuffle_epi32 (abcdx , k_reverse_32 );
179- _mm_store_si128 (((__m128i * )(& md -> sha1_x86 .state [0 ])), abcdx );
180- * ((int * )(& md -> sha1_x86 .state [4 ])) = _mm_extract_epi32 (e , 3 );
179+ _mm_store_si128 (((__m128i * )(& md -> sha1 .state [0 ])), abcdx );
180+ * ((int * )(& md -> sha1 .state [4 ])) = _mm_extract_epi32 (e , 3 );
181181
182182 return CRYPT_OK ;
183183
@@ -202,13 +202,16 @@ static int s_sha1_x86_compress(hash_state *md, const unsigned char *buf)
202202int sha1_x86_init (hash_state * md )
203203{
204204 LTC_ARGCHK (md != NULL );
205- md -> sha1_x86 .state [0 ] = 0x67452301UL ;
206- md -> sha1_x86 .state [1 ] = 0xefcdab89UL ;
207- md -> sha1_x86 .state [2 ] = 0x98badcfeUL ;
208- md -> sha1_x86 .state [3 ] = 0x10325476UL ;
209- md -> sha1_x86 .state [4 ] = 0xc3d2e1f0UL ;
210- md -> sha1_x86 .curlen = 0 ;
211- md -> sha1_x86 .length = 0 ;
205+
206+ md -> sha1 .state = LTC_ALIGN_BUF (md -> sha1 .state_buf , 16 );
207+
208+ md -> sha1 .state [0 ] = 0x67452301UL ;
209+ md -> sha1 .state [1 ] = 0xefcdab89UL ;
210+ md -> sha1 .state [2 ] = 0x98badcfeUL ;
211+ md -> sha1 .state [3 ] = 0x10325476UL ;
212+ md -> sha1 .state [4 ] = 0xc3d2e1f0UL ;
213+ md -> sha1 .curlen = 0 ;
214+ md -> sha1 .length = 0 ;
212215 return CRYPT_OK ;
213216}
214217
@@ -219,7 +222,7 @@ int sha1_x86_init(hash_state * md)
219222 @param inlen The length of the data (octets)
220223 @return CRYPT_OK if successful
221224*/
222- HASH_PROCESS (sha1_x86_process , s_sha1_x86_compress , sha1_x86 , 64 )
225+ HASH_PROCESS (sha1_x86_process , s_sha1_x86_compress , sha1 , 64 )
223226
224227/**
225228 Terminate the hash to get the digest
@@ -234,40 +237,40 @@ int sha1_x86_done(hash_state * md, unsigned char *out)
234237 LTC_ARGCHK (md != NULL );
235238 LTC_ARGCHK (out != NULL );
236239
237- if (md -> sha1_x86 .curlen >= ((int )(sizeof (md -> sha1_x86 .buf )))) {
240+ if (md -> sha1 .curlen >= ((int )(sizeof (md -> sha1 .buf )))) {
238241 return CRYPT_INVALID_ARG ;
239242 }
240243
241244 /* increase the length of the message */
242- md -> sha1_x86 .length += md -> sha1_x86 .curlen * 8 ;
245+ md -> sha1 .length += md -> sha1 .curlen * 8 ;
243246
244247 /* append the '1' bit */
245- md -> sha1_x86 .buf [md -> sha1_x86 .curlen ++ ] = (unsigned char )0x80 ;
248+ md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0x80 ;
246249
247250 /* if the length is currently above 56 bytes we append zeros
248251 * then compress. Then we can fall back to padding zeros and length
249252 * encoding like normal.
250253 */
251- if (md -> sha1_x86 .curlen > 56 ) {
252- while (md -> sha1_x86 .curlen < 64 ) {
253- md -> sha1_x86 .buf [md -> sha1_x86 .curlen ++ ] = (unsigned char )0 ;
254+ if (md -> sha1 .curlen > 56 ) {
255+ while (md -> sha1 .curlen < 64 ) {
256+ md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0 ;
254257 }
255- s_sha1_x86_compress (md , md -> sha1_x86 .buf );
256- md -> sha1_x86 .curlen = 0 ;
258+ s_sha1_x86_compress (md , md -> sha1 .buf );
259+ md -> sha1 .curlen = 0 ;
257260 }
258261
259262 /* pad upto 56 bytes of zeroes */
260- while (md -> sha1_x86 .curlen < 56 ) {
261- md -> sha1_x86 .buf [md -> sha1_x86 .curlen ++ ] = (unsigned char )0 ;
263+ while (md -> sha1 .curlen < 56 ) {
264+ md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0 ;
262265 }
263266
264267 /* store length */
265- STORE64H (md -> sha1_x86 .length , md -> sha1_x86 .buf + 56 );
266- s_sha1_x86_compress (md , md -> sha1_x86 .buf );
268+ STORE64H (md -> sha1 .length , md -> sha1 .buf + 56 );
269+ s_sha1_x86_compress (md , md -> sha1 .buf );
267270
268271 /* copy output */
269272 for (i = 0 ; i < 5 ; i ++ ) {
270- STORE32H (md -> sha1_x86 .state [i ], out + (4 * i ));
273+ STORE32H (md -> sha1 .state [i ], out + (4 * i ));
271274 }
272275#ifdef LTC_CLEAN_STACK
273276 zeromem (md , sizeof (hash_state ));
0 commit comments