Changeset a35b458 in mainline for uspace/lib/crypto/crypto.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/crypto/crypto.c

    r3061bc1 ra35b458  
    101101        uint32_t f, g, temp;
    102102        uint32_t w[HASH_MD5 / 4];
    103        
     103
    104104        memcpy(w, h, (HASH_MD5 / 4) * sizeof(uint32_t));
    105        
     105
    106106        for (size_t k = 0; k < 64; k++) {
    107107                if (k < 16) {
     
    118118                        g = 7 * k % 16;
    119119                }
    120                
     120
    121121                temp = w[3];
    122122                w[3] = w[2];
     
    127127                w[0] = temp;
    128128        }
    129        
     129
    130130        for (uint8_t k = 0; k < HASH_MD5 / 4; k++)
    131131                h[k] += w[k];
     
    142142        uint32_t f, cf, temp;
    143143        uint32_t w[HASH_SHA1 / 4];
    144        
     144
    145145        for (size_t k = 16; k < 80; k++) {
    146146                sched_arr[k] = rotl_uint32(
     
    151151                    1);
    152152        }
    153        
     153
    154154        memcpy(w, h, (HASH_SHA1 / 4) * sizeof(uint32_t));
    155        
     155
    156156        for (size_t k = 0; k < 80; k++) {
    157157                if (k < 20) {
     
    168168                        cf = 0xca62c1d6;
    169169                }
    170                
     170
    171171                temp = rotl_uint32(w[0], 5) + f + w[4] + cf + sched_arr[k];
    172                
     172
    173173                w[4] = w[3];
    174174                w[3] = w[2];
     
    177177                w[0] = temp;
    178178        }
    179        
     179
    180180        for (uint8_t k = 0; k < HASH_SHA1 / 4; k++)
    181181                h[k] += w[k];
     
    199199        if (!input)
    200200                return EINVAL;
    201        
     201
    202202        if (!output)
    203203                return ENOMEM;
    204        
     204
    205205        hash_fnc_t hash_func = (hash_sel == HASH_MD5) ? md5_proc : sha1_proc;
    206        
     206
    207207        /* Prepare scheduled input. */
    208208        uint8_t work_input[input_size + 1];
    209209        memcpy(work_input, input, input_size);
    210210        work_input[input_size] = 0x80;
    211        
     211
    212212        // FIXME: double?
    213213        size_t blocks = ceil_uint32((((double) input_size + 1) / 4 + 2) / 16);
     
    222222                }
    223223        }
    224        
     224
    225225        uint64_t bits_size = (uint64_t) (input_size * 8);
    226226        if (hash_sel == HASH_MD5)
    227227                bits_size = uint64_t_byteorder_swap(bits_size);
    228        
     228
    229229        work_arr[(blocks - 1) * 16 + 14] = bits_size >> 32;
    230230        work_arr[(blocks - 1) * 16 + 15] = bits_size & 0xffffffff;
    231        
     231
    232232        /* Hash computation. */
    233233        uint32_t h[hash_sel / 4];
     
    237237                for (size_t k = 0; k < 16; k++)
    238238                        sched_arr[k] = work_arr[i * 16 + k];
    239                
     239
    240240                hash_func(h, sched_arr);
    241241        }
    242        
     242
    243243        /* Copy hash parts into final result. */
    244244        for (size_t i = 0; i < hash_sel / 4; i++) {
    245245                if (hash_sel == HASH_SHA1)
    246246                        h[i] = uint32_t_byteorder_swap(h[i]);
    247                
     247
    248248                memcpy(output + i * sizeof(uint32_t), &h[i], sizeof(uint32_t));
    249249        }
    250        
     250
    251251        return EOK;
    252252}
     
    271271        if ((!key) || (!msg))
    272272                return EINVAL;
    273        
     273
    274274        if (!hash)
    275275                return ENOMEM;
    276        
     276
    277277        uint8_t work_key[HMAC_BLOCK_LENGTH];
    278278        uint8_t o_key_pad[HMAC_BLOCK_LENGTH];
     
    280280        uint8_t temp_hash[hash_sel];
    281281        memset(work_key, 0, HMAC_BLOCK_LENGTH);
    282        
     282
    283283        if(key_size > HMAC_BLOCK_LENGTH)
    284284                create_hash(key, key_size, work_key, hash_sel);
    285285        else
    286286                memcpy(work_key, key, key_size);
    287        
     287
    288288        for (size_t i = 0; i < HMAC_BLOCK_LENGTH; i++) {
    289289                o_key_pad[i] = work_key[i] ^ 0x5c;
    290290                i_key_pad[i] = work_key[i] ^ 0x36;
    291291        }
    292        
     292
    293293        uint8_t temp_work[HMAC_BLOCK_LENGTH + max(msg_size, hash_sel)];
    294294        memcpy(temp_work, i_key_pad, HMAC_BLOCK_LENGTH);
    295295        memcpy(temp_work + HMAC_BLOCK_LENGTH, msg, msg_size);
    296        
     296
    297297        create_hash(temp_work, HMAC_BLOCK_LENGTH + msg_size, temp_hash,
    298298            hash_sel);
    299        
     299
    300300        memcpy(temp_work, o_key_pad, HMAC_BLOCK_LENGTH);
    301301        memcpy(temp_work + HMAC_BLOCK_LENGTH, temp_hash, hash_sel);
    302        
     302
    303303        create_hash(temp_work, HMAC_BLOCK_LENGTH + hash_sel, hash, hash_sel);
    304        
     304
    305305        return EOK;
    306306}
     
    327327        if ((!pass) || (!salt))
    328328                return EINVAL;
    329        
     329
    330330        if (!hash)
    331331                return ENOMEM;
    332        
     332
    333333        uint8_t work_salt[salt_size + 4];
    334334        memcpy(work_salt, salt, salt_size);
     
    337337        uint8_t xor_hmac[HASH_SHA1];
    338338        uint8_t temp_hash[HASH_SHA1 * 2];
    339        
     339
    340340        for (size_t i = 0; i < 2; i++) {
    341341                uint32_t be_i = host2uint32_t_be(i + 1);
    342                
     342
    343343                memcpy(work_salt + salt_size, &be_i, 4);
    344344                hmac(pass, pass_size, work_salt, salt_size + 4,
    345345                    work_hmac, HASH_SHA1);
    346346                memcpy(xor_hmac, work_hmac, HASH_SHA1);
    347                
     347
    348348                for (size_t k = 1; k < 4096; k++) {
    349349                        memcpy(temp_hmac, work_hmac, HASH_SHA1);
    350350                        hmac(pass, pass_size, temp_hmac, HASH_SHA1,
    351351                            work_hmac, HASH_SHA1);
    352                        
     352
    353353                        for (size_t t = 0; t < HASH_SHA1; t++)
    354354                                xor_hmac[t] ^= work_hmac[t];
    355355                }
    356                
     356
    357357                memcpy(temp_hash + i * HASH_SHA1, xor_hmac, HASH_SHA1);
    358358        }
    359        
     359
    360360        memcpy(hash, temp_hash, PBKDF2_KEY_LENGTH);
    361        
     361
    362362        return EOK;
    363363}
Note: See TracChangeset for help on using the changeset viewer.