Changeset a931b7b in mainline for uspace/lib/crypto/crypto.c
- Timestamp:
- 2015-04-13T20:48:33Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cc575ef9
- Parents:
- 053fc2b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/crypto/crypto.c
r053fc2b ra931b7b 252 252 253 253 /** 254 * Hash-based message authentication code using SHA-1 algorithm.254 * Hash-based message authentication code. 255 255 * 256 256 * @param key Cryptographic key sequence. … … 308 308 * Password-Based Key Derivation Function 2 as defined in RFC 2898, 309 309 * using HMAC-SHA1 with 4096 iterations and 32 bytes key result used 310 * for WPA 2.310 * for WPA/WPA2. 311 311 * 312 312 * @param pass Password sequence. … … 315 315 * @param salt_size Salt sequence length. 316 316 * @param hash Output parameter for result hash (32 byte value). 317 * @param hash_sel Hash function selector.318 317 * 319 318 * @return EINVAL when pass or salt not specified, ENOMEM when pointer for … … 321 320 */ 322 321 int 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) 324 323 { 325 324 if(!pass || !salt) … … 331 330 uint8_t work_salt[salt_size + sizeof(uint32_t)]; 332 331 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]; 337 336 338 337 for(size_t i = 0; i < 2; i++) { … … 340 339 memcpy(work_salt + salt_size, &big_i, sizeof(uint32_t)); 341 340 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); 344 343 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++) { 349 348 xor_hmac[t] ^= work_hmac[t]; 350 349 } 351 350 } 352 memcpy(temp_hash + i* hash_sel, xor_hmac, hash_sel);351 memcpy(temp_hash + i*HASH_SHA1, xor_hmac, HASH_SHA1); 353 352 } 354 353
Note:
See TracChangeset
for help on using the changeset viewer.