comparison signkey.c @ 214:5a75f8a21503

Change the format of for loops, gcc4 produces incorrect binaries with the previous code.
author Matt Johnston <matt@ucc.asn.au>
date Fri, 08 Jul 2005 11:30:54 +0000
parents 0cfba3034be5
children eb7b9f2bb8e8
comparison
equal deleted inserted replaced
208:1a52846ec11f 214:5a75f8a21503
277 unsigned int keybloblen) { 277 unsigned int keybloblen) {
278 278
279 char * ret; 279 char * ret;
280 hash_state hs; 280 hash_state hs;
281 unsigned char hash[MD5_HASH_SIZE]; 281 unsigned char hash[MD5_HASH_SIZE];
282 unsigned int h, i; 282 unsigned int i;
283 unsigned int buflen; 283 unsigned int buflen;
284 284
285 md5_init(&hs); 285 md5_init(&hs);
286 286
287 /* skip the size int of the string - this is a bit messy */ 287 /* skip the size int of the string - this is a bit messy */
294 ret = (char*)m_malloc(buflen); 294 ret = (char*)m_malloc(buflen);
295 295
296 memset(ret, 'Z', buflen); 296 memset(ret, 'Z', buflen);
297 strcpy(ret, "md5 "); 297 strcpy(ret, "md5 ");
298 298
299 for (i = 4, h = 0; i < buflen; i+=3, h++) { 299 for (i = 0; i < MD5_HASH_SIZE; i++) {
300 ret[i] = hexdig(hash[h] >> 4); 300 unsigned int pos = 4 + i*3;
301 ret[i+1] = hexdig(hash[h] & 0x0f); 301 ret[pos] = hexdig(hash[i] >> 4);
302 ret[i+2] = ':'; 302 ret[pos+1] = hexdig(hash[i] & 0x0f);
303 ret[pos+2] = ':';
303 } 304 }
304 ret[buflen-1] = 0x0; 305 ret[buflen-1] = 0x0;
305 306
306 return ret; 307 return ret;
307 } 308 }
311 unsigned int keybloblen) { 312 unsigned int keybloblen) {
312 313
313 char * ret; 314 char * ret;
314 hash_state hs; 315 hash_state hs;
315 unsigned char hash[SHA1_HASH_SIZE]; 316 unsigned char hash[SHA1_HASH_SIZE];
316 unsigned int h, i; 317 unsigned int i;
317 unsigned int buflen; 318 unsigned int buflen;
318 319
319 sha1_init(&hs); 320 sha1_init(&hs);
320 321
321 /* skip the size int of the string - this is a bit messy */ 322 /* skip the size int of the string - this is a bit messy */
327 buflen = 5 + 3*SHA1_HASH_SIZE; 328 buflen = 5 + 3*SHA1_HASH_SIZE;
328 ret = (char*)m_malloc(buflen); 329 ret = (char*)m_malloc(buflen);
329 330
330 strcpy(ret, "sha1 "); 331 strcpy(ret, "sha1 ");
331 332
332 for (i = 5, h = 0; i < buflen; i+=3, h++) { 333 for (i = 0; i < SHA1_HASH_SIZE; i++) {
333 ret[i] = hexdig(hash[h] >> 4); 334 unsigned int pos = 5 + 3*i;
334 ret[i+1] = hexdig(hash[h] & 0x0f); 335 ret[pos] = hexdig(hash[i] >> 4);
335 ret[i+2] = ':'; 336 ret[pos+1] = hexdig(hash[i] & 0x0f);
337 ret[pos+2] = ':';
336 } 338 }
337 ret[buflen-1] = 0x0; 339 ret[buflen-1] = 0x0;
338 340
339 return ret; 341 return ret;
340 } 342 }