1818#define LTC_SMALL_STACK_SHA1
1919#endif
2020
21- const struct ltc_hash_descriptor sha1_desc =
21+ const struct ltc_hash_descriptor sha1_portable_desc =
2222{
23- "sha1 " ,
23+ "sha1_portable " ,
2424 2 ,
2525 20 ,
2626 64 ,
@@ -29,10 +29,10 @@ const struct ltc_hash_descriptor sha1_desc =
2929 { 1 , 3 , 14 , 3 , 2 , 26 , },
3030 6 ,
3131
32- & sha1_init ,
33- & sha1_process ,
34- & sha1_done ,
35- & sha1_test ,
32+ & sha1_c_init ,
33+ & sha1_c_process ,
34+ & sha1_c_done ,
35+ & sha1_c_test ,
3636 NULL
3737};
3838
@@ -42,9 +42,9 @@ const struct ltc_hash_descriptor sha1_desc =
4242#define F3 (x ,y ,z ) (x ^ y ^ z)
4343
4444#ifdef LTC_CLEAN_STACK
45- static int ss_sha1_compress (hash_state * md , const unsigned char * buf )
45+ static int ss_sha1_c_compress (hash_state * md , const unsigned char * buf )
4646#else
47- static int s_sha1_compress (hash_state * md , const unsigned char * buf )
47+ static int s_sha1_c_compress (hash_state * md , const unsigned char * buf )
4848#endif
4949{
5050 ulong32 a ,b ,c ,d ,e ,i ;
@@ -63,11 +63,11 @@ static int s_sha1_compress(hash_state *md, const unsigned char *buf)
6363 }
6464
6565 /* copy state */
66- a = md -> sha1 .state [0 ];
67- b = md -> sha1 .state [1 ];
68- c = md -> sha1 .state [2 ];
69- d = md -> sha1 .state [3 ];
70- e = md -> sha1 .state [4 ];
66+ a = md -> sha1_c .state [0 ];
67+ b = md -> sha1_c .state [1 ];
68+ c = md -> sha1_c .state [2 ];
69+ d = md -> sha1_c .state [3 ];
70+ e = md -> sha1_c .state [4 ];
7171
7272#ifdef LTC_SMALL_STACK_SHA1
7373 #define Wi (i ) do { W[(i) % 16] = ROL(W[((i) - 3) % 16] ^ W[((i) - 8) % 16] ^ W[((i) - 14) % 16] ^ W[((i) - 16) % 16], 1); } while(0)
@@ -160,20 +160,20 @@ static int s_sha1_compress(hash_state *md, const unsigned char *buf)
160160 #undef Windex
161161
162162 /* store */
163- md -> sha1 .state [0 ] = md -> sha1 .state [0 ] + a ;
164- md -> sha1 .state [1 ] = md -> sha1 .state [1 ] + b ;
165- md -> sha1 .state [2 ] = md -> sha1 .state [2 ] + c ;
166- md -> sha1 .state [3 ] = md -> sha1 .state [3 ] + d ;
167- md -> sha1 .state [4 ] = md -> sha1 .state [4 ] + e ;
163+ md -> sha1_c .state [0 ] = md -> sha1_c .state [0 ] + a ;
164+ md -> sha1_c .state [1 ] = md -> sha1_c .state [1 ] + b ;
165+ md -> sha1_c .state [2 ] = md -> sha1_c .state [2 ] + c ;
166+ md -> sha1_c .state [3 ] = md -> sha1_c .state [3 ] + d ;
167+ md -> sha1_c .state [4 ] = md -> sha1_c .state [4 ] + e ;
168168
169169 return CRYPT_OK ;
170170}
171171
172172#ifdef LTC_CLEAN_STACK
173- static int s_sha1_compress (hash_state * md , const unsigned char * buf )
173+ static int s_sha1_c_compress (hash_state * md , const unsigned char * buf )
174174{
175175 int err ;
176- err = ss_sha1_compress (md , buf );
176+ err = ss_sha1_c_compress (md , buf );
177177 burn_stack (sizeof (ulong32 ) * 87 );
178178 return err ;
179179}
@@ -184,16 +184,16 @@ static int s_sha1_compress(hash_state *md, const unsigned char *buf)
184184 @param md The hash state you wish to initialize
185185 @return CRYPT_OK if successful
186186*/
187- int sha1_init (hash_state * md )
187+ int sha1_c_init (hash_state * md )
188188{
189189 LTC_ARGCHK (md != NULL );
190- md -> sha1 .state [0 ] = 0x67452301UL ;
191- md -> sha1 .state [1 ] = 0xefcdab89UL ;
192- md -> sha1 .state [2 ] = 0x98badcfeUL ;
193- md -> sha1 .state [3 ] = 0x10325476UL ;
194- md -> sha1 .state [4 ] = 0xc3d2e1f0UL ;
195- md -> sha1 .curlen = 0 ;
196- md -> sha1 .length = 0 ;
190+ md -> sha1_c .state [0 ] = 0x67452301UL ;
191+ md -> sha1_c .state [1 ] = 0xefcdab89UL ;
192+ md -> sha1_c .state [2 ] = 0x98badcfeUL ;
193+ md -> sha1_c .state [3 ] = 0x10325476UL ;
194+ md -> sha1_c .state [4 ] = 0xc3d2e1f0UL ;
195+ md -> sha1_c .curlen = 0 ;
196+ md -> sha1_c .length = 0 ;
197197 return CRYPT_OK ;
198198}
199199
@@ -204,55 +204,55 @@ int sha1_init(hash_state * md)
204204 @param inlen The length of the data (octets)
205205 @return CRYPT_OK if successful
206206*/
207- HASH_PROCESS (sha1_process , s_sha1_compress , sha1 , 64 )
207+ HASH_PROCESS (sha1_c_process , s_sha1_c_compress , sha1_c , 64 )
208208
209209/**
210210 Terminate the hash to get the digest
211211 @param md The hash state
212212 @param out [out] The destination of the hash (20 bytes)
213213 @return CRYPT_OK if successful
214214*/
215- int sha1_done (hash_state * md , unsigned char * out )
215+ int sha1_c_done (hash_state * md , unsigned char * out )
216216{
217217 int i ;
218218
219219 LTC_ARGCHK (md != NULL );
220220 LTC_ARGCHK (out != NULL );
221221
222- if (md -> sha1 .curlen >= sizeof (md -> sha1 .buf )) {
222+ if (md -> sha1_c .curlen >= sizeof (md -> sha1_c .buf )) {
223223 return CRYPT_INVALID_ARG ;
224224 }
225225
226226 /* increase the length of the message */
227- md -> sha1 .length += md -> sha1 .curlen * 8 ;
227+ md -> sha1_c .length += md -> sha1_c .curlen * 8 ;
228228
229229 /* append the '1' bit */
230- md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0x80 ;
230+ md -> sha1_c .buf [md -> sha1_c .curlen ++ ] = (unsigned char )0x80 ;
231231
232232 /* if the length is currently above 56 bytes we append zeros
233233 * then compress. Then we can fall back to padding zeros and length
234234 * encoding like normal.
235235 */
236- if (md -> sha1 .curlen > 56 ) {
237- while (md -> sha1 .curlen < 64 ) {
238- md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0 ;
236+ if (md -> sha1_c .curlen > 56 ) {
237+ while (md -> sha1_c .curlen < 64 ) {
238+ md -> sha1_c .buf [md -> sha1_c .curlen ++ ] = (unsigned char )0 ;
239239 }
240- s_sha1_compress (md , md -> sha1 .buf );
241- md -> sha1 .curlen = 0 ;
240+ s_sha1_c_compress (md , md -> sha1_c .buf );
241+ md -> sha1_c .curlen = 0 ;
242242 }
243243
244244 /* pad upto 56 bytes of zeroes */
245- while (md -> sha1 .curlen < 56 ) {
246- md -> sha1 .buf [md -> sha1 .curlen ++ ] = (unsigned char )0 ;
245+ while (md -> sha1_c .curlen < 56 ) {
246+ md -> sha1_c .buf [md -> sha1_c .curlen ++ ] = (unsigned char )0 ;
247247 }
248248
249249 /* store length */
250- STORE64H (md -> sha1 .length , md -> sha1 .buf + 56 );
251- s_sha1_compress (md , md -> sha1 .buf );
250+ STORE64H (md -> sha1_c .length , md -> sha1_c .buf + 56 );
251+ s_sha1_c_compress (md , md -> sha1_c .buf );
252252
253253 /* copy output */
254254 for (i = 0 ; i < 5 ; i ++ ) {
255- STORE32H (md -> sha1 .state [i ], out + (4 * i ));
255+ STORE32H (md -> sha1_c .state [i ], out + (4 * i ));
256256 }
257257#ifdef LTC_CLEAN_STACK
258258 zeromem (md , sizeof (hash_state ));
@@ -264,7 +264,7 @@ int sha1_done(hash_state * md, unsigned char *out)
264264 Self-test the hash
265265 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
266266*/
267- int sha1_test (void )
267+ int sha1_c_test (void )
268268{
269269 #ifndef LTC_TEST
270270 return CRYPT_NOP ;
@@ -290,9 +290,9 @@ int sha1_test(void)
290290 hash_state md ;
291291
292292 for (i = 0 ; i < (int )(sizeof (tests ) / sizeof (tests [0 ])); i ++ ) {
293- sha1_init (& md );
294- sha1_process (& md , (unsigned char * )tests [i ].msg , (unsigned long )XSTRLEN (tests [i ].msg ));
295- sha1_done (& md , tmp );
293+ sha1_c_init (& md );
294+ sha1_c_process (& md , (unsigned char * )tests [i ].msg , (unsigned long )XSTRLEN (tests [i ].msg ));
295+ sha1_c_done (& md , tmp );
296296 if (ltc_compare_testvector (tmp , sizeof (tmp ), tests [i ].hash , sizeof (tests [i ].hash ), "SHA1" , i )) {
297297 return CRYPT_FAIL_TESTVECTOR ;
298298 }
0 commit comments