- Timestamp:
- 2012-02-10T13:37:08Z (13 years ago)
- Branches:
- master
- Children:
- bb2d198
- Parents:
- 7d27962
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/sha1.c
r7d27962 re0a0a42 37 37 38 38 #include <string.h> 39 #include <stdio.h> 39 40 #include "sha1.h" 40 41 … … 421 422 sha1_finish( &sha1, Message_Digest ); 422 423 } 424 425 /* I think this follows the scheme described on: 426 http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 427 My random data comes from a SHA1 generator but hey, it's random enough for 428 me, and RFC 4122 looks way more complicated than I need this to be. 429 430 Returns a value that must be free()d. */ 431 char *sha1_random_uuid( sha1_state_t * context ) 432 { 433 uint8_t dig[sha1_hash_size]; 434 char *ret = g_new0( char, 40 ); /* 36 chars + \0 */ 435 int i, p; 436 437 sha1_finish(context, dig); 438 for( p = i = 0; i < 16; i ++ ) 439 { 440 if( i == 4 || i == 6 || i == 8 || i == 10 ) 441 ret[p++] = '-'; 442 if( i == 6 ) 443 dig[i] = ( dig[i] & 0x0f ) | 0x40; 444 if( i == 8 ) 445 dig[i] = ( dig[i] & 0x30 ) | 0x80; 446 447 sprintf( ret + p, "%02x", dig[i] ); 448 p += 2; 449 } 450 ret[p] = '\0'; 451 452 return ret; 453 } -
lib/sha1.h
r7d27962 re0a0a42 68 68 G_MODULE_EXPORT int sha1_finish(sha1_state_t *, uint8_t Message_Digest[sha1_hash_size]); 69 69 G_MODULE_EXPORT void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, uint8_t Message_Digest[sha1_hash_size]); 70 G_MODULE_EXPORT char *sha1_random_uuid( sha1_state_t * context ); 70 71 71 72 #endif
Note: See TracChangeset
for help on using the changeset viewer.