Changeset 5ebff60 for lib/sha1.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/sha1.c

    raf359b4 r5ebff60  
    1717{
    1818        gsize digest_len = SHA1_HASH_SIZE;
     19
    1920        g_checksum_get_digest(*ctx, digest, &digest_len);
    2021        g_checksum_free(*ctx);
     
    2829        sha1_state_t sha1;
    2930        guint8 hash[SHA1_HASH_SIZE];
    30         guint8 key[HMAC_BLOCK_SIZE+1];
     31        guint8 key[HMAC_BLOCK_SIZE + 1];
    3132        int i;
    32        
    33         if( key_len == 0 )
    34                 key_len = strlen( key_ );
    35         if( payload_len == 0 )
    36                 payload_len = strlen( payload );
    37        
     33
     34        if (key_len == 0) {
     35                key_len = strlen(key_);
     36        }
     37        if (payload_len == 0) {
     38                payload_len = strlen(payload);
     39        }
     40
    3841        /* Create K. If our current key is >64 chars we have to hash it,
    3942           otherwise just pad. */
    40         memset( key, 0, HMAC_BLOCK_SIZE + 1 );
    41         if( key_len > HMAC_BLOCK_SIZE )
    42         {
    43                 sha1_init( &sha1 );
    44                 sha1_append( &sha1, (guint8*) key_, key_len );
    45                 sha1_finish( &sha1, key );
     43        memset(key, 0, HMAC_BLOCK_SIZE + 1);
     44        if (key_len > HMAC_BLOCK_SIZE) {
     45                sha1_init(&sha1);
     46                sha1_append(&sha1, (guint8 *) key_, key_len);
     47                sha1_finish(&sha1, key);
     48        } else {
     49                memcpy(key, key_, key_len);
    4650        }
    47         else
    48         {
    49                 memcpy( key, key_, key_len );
     51
     52        /* Inner part: H(K XOR 0x36, text) */
     53        sha1_init(&sha1);
     54        for (i = 0; i < HMAC_BLOCK_SIZE; i++) {
     55                key[i] ^= 0x36;
    5056        }
    51        
    52         /* Inner part: H(K XOR 0x36, text) */
    53         sha1_init( &sha1 );
    54         for( i = 0; i < HMAC_BLOCK_SIZE; i ++ )
    55                 key[i] ^= 0x36;
    56         sha1_append( &sha1, key, HMAC_BLOCK_SIZE );
    57         sha1_append( &sha1, (const guint8*) payload, payload_len );
    58         sha1_finish( &sha1, hash );
    59        
     57        sha1_append(&sha1, key, HMAC_BLOCK_SIZE);
     58        sha1_append(&sha1, (const guint8 *) payload, payload_len);
     59        sha1_finish(&sha1, hash);
     60
    6061        /* Final result: H(K XOR 0x5C, inner stuff) */
    61         sha1_init( &sha1 );
    62         for( i = 0; i < HMAC_BLOCK_SIZE; i ++ )
     62        sha1_init(&sha1);
     63        for (i = 0; i < HMAC_BLOCK_SIZE; i++) {
    6364                key[i] ^= 0x36 ^ 0x5c;
    64         sha1_append( &sha1, key, HMAC_BLOCK_SIZE );
    65         sha1_append( &sha1, hash, SHA1_HASH_SIZE );
    66         sha1_finish( &sha1, digest );
     65        }
     66        sha1_append(&sha1, key, HMAC_BLOCK_SIZE);
     67        sha1_append(&sha1, hash, SHA1_HASH_SIZE);
     68        sha1_finish(&sha1, digest);
    6769}
    6870
     
    7173   My random data comes from a SHA1 generator but hey, it's random enough for
    7274   me, and RFC 4122 looks way more complicated than I need this to be.
    73    
     75
    7476   Returns a value that must be free()d. */
    75 char *sha1_random_uuid( sha1_state_t * context )
     77char *sha1_random_uuid(sha1_state_t * context)
    7678{
    7779        guint8 dig[SHA1_HASH_SIZE];
    78         char *ret = g_new0( char, 40 ); /* 36 chars + \0 */
     80        char *ret = g_new0(char, 40);  /* 36 chars + \0 */
    7981        int i, p;
    80        
     82
    8183        sha1_finish(context, dig);
    82         for( p = i = 0; i < 16; i ++ )
    83         {
    84                 if( i == 4 || i == 6 || i == 8 || i == 10 )
     84        for (p = i = 0; i < 16; i++) {
     85                if (i == 4 || i == 6 || i == 8 || i == 10) {
    8586                        ret[p++] = '-';
    86                 if( i == 6 )
    87                         dig[i] = ( dig[i] & 0x0f ) | 0x40;
    88                 if( i == 8 )
    89                         dig[i] = ( dig[i] & 0x30 ) | 0x80;
    90                
    91                 sprintf( ret + p, "%02x", dig[i] );
     87                }
     88                if (i == 6) {
     89                        dig[i] = (dig[i] & 0x0f) | 0x40;
     90                }
     91                if (i == 8) {
     92                        dig[i] = (dig[i] & 0x30) | 0x80;
     93                }
     94
     95                sprintf(ret + p, "%02x", dig[i]);
    9296                p += 2;
    9397        }
    9498        ret[p] = '\0';
    95        
     99
    96100        return ret;
    97101}
Note: See TracChangeset for help on using the changeset viewer.