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


Ignore:
Timestamp:
2015-04-13T20:48:33Z (10 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc575ef9
Parents:
053fc2b
Message:

Added TKIP support, handling old WPA in 4way handshake, some fixes in wifi_supplicant app

File:
1 edited

Legend:

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

    r053fc2b ra931b7b  
    252252
    253253/**
    254  * Hash-based message authentication code using SHA-1 algorithm.
     254 * Hash-based message authentication code.
    255255 *
    256256 * @param key Cryptographic key sequence.
     
    308308 * Password-Based Key Derivation Function 2 as defined in RFC 2898,
    309309 * using HMAC-SHA1 with 4096 iterations and 32 bytes key result used
    310  * for WPA2.
     310 * for WPA/WPA2.
    311311 *
    312312 * @param pass Password sequence.
     
    315315 * @param salt_size Salt sequence length.
    316316 * @param hash Output parameter for result hash (32 byte value).
    317  * @param hash_sel Hash function selector.
    318317 *
    319318 * @return EINVAL when pass or salt not specified, ENOMEM when pointer for
     
    321320 */
    322321int pbkdf2(uint8_t *pass, size_t pass_size, uint8_t *salt, size_t salt_size,
    323         uint8_t *hash, hash_func_t hash_sel)
     322        uint8_t *hash)
    324323{
    325324        if(!pass || !salt)
     
    331330        uint8_t work_salt[salt_size + sizeof(uint32_t)];
    332331        memcpy(work_salt, salt, salt_size);
    333         uint8_t work_hmac[hash_sel];
    334         uint8_t temp_hmac[hash_sel];
    335         uint8_t xor_hmac[hash_sel];
    336         uint8_t temp_hash[hash_sel*2];
     332        uint8_t work_hmac[HASH_SHA1];
     333        uint8_t temp_hmac[HASH_SHA1];
     334        uint8_t xor_hmac[HASH_SHA1];
     335        uint8_t temp_hash[HASH_SHA1*2];
    337336       
    338337        for(size_t i = 0; i < 2; i++) {
     
    340339                memcpy(work_salt + salt_size, &big_i, sizeof(uint32_t));
    341340                hmac(pass, pass_size, work_salt, salt_size + sizeof(uint32_t),
    342                         work_hmac, hash_sel);
    343                 memcpy(xor_hmac, work_hmac, hash_sel);
     341                        work_hmac, HASH_SHA1);
     342                memcpy(xor_hmac, work_hmac, HASH_SHA1);
    344343                for(size_t k = 1; k < 4096; k++) {
    345                         memcpy(temp_hmac, work_hmac, hash_sel);
    346                         hmac(pass, pass_size, temp_hmac, hash_sel,
    347                                 work_hmac, hash_sel);
    348                         for(size_t t = 0; t < hash_sel; t++) {
     344                        memcpy(temp_hmac, work_hmac, HASH_SHA1);
     345                        hmac(pass, pass_size, temp_hmac, HASH_SHA1,
     346                                work_hmac, HASH_SHA1);
     347                        for(size_t t = 0; t < HASH_SHA1; t++) {
    349348                                xor_hmac[t] ^= work_hmac[t];
    350349                        }
    351350                }
    352                 memcpy(temp_hash + i*hash_sel, xor_hmac, hash_sel);
     351                memcpy(temp_hash + i*HASH_SHA1, xor_hmac, HASH_SHA1);
    353352        }
    354353       
Note: See TracChangeset for help on using the changeset viewer.