Changeset a931b7b in mainline for uspace/lib/crypto


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

Location:
uspace/lib/crypto
Files:
3 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       
  • uspace/lib/crypto/crypto.h

    r053fc2b ra931b7b  
    4141} hash_func_t;
    4242
    43 extern int rc4(uint8_t *key, size_t key_size, uint8_t *input,
    44         size_t input_size, uint8_t *output);
     43extern int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size,
     44        size_t skip, uint8_t *output);
    4545extern int aes_encrypt(uint8_t *key, uint8_t *input, uint8_t *output);
    4646extern int aes_decrypt(uint8_t *key, uint8_t *input, uint8_t *output);
     
    5050        uint8_t *hash, hash_func_t hash_sel);
    5151extern int pbkdf2(uint8_t *pass, size_t pass_size, uint8_t *salt,
    52         size_t salt_size, uint8_t *hash, hash_func_t hash_sel);
     52        size_t salt_size, uint8_t *hash);
    5353
    5454#endif
  • uspace/lib/crypto/rc4.c

    r053fc2b ra931b7b  
    8282 * @param input Input data sequence to be processed.
    8383 * @param input_size Size of input data sequence.
     84 * @param skip Number of bytes to be skipped from the beginning of key stream.
    8485 * @param output Result data sequence.
    8586 *
     
    8889 */
    8990int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size,
    90         uint8_t *output)
     91        size_t skip, uint8_t *output)
    9192{
    9293        if(!key || !input)
     
    100101        create_sbox(key, key_size, sbox);
    101102       
     103        /* Skip first x bytes. */
     104        uint8_t i = 0, j = 0;
     105        for(size_t k = 0; k < skip; k++) {
     106                i = i+1;
     107                j = j + sbox[i];
     108                swap(i, j, sbox);
     109        }
     110       
    102111        /* Processing loop. */
    103         uint8_t i = 0, j = 0, val;
     112        uint8_t val;
    104113        for(size_t k = 0; k < input_size; k++) {
    105114                i = i+1;
Note: See TracChangeset for help on using the changeset viewer.