| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 #include "plarena.h" | 5 #include "plarena.h" |
| 6 | 6 |
| 7 #include "seccomon.h" | 7 #include "seccomon.h" |
| 8 #include "secitem.h" | 8 #include "secitem.h" |
| 9 #include "secport.h" | 9 #include "secport.h" |
| 10 #include "hasht.h" | 10 #include "hasht.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 /* use byt xor, not all platforms are happy about inaligned | 312 /* use byt xor, not all platforms are happy about inaligned |
| 313 * integer fetches */ | 313 * integer fetches */ |
| 314 while (len--) { | 314 while (len--) { |
| 315 *dest = *dest ^ *src; | 315 *dest = *dest ^ *src; |
| 316 dest++; | 316 dest++; |
| 317 src++; | 317 src++; |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 static SECStatus | 321 static SECStatus |
| 322 nsspkcs5_PBKFD2_F(const SECHashObject *hashobj, SECItem *pwitem, SECItem *salt, | 322 nsspkcs5_PBKDF2_F(const SECHashObject *hashobj, SECItem *pwitem, SECItem *salt, |
| 323 » » » int iterations, unsigned int i, unsigned char *T) | 323 int iterations, unsigned int i, unsigned char *T) |
| 324 { | 324 { |
| 325 int j; | 325 int j; |
| 326 HMACContext *cx = NULL; | 326 HMACContext *cx = NULL; |
| 327 unsigned int hLen = hashobj->length; | 327 unsigned int hLen = hashobj->length; |
| 328 SECStatus rv = SECFailure; | 328 SECStatus rv = SECFailure; |
| 329 unsigned char *last = NULL; | 329 unsigned char *last = NULL; |
| 330 unsigned int lastLength = salt->len + 4; | 330 unsigned int lastLength = salt->len + 4; |
| 331 unsigned int lastBufLength; | 331 unsigned int lastBufLength; |
| 332 | 332 |
| 333 cx=HMAC_Create(hashobj,pwitem->data,pwitem->len,PR_FALSE); | 333 cx=HMAC_Create(hashobj,pwitem->data,pwitem->len,PR_FALSE); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (result == NULL) { | 386 if (result == NULL) { |
| 387 return NULL; | 387 return NULL; |
| 388 } | 388 } |
| 389 | 389 |
| 390 T = PORT_Alloc(hLen); | 390 T = PORT_Alloc(hLen); |
| 391 if (T == NULL) { | 391 if (T == NULL) { |
| 392 goto loser; | 392 goto loser; |
| 393 } | 393 } |
| 394 | 394 |
| 395 for (i=1,rp=result->data; i <= nblocks ; i++, rp +=hLen) { | 395 for (i=1,rp=result->data; i <= nblocks ; i++, rp +=hLen) { |
| 396 » rv = nsspkcs5_PBKFD2_F(hashobj,pwitem,salt,iterations,i,T); | 396 rv = nsspkcs5_PBKDF2_F(hashobj, pwitem, salt, iterations, i, T); |
| 397 if (rv != SECSuccess) { | 397 if (rv != SECSuccess) { |
| 398 break; | 398 break; |
| 399 } | 399 } |
| 400 PORT_Memcpy(rp,T,hLen); | 400 PORT_Memcpy(rp,T,hLen); |
| 401 } | 401 } |
| 402 | 402 |
| 403 loser: | 403 loser: |
| 404 if (T) { | 404 if (T) { |
| 405 PORT_ZFree(T,hLen); | 405 PORT_ZFree(T,hLen); |
| 406 } | 406 } |
| 407 if (rv != SECSuccess) { | 407 if (rv != SECSuccess) { |
| 408 SECITEM_FreeItem(result,PR_TRUE); | 408 SECITEM_FreeItem(result,PR_TRUE); |
| 409 result = NULL; | 409 result = NULL; |
| 410 } else { | 410 } else { |
| 411 result->len = dkLen; | 411 result->len = dkLen; |
| 412 } | 412 } |
| 413 » | 413 |
| 414 return result; | 414 return result; |
| 415 } | 415 } |
| 416 #endif | 416 #endif |
| 417 | 417 |
| 418 #define HMAC_BUFFER 64 | 418 #define HMAC_BUFFER 64 |
| 419 #define NSSPBE_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y)) | 419 #define NSSPBE_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y)) |
| 420 #define NSSPBE_MIN(x,y) ((x) < (y) ? (x) : (y)) | 420 #define NSSPBE_MIN(x,y) ((x) < (y) ? (x) : (y)) |
| 421 /* | 421 /* |
| 422 * This is the extended PBE function defined by the final PKCS #12 spec. | 422 * This is the extended PBE function defined by the final PKCS #12 spec. |
| 423 */ | 423 */ |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 rv = SECOID_CopyAlgorithmID(NULL, ret_algid, algid); | 1369 rv = SECOID_CopyAlgorithmID(NULL, ret_algid, algid); |
| 1370 if (rv != SECSuccess) { | 1370 if (rv != SECSuccess) { |
| 1371 SECOID_DestroyAlgorithmID(ret_algid, PR_TRUE); | 1371 SECOID_DestroyAlgorithmID(ret_algid, PR_TRUE); |
| 1372 ret_algid = NULL; | 1372 ret_algid = NULL; |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 loser: | 1375 loser: |
| 1376 | 1376 |
| 1377 return ret_algid; | 1377 return ret_algid; |
| 1378 } | 1378 } |
| OLD | NEW |