1 /* 2 * loader.c - load platform dependent DSO containing freebl implementation. 3 * 4 * ***** BEGIN LICENSE BLOCK ***** 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * The Original Code is the Netscape security libraries. 18 * 19 * The Initial Developer of the Original Code is 20 * Netscape Communications Corporation. 21 * Portions created by the Initial Developer are Copyright (C) 2000 22 * the Initial Developer. All Rights Reserved. 23 * 24 * Contributor(s): 25 * Dr Vipul Gupta <vipul.gupta (at) sun.com>, Sun Microsystems Laboratories 26 * 27 * Alternatively, the contents of this file may be used under the terms of 28 * either the GNU General Public License Version 2 or later (the "GPL"), or 29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 30 * in which case the provisions of the GPL or the LGPL are applicable instead 31 * of those above. If you wish to allow use of your version of this file only 32 * under the terms of either the GPL or the LGPL, and not to allow others to 33 * use your version of this file under the terms of the MPL, indicate your 34 * decision by deleting the provisions above and replace them with the notice 35 * and other provisions required by the GPL or the LGPL. If you do not delete 36 * the provisions above, a recipient may use your version of this file under 37 * the terms of any one of the MPL, the GPL or the LGPL. 38 * 39 * ***** END LICENSE BLOCK ***** */ 40 /* $Id: loader.c,v 1.44 2009/03/29 03:45:32 wtc%google.com Exp $ */ 41 42 #include "loader.h" 43 #include "prmem.h" 44 #include "prerror.h" 45 #include "prinit.h" 46 #include "prenv.h" 47 48 static const char* default_name = 49 SHLIB_PREFIX"freebl"SHLIB_VERSION"."SHLIB_SUFFIX; 50 51 /* getLibName() returns the name of the library to load. */ 52 53 #if defined(SOLARIS) && defined(__sparc) 54 #include <stddef.h> 55 #include <strings.h> 56 #include <sys/systeminfo.h> 57 58 59 #if defined(NSS_USE_64) 60 61 const static char fpu_hybrid_shared_lib[] = "libfreebl_64fpu_3.so"; 62 const static char int_hybrid_shared_lib[] = "libfreebl_64int_3.so"; 63 const static char non_hybrid_shared_lib[] = "libfreebl_64fpu_3.so"; 64 65 const static char int_hybrid_isa[] = "sparcv9"; 66 const static char fpu_hybrid_isa[] = "sparcv9+vis"; 67 68 #else 69 70 const static char fpu_hybrid_shared_lib[] = "libfreebl_32fpu_3.so"; 71 const static char int_hybrid_shared_lib[] = "libfreebl_32int64_3.so"; 72 const static char non_hybrid_shared_lib[] = "libfreebl_32int_3.so"; 73 74 const static char int_hybrid_isa[] = "sparcv8plus"; 75 const static char fpu_hybrid_isa[] = "sparcv8plus+vis"; 76 77 #endif 78 79 static const char * 80 getLibName(void) 81 { 82 char * found_int_hybrid; 83 char * found_fpu_hybrid; 84 long buflen; 85 char buf[256]; 86 87 buflen = sysinfo(SI_ISALIST, buf, sizeof buf); 88 if (buflen <= 0) 89 return NULL; 90 /* sysinfo output is always supposed to be NUL terminated, but ... */ 91 if (buflen < sizeof buf) 92 buf[buflen] = '\0'; 93 else 94 buf[(sizeof buf) - 1] = '\0'; 95 /* The ISA list is a space separated string of names of ISAs and 96 * ISA extensions, in order of decreasing performance. 97 * There are two different ISAs with which NSS's crypto code can be 98 * accelerated. If both are in the list, we take the first one. 99 * If one is in the list, we use it, and if neither then we use 100 * the base unaccelerated code. 101 */ 102 found_int_hybrid = strstr(buf, int_hybrid_isa); 103 found_fpu_hybrid = strstr(buf, fpu_hybrid_isa); 104 if (found_fpu_hybrid && 105 (!found_int_hybrid || 106 (found_int_hybrid - found_fpu_hybrid) >= 0)) { 107 return fpu_hybrid_shared_lib; 108 } 109 if (found_int_hybrid) { 110 return int_hybrid_shared_lib; 111 } 112 return non_hybrid_shared_lib; 113 } 114 115 #elif defined(HPUX) && !defined(NSS_USE_64) && !defined(__ia64) 116 /* This code tests to see if we're running on a PA2.x CPU. 117 ** It returns true (1) if so, and false (0) otherwise. 118 */ 119 static const char * 120 getLibName(void) 121 { 122 long cpu = sysconf(_SC_CPU_VERSION); 123 return (cpu == CPU_PA_RISC2_0) 124 ? "libfreebl_32fpu_3.sl" 125 : "libfreebl_32int32_3.sl" ; 126 } 127 #else 128 /* default case, for platforms/ABIs that have only one freebl shared lib. */ 129 static const char * getLibName(void) { return default_name; } 130 #endif 131 132 #include "prio.h" 133 #include "prprf.h" 134 #include <stdio.h> 135 #include "prsystem.h" 136 137 static const char *NameOfThisSharedLib = 138 SHLIB_PREFIX"softokn"SOFTOKEN_SHLIB_VERSION"."SHLIB_SUFFIX; 139 140 static PRLibrary* blLib; 141 142 #define LSB(x) ((x)&0xff) 143 #define MSB(x) ((x)>>8) 144 145 static const FREEBLVector *vector; 146 static const char *libraryName = NULL; 147 148 #include "genload.c" 149 150 /* This function must be run only once. */ 151 /* determine if hybrid platform, then actually load the DSO. */ 152 static PRStatus 153 freebl_LoadDSO( void ) 154 { 155 PRLibrary * handle; 156 const char * name = getLibName(); 157 158 if (!name) { 159 PR_SetError(PR_LOAD_LIBRARY_ERROR, 0); 160 return PR_FAILURE; 161 } 162 163 handle = loader_LoadLibrary(name); 164 if (handle) { 165 PRFuncPtr address = PR_FindFunctionSymbol(handle, "FREEBL_GetVector"); 166 PRStatus status; 167 if (address) { 168 FREEBLGetVectorFn * getVector = (FREEBLGetVectorFn *)address; 169 const FREEBLVector * dsoVector = getVector(); 170 if (dsoVector) { 171 unsigned short dsoVersion = dsoVector->version; 172 unsigned short myVersion = FREEBL_VERSION; 173 if (MSB(dsoVersion) == MSB(myVersion) && 174 LSB(dsoVersion) >= LSB(myVersion) && 175 dsoVector->length >= sizeof(FREEBLVector)) { 176 vector = dsoVector; 177 libraryName = name; 178 blLib = handle; 179 return PR_SUCCESS; 180 } 181 } 182 } 183 status = PR_UnloadLibrary(handle); 184 PORT_Assert(PR_SUCCESS == status); 185 } 186 return PR_FAILURE; 187 } 188 189 static const PRCallOnceType pristineCallOnce; 190 static PRCallOnceType loadFreeBLOnce; 191 192 static PRStatus 193 freebl_RunLoaderOnce( void ) 194 { 195 PRStatus status; 196 197 status = PR_CallOnce(&loadFreeBLOnce, &freebl_LoadDSO); 198 return status; 199 } 200 201 SECStatus 202 BL_Init(void) 203 { 204 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 205 return SECFailure; 206 return (vector->p_BL_Init)(); 207 } 208 209 RSAPrivateKey * 210 RSA_NewKey(int keySizeInBits, SECItem * publicExponent) 211 { 212 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 213 return NULL; 214 return (vector->p_RSA_NewKey)(keySizeInBits, publicExponent); 215 } 216 217 SECStatus 218 RSA_PublicKeyOp(RSAPublicKey * key, 219 unsigned char * output, 220 const unsigned char * input) 221 { 222 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 223 return SECFailure; 224 return (vector->p_RSA_PublicKeyOp)(key, output, input); 225 } 226 227 SECStatus 228 RSA_PrivateKeyOp(RSAPrivateKey * key, 229 unsigned char * output, 230 const unsigned char * input) 231 { 232 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 233 return SECFailure; 234 return (vector->p_RSA_PrivateKeyOp)(key, output, input); 235 } 236 237 SECStatus 238 RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey *key, 239 unsigned char *output, 240 const unsigned char *input) 241 { 242 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 243 return SECFailure; 244 return (vector->p_RSA_PrivateKeyOpDoubleChecked)(key, output, input); 245 } 246 247 SECStatus 248 RSA_PrivateKeyCheck(RSAPrivateKey *key) 249 { 250 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 251 return SECFailure; 252 return (vector->p_RSA_PrivateKeyCheck)(key); 253 } 254 255 SECStatus 256 DSA_NewKey(const PQGParams * params, DSAPrivateKey ** privKey) 257 { 258 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 259 return SECFailure; 260 return (vector->p_DSA_NewKey)(params, privKey); 261 } 262 263 SECStatus 264 DSA_SignDigest(DSAPrivateKey * key, SECItem * signature, const SECItem * digest) 265 { 266 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 267 return SECFailure; 268 return (vector->p_DSA_SignDigest)( key, signature, digest); 269 } 270 271 SECStatus 272 DSA_VerifyDigest(DSAPublicKey * key, const SECItem * signature, 273 const SECItem * digest) 274 { 275 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 276 return SECFailure; 277 return (vector->p_DSA_VerifyDigest)( key, signature, digest); 278 } 279 280 SECStatus 281 DSA_NewKeyFromSeed(const PQGParams *params, const unsigned char * seed, 282 DSAPrivateKey **privKey) 283 { 284 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 285 return SECFailure; 286 return (vector->p_DSA_NewKeyFromSeed)(params, seed, privKey); 287 } 288 289 SECStatus 290 DSA_SignDigestWithSeed(DSAPrivateKey * key, SECItem * signature, 291 const SECItem * digest, const unsigned char * seed) 292 { 293 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 294 return SECFailure; 295 return (vector->p_DSA_SignDigestWithSeed)( key, signature, digest, seed); 296 } 297 298 SECStatus 299 DH_GenParam(int primeLen, DHParams ** params) 300 { 301 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 302 return SECFailure; 303 return (vector->p_DH_GenParam)(primeLen, params); 304 } 305 306 SECStatus 307 DH_NewKey(DHParams * params, DHPrivateKey ** privKey) 308 { 309 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 310 return SECFailure; 311 return (vector->p_DH_NewKey)( params, privKey); 312 } 313 314 SECStatus 315 DH_Derive(SECItem * publicValue, SECItem * prime, SECItem * privateValue, 316 SECItem * derivedSecret, unsigned int maxOutBytes) 317 { 318 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 319 return SECFailure; 320 return (vector->p_DH_Derive)( publicValue, prime, privateValue, 321 derivedSecret, maxOutBytes); 322 } 323 324 SECStatus 325 KEA_Derive(SECItem *prime, SECItem *public1, SECItem *public2, 326 SECItem *private1, SECItem *private2, SECItem *derivedSecret) 327 { 328 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 329 return SECFailure; 330 return (vector->p_KEA_Derive)(prime, public1, public2, 331 private1, private2, derivedSecret); 332 } 333 334 PRBool 335 KEA_Verify(SECItem *Y, SECItem *prime, SECItem *subPrime) 336 { 337 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 338 return PR_FALSE; 339 return (vector->p_KEA_Verify)(Y, prime, subPrime); 340 } 341 342 RC4Context * 343 RC4_CreateContext(const unsigned char *key, int len) 344 { 345 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 346 return NULL; 347 return (vector->p_RC4_CreateContext)(key, len); 348 } 349 350 void 351 RC4_DestroyContext(RC4Context *cx, PRBool freeit) 352 { 353 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 354 return; 355 (vector->p_RC4_DestroyContext)(cx, freeit); 356 } 357 358 SECStatus 359 RC4_Encrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen, 360 unsigned int maxOutputLen, const unsigned char *input, 361 unsigned int inputLen) 362 { 363 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 364 return SECFailure; 365 return (vector->p_RC4_Encrypt)(cx, output, outputLen, maxOutputLen, input, 366 inputLen); 367 } 368 369 SECStatus 370 RC4_Decrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen, 371 unsigned int maxOutputLen, const unsigned char *input, 372 unsigned int inputLen) 373 { 374 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 375 return SECFailure; 376 return (vector->p_RC4_Decrypt)(cx, output, outputLen, maxOutputLen, input, 377 inputLen); 378 } 379 380 RC2Context * 381 RC2_CreateContext(const unsigned char *key, unsigned int len, 382 const unsigned char *iv, int mode, unsigned effectiveKeyLen) 383 { 384 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 385 return NULL; 386 return (vector->p_RC2_CreateContext)(key, len, iv, mode, effectiveKeyLen); 387 } 388 389 void 390 RC2_DestroyContext(RC2Context *cx, PRBool freeit) 391 { 392 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 393 return; 394 (vector->p_RC2_DestroyContext)(cx, freeit); 395 } 396 397 SECStatus 398 RC2_Encrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen, 399 unsigned int maxOutputLen, const unsigned char *input, 400 unsigned int inputLen) 401 { 402 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 403 return SECFailure; 404 return (vector->p_RC2_Encrypt)(cx, output, outputLen, maxOutputLen, input, 405 inputLen); 406 } 407 408 SECStatus 409 RC2_Decrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen, 410 unsigned int maxOutputLen, const unsigned char *input, 411 unsigned int inputLen) 412 { 413 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 414 return SECFailure; 415 return (vector->p_RC2_Decrypt)(cx, output, outputLen, maxOutputLen, input, 416 inputLen); 417 } 418 419 RC5Context * 420 RC5_CreateContext(const SECItem *key, unsigned int rounds, 421 unsigned int wordSize, const unsigned char *iv, int mode) 422 { 423 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 424 return NULL; 425 return (vector->p_RC5_CreateContext)(key, rounds, wordSize, iv, mode); 426 } 427 428 void 429 RC5_DestroyContext(RC5Context *cx, PRBool freeit) 430 { 431 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 432 return; 433 (vector->p_RC5_DestroyContext)(cx, freeit); 434 } 435 436 SECStatus 437 RC5_Encrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen, 438 unsigned int maxOutputLen, const unsigned char *input, 439 unsigned int inputLen) 440 { 441 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 442 return SECFailure; 443 return (vector->p_RC5_Encrypt)(cx, output, outputLen, maxOutputLen, input, 444 inputLen); 445 } 446 447 SECStatus 448 RC5_Decrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen, 449 unsigned int maxOutputLen, const unsigned char *input, 450 unsigned int inputLen) 451 { 452 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 453 return SECFailure; 454 return (vector->p_RC5_Decrypt)(cx, output, outputLen, maxOutputLen, input, 455 inputLen); 456 } 457 458 DESContext * 459 DES_CreateContext(const unsigned char *key, const unsigned char *iv, 460 int mode, PRBool encrypt) 461 { 462 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 463 return NULL; 464 return (vector->p_DES_CreateContext)(key, iv, mode, encrypt); 465 } 466 467 void 468 DES_DestroyContext(DESContext *cx, PRBool freeit) 469 { 470 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 471 return; 472 (vector->p_DES_DestroyContext)(cx, freeit); 473 } 474 475 SECStatus 476 DES_Encrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen, 477 unsigned int maxOutputLen, const unsigned char *input, 478 unsigned int inputLen) 479 { 480 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 481 return SECFailure; 482 return (vector->p_DES_Encrypt)(cx, output, outputLen, maxOutputLen, input, 483 inputLen); 484 } 485 486 SECStatus 487 DES_Decrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen, 488 unsigned int maxOutputLen, const unsigned char *input, 489 unsigned int inputLen) 490 { 491 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 492 return SECFailure; 493 return (vector->p_DES_Decrypt)(cx, output, outputLen, maxOutputLen, input, 494 inputLen); 495 } 496 SEEDContext * 497 SEED_CreateContext(const unsigned char *key, const unsigned char *iv, 498 int mode, PRBool encrypt) 499 { 500 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 501 return NULL; 502 return (vector->p_SEED_CreateContext)(key, iv, mode, encrypt); 503 } 504 505 void 506 SEED_DestroyContext(SEEDContext *cx, PRBool freeit) 507 { 508 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 509 return; 510 (vector->p_SEED_DestroyContext)(cx, freeit); 511 } 512 513 SECStatus 514 SEED_Encrypt(SEEDContext *cx, unsigned char *output, unsigned int *outputLen, 515 unsigned int maxOutputLen, const unsigned char *input, 516 unsigned int inputLen) 517 { 518 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 519 return SECFailure; 520 return (vector->p_SEED_Encrypt)(cx, output, outputLen, maxOutputLen, input, 521 inputLen); 522 } 523 524 SECStatus 525 SEED_Decrypt(SEEDContext *cx, unsigned char *output, unsigned int *outputLen, 526 unsigned int maxOutputLen, const unsigned char *input, 527 unsigned int inputLen) 528 { 529 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 530 return SECFailure; 531 return (vector->p_SEED_Decrypt)(cx, output, outputLen, maxOutputLen, input, 532 inputLen); 533 } 534 535 AESContext * 536 AES_CreateContext(const unsigned char *key, const unsigned char *iv, 537 int mode, int encrypt, 538 unsigned int keylen, unsigned int blocklen) 539 { 540 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 541 return NULL; 542 return (vector->p_AES_CreateContext)(key, iv, mode, encrypt, keylen, 543 blocklen); 544 } 545 546 void 547 AES_DestroyContext(AESContext *cx, PRBool freeit) 548 { 549 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 550 return ; 551 (vector->p_AES_DestroyContext)(cx, freeit); 552 } 553 554 SECStatus 555 AES_Encrypt(AESContext *cx, unsigned char *output, 556 unsigned int *outputLen, unsigned int maxOutputLen, 557 const unsigned char *input, unsigned int inputLen) 558 { 559 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 560 return SECFailure; 561 return (vector->p_AES_Encrypt)(cx, output, outputLen, maxOutputLen, 562 input, inputLen); 563 } 564 565 SECStatus 566 AES_Decrypt(AESContext *cx, unsigned char *output, 567 unsigned int *outputLen, unsigned int maxOutputLen, 568 const unsigned char *input, unsigned int inputLen) 569 { 570 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 571 return SECFailure; 572 return (vector->p_AES_Decrypt)(cx, output, outputLen, maxOutputLen, 573 input, inputLen); 574 } 575 576 SECStatus 577 MD5_Hash(unsigned char *dest, const char *src) 578 { 579 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 580 return SECFailure; 581 return (vector->p_MD5_Hash)(dest, src); 582 } 583 584 SECStatus 585 MD5_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length) 586 { 587 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 588 return SECFailure; 589 return (vector->p_MD5_HashBuf)(dest, src, src_length); 590 } 591 592 MD5Context * 593 MD5_NewContext(void) 594 { 595 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 596 return NULL; 597 return (vector->p_MD5_NewContext)(); 598 } 599 600 void 601 MD5_DestroyContext(MD5Context *cx, PRBool freeit) 602 { 603 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 604 return; 605 (vector->p_MD5_DestroyContext)(cx, freeit); 606 } 607 608 void 609 MD5_Begin(MD5Context *cx) 610 { 611 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 612 return; 613 (vector->p_MD5_Begin)(cx); 614 } 615 616 void 617 MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen) 618 { 619 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 620 return; 621 (vector->p_MD5_Update)(cx, input, inputLen); 622 } 623 624 void 625 MD5_End(MD5Context *cx, unsigned char *digest, 626 unsigned int *digestLen, unsigned int maxDigestLen) 627 { 628 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 629 return; 630 (vector->p_MD5_End)(cx, digest, digestLen, maxDigestLen); 631 } 632 633 unsigned int 634 MD5_FlattenSize(MD5Context *cx) 635 { 636 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 637 return 0; 638 return (vector->p_MD5_FlattenSize)(cx); 639 } 640 641 SECStatus 642 MD5_Flatten(MD5Context *cx,unsigned char *space) 643 { 644 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 645 return SECFailure; 646 return (vector->p_MD5_Flatten)(cx, space); 647 } 648 649 MD5Context * 650 MD5_Resurrect(unsigned char *space, void *arg) 651 { 652 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 653 return NULL; 654 return (vector->p_MD5_Resurrect)(space, arg); 655 } 656 657 void 658 MD5_TraceState(MD5Context *cx) 659 { 660 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 661 return ; 662 (vector->p_MD5_TraceState)(cx); 663 } 664 665 SECStatus 666 MD2_Hash(unsigned char *dest, const char *src) 667 { 668 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 669 return SECFailure; 670 return (vector->p_MD2_Hash)(dest, src); 671 } 672 673 MD2Context * 674 MD2_NewContext(void) 675 { 676 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 677 return NULL; 678 return (vector->p_MD2_NewContext)(); 679 } 680 681 void 682 MD2_DestroyContext(MD2Context *cx, PRBool freeit) 683 { 684 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 685 return ; 686 (vector->p_MD2_DestroyContext)(cx, freeit); 687 } 688 689 void 690 MD2_Begin(MD2Context *cx) 691 { 692 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 693 return ; 694 (vector->p_MD2_Begin)(cx); 695 } 696 697 void 698 MD2_Update(MD2Context *cx, const unsigned char *input, unsigned int inputLen) 699 { 700 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 701 return ; 702 (vector->p_MD2_Update)(cx, input, inputLen); 703 } 704 705 void 706 MD2_End(MD2Context *cx, unsigned char *digest, 707 unsigned int *digestLen, unsigned int maxDigestLen) 708 { 709 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 710 return ; 711 (vector->p_MD2_End)(cx, digest, digestLen, maxDigestLen); 712 } 713 714 unsigned int 715 MD2_FlattenSize(MD2Context *cx) 716 { 717 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 718 return 0; 719 return (vector->p_MD2_FlattenSize)(cx); 720 } 721 722 SECStatus 723 MD2_Flatten(MD2Context *cx,unsigned char *space) 724 { 725 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 726 return SECFailure; 727 return (vector->p_MD2_Flatten)(cx, space); 728 } 729 730 MD2Context * 731 MD2_Resurrect(unsigned char *space, void *arg) 732 { 733 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 734 return NULL; 735 return (vector->p_MD2_Resurrect)(space, arg); 736 } 737 738 739 SECStatus 740 SHA1_Hash(unsigned char *dest, const char *src) 741 { 742 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 743 return SECFailure; 744 return (vector->p_SHA1_Hash)(dest, src); 745 } 746 747 SECStatus 748 SHA1_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length) 749 { 750 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 751 return SECFailure; 752 return (vector->p_SHA1_HashBuf)(dest, src, src_length); 753 } 754 755 SHA1Context * 756 SHA1_NewContext(void) 757 { 758 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 759 return NULL; 760 return (vector->p_SHA1_NewContext)(); 761 } 762 763 void 764 SHA1_DestroyContext(SHA1Context *cx, PRBool freeit) 765 { 766 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 767 return ; 768 (vector->p_SHA1_DestroyContext)(cx, freeit); 769 } 770 771 void 772 SHA1_Begin(SHA1Context *cx) 773 { 774 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 775 return ; 776 (vector->p_SHA1_Begin)(cx); 777 } 778 779 void 780 SHA1_Update(SHA1Context *cx, const unsigned char *input, 781 unsigned int inputLen) 782 { 783 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 784 return ; 785 (vector->p_SHA1_Update)(cx, input, inputLen); 786 } 787 788 void 789 SHA1_End(SHA1Context *cx, unsigned char *digest, 790 unsigned int *digestLen, unsigned int maxDigestLen) 791 { 792 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 793 return ; 794 (vector->p_SHA1_End)(cx, digest, digestLen, maxDigestLen); 795 } 796 797 void 798 SHA1_TraceState(SHA1Context *cx) 799 { 800 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 801 return ; 802 (vector->p_SHA1_TraceState)(cx); 803 } 804 805 unsigned int 806 SHA1_FlattenSize(SHA1Context *cx) 807 { 808 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 809 return 0; 810 return (vector->p_SHA1_FlattenSize)(cx); 811 } 812 813 SECStatus 814 SHA1_Flatten(SHA1Context *cx,unsigned char *space) 815 { 816 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 817 return SECFailure; 818 return (vector->p_SHA1_Flatten)(cx, space); 819 } 820 821 SHA1Context * 822 SHA1_Resurrect(unsigned char *space, void *arg) 823 { 824 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 825 return NULL; 826 return (vector->p_SHA1_Resurrect)(space, arg); 827 } 828 829 SECStatus 830 RNG_RNGInit(void) 831 { 832 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 833 return SECFailure; 834 return (vector->p_RNG_RNGInit)(); 835 } 836 837 SECStatus 838 RNG_RandomUpdate(const void *data, size_t bytes) 839 { 840 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 841 return SECFailure; 842 return (vector->p_RNG_RandomUpdate)(data, bytes); 843 } 844 845 SECStatus 846 RNG_GenerateGlobalRandomBytes(void *dest, size_t len) 847 { 848 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 849 return SECFailure; 850 return (vector->p_RNG_GenerateGlobalRandomBytes)(dest, len); 851 } 852 853 void 854 RNG_RNGShutdown(void) 855 { 856 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 857 return ; 858 (vector->p_RNG_RNGShutdown)(); 859 } 860 861 SECStatus 862 PQG_ParamGen(unsigned int j, PQGParams **pParams, PQGVerify **pVfy) 863 { 864 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 865 return SECFailure; 866 return (vector->p_PQG_ParamGen)(j, pParams, pVfy); 867 } 868 869 SECStatus 870 PQG_ParamGenSeedLen( unsigned int j, unsigned int seedBytes, 871 PQGParams **pParams, PQGVerify **pVfy) 872 { 873 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 874 return SECFailure; 875 return (vector->p_PQG_ParamGenSeedLen)(j, seedBytes, pParams, pVfy); 876 } 877 878 SECStatus 879 PQG_VerifyParams(const PQGParams *params, const PQGVerify *vfy, 880 SECStatus *result) 881 { 882 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 883 return SECFailure; 884 return (vector->p_PQG_VerifyParams)(params, vfy, result); 885 } 886 887 void 888 PQG_DestroyParams(PQGParams *params) 889 { 890 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 891 return; 892 (vector->p_PQG_DestroyParams)(params); 893 } 894 895 void 896 PQG_DestroyVerify(PQGVerify *vfy) 897 { 898 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 899 return; 900 (vector->p_PQG_DestroyVerify)(vfy); 901 } 902 903 void 904 BL_Cleanup(void) 905 { 906 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 907 return; 908 (vector->p_BL_Cleanup)(); 909 } 910 911 void 912 BL_Unload(void) 913 { 914 /* This function is not thread-safe, but doesn't need to be, because it is 915 * only called from functions that are also defined as not thread-safe, 916 * namely C_Finalize in softoken, and the SSL bypass shutdown callback called 917 * from NSS_Shutdown. */ 918 char *disableUnload = NULL; 919 vector = NULL; 920 /* If an SSL socket is configured with SSL_BYPASS_PKCS11, but the application 921 * never does a handshake on it, BL_Unload will be called even though freebl 922 * was never loaded. So, don't assert blLib. */ 923 if (blLib) { 924 disableUnload = PR_GetEnv("NSS_DISABLE_UNLOAD"); 925 if (!disableUnload) { 926 PRStatus status = PR_UnloadLibrary(blLib); 927 PORT_Assert(PR_SUCCESS == status); 928 } 929 blLib = NULL; 930 } 931 loadFreeBLOnce = pristineCallOnce; 932 } 933 934 /* ============== New for 3.003 =============================== */ 935 936 SECStatus 937 SHA256_Hash(unsigned char *dest, const char *src) 938 { 939 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 940 return SECFailure; 941 return (vector->p_SHA256_Hash)(dest, src); 942 } 943 944 SECStatus 945 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length) 946 { 947 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 948 return SECFailure; 949 return (vector->p_SHA256_HashBuf)(dest, src, src_length); 950 } 951 952 SHA256Context * 953 SHA256_NewContext(void) 954 { 955 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 956 return NULL; 957 return (vector->p_SHA256_NewContext)(); 958 } 959 960 void 961 SHA256_DestroyContext(SHA256Context *cx, PRBool freeit) 962 { 963 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 964 return ; 965 (vector->p_SHA256_DestroyContext)(cx, freeit); 966 } 967 968 void 969 SHA256_Begin(SHA256Context *cx) 970 { 971 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 972 return ; 973 (vector->p_SHA256_Begin)(cx); 974 } 975 976 void 977 SHA256_Update(SHA256Context *cx, const unsigned char *input, 978 unsigned int inputLen) 979 { 980 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 981 return ; 982 (vector->p_SHA256_Update)(cx, input, inputLen); 983 } 984 985 void 986 SHA256_End(SHA256Context *cx, unsigned char *digest, 987 unsigned int *digestLen, unsigned int maxDigestLen) 988 { 989 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 990 return ; 991 (vector->p_SHA256_End)(cx, digest, digestLen, maxDigestLen); 992 } 993 994 void 995 SHA256_TraceState(SHA256Context *cx) 996 { 997 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 998 return ; 999 (vector->p_SHA256_TraceState)(cx); 1000 } 1001 1002 unsigned int 1003 SHA256_FlattenSize(SHA256Context *cx) 1004 { 1005 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1006 return 0; 1007 return (vector->p_SHA256_FlattenSize)(cx); 1008 } 1009 1010 SECStatus 1011 SHA256_Flatten(SHA256Context *cx,unsigned char *space) 1012 { 1013 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1014 return SECFailure; 1015 return (vector->p_SHA256_Flatten)(cx, space); 1016 } 1017 1018 SHA256Context * 1019 SHA256_Resurrect(unsigned char *space, void *arg) 1020 { 1021 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1022 return NULL; 1023 return (vector->p_SHA256_Resurrect)(space, arg); 1024 } 1025 1026 SECStatus 1027 SHA512_Hash(unsigned char *dest, const char *src) 1028 { 1029 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1030 return SECFailure; 1031 return (vector->p_SHA512_Hash)(dest, src); 1032 } 1033 1034 SECStatus 1035 SHA512_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length) 1036 { 1037 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1038 return SECFailure; 1039 return (vector->p_SHA512_HashBuf)(dest, src, src_length); 1040 } 1041 1042 SHA512Context * 1043 SHA512_NewContext(void) 1044 { 1045 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1046 return NULL; 1047 return (vector->p_SHA512_NewContext)(); 1048 } 1049 1050 void 1051 SHA512_DestroyContext(SHA512Context *cx, PRBool freeit) 1052 { 1053 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1054 return ; 1055 (vector->p_SHA512_DestroyContext)(cx, freeit); 1056 } 1057 1058 void 1059 SHA512_Begin(SHA512Context *cx) 1060 { 1061 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1062 return ; 1063 (vector->p_SHA512_Begin)(cx); 1064 } 1065 1066 void 1067 SHA512_Update(SHA512Context *cx, const unsigned char *input, 1068 unsigned int inputLen) 1069 { 1070 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1071 return ; 1072 (vector->p_SHA512_Update)(cx, input, inputLen); 1073 } 1074 1075 void 1076 SHA512_End(SHA512Context *cx, unsigned char *digest, 1077 unsigned int *digestLen, unsigned int maxDigestLen) 1078 { 1079 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1080 return ; 1081 (vector->p_SHA512_End)(cx, digest, digestLen, maxDigestLen); 1082 } 1083 1084 void 1085 SHA512_TraceState(SHA512Context *cx) 1086 { 1087 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1088 return ; 1089 (vector->p_SHA512_TraceState)(cx); 1090 } 1091 1092 unsigned int 1093 SHA512_FlattenSize(SHA512Context *cx) 1094 { 1095 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1096 return 0; 1097 return (vector->p_SHA512_FlattenSize)(cx); 1098 } 1099 1100 SECStatus 1101 SHA512_Flatten(SHA512Context *cx,unsigned char *space) 1102 { 1103 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1104 return SECFailure; 1105 return (vector->p_SHA512_Flatten)(cx, space); 1106 } 1107 1108 SHA512Context * 1109 SHA512_Resurrect(unsigned char *space, void *arg) 1110 { 1111 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1112 return NULL; 1113 return (vector->p_SHA512_Resurrect)(space, arg); 1114 } 1115 1116 1117 SECStatus 1118 SHA384_Hash(unsigned char *dest, const char *src) 1119 { 1120 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1121 return SECFailure; 1122 return (vector->p_SHA384_Hash)(dest, src); 1123 } 1124 1125 SECStatus 1126 SHA384_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length) 1127 { 1128 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1129 return SECFailure; 1130 return (vector->p_SHA384_HashBuf)(dest, src, src_length); 1131 } 1132 1133 SHA384Context * 1134 SHA384_NewContext(void) 1135 { 1136 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1137 return NULL; 1138 return (vector->p_SHA384_NewContext)(); 1139 } 1140 1141 void 1142 SHA384_DestroyContext(SHA384Context *cx, PRBool freeit) 1143 { 1144 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1145 return ; 1146 (vector->p_SHA384_DestroyContext)(cx, freeit); 1147 } 1148 1149 void 1150 SHA384_Begin(SHA384Context *cx) 1151 { 1152 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1153 return ; 1154 (vector->p_SHA384_Begin)(cx); 1155 } 1156 1157 void 1158 SHA384_Update(SHA384Context *cx, const unsigned char *input, 1159 unsigned int inputLen) 1160 { 1161 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1162 return ; 1163 (vector->p_SHA384_Update)(cx, input, inputLen); 1164 } 1165 1166 void 1167 SHA384_End(SHA384Context *cx, unsigned char *digest, 1168 unsigned int *digestLen, unsigned int maxDigestLen) 1169 { 1170 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1171 return ; 1172 (vector->p_SHA384_End)(cx, digest, digestLen, maxDigestLen); 1173 } 1174 1175 void 1176 SHA384_TraceState(SHA384Context *cx) 1177 { 1178 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1179 return ; 1180 (vector->p_SHA384_TraceState)(cx); 1181 } 1182 1183 unsigned int 1184 SHA384_FlattenSize(SHA384Context *cx) 1185 { 1186 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1187 return 0; 1188 return (vector->p_SHA384_FlattenSize)(cx); 1189 } 1190 1191 SECStatus 1192 SHA384_Flatten(SHA384Context *cx,unsigned char *space) 1193 { 1194 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1195 return SECFailure; 1196 return (vector->p_SHA384_Flatten)(cx, space); 1197 } 1198 1199 SHA384Context * 1200 SHA384_Resurrect(unsigned char *space, void *arg) 1201 { 1202 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1203 return NULL; 1204 return (vector->p_SHA384_Resurrect)(space, arg); 1205 } 1206 1207 1208 AESKeyWrapContext * 1209 AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv, 1210 int encrypt, unsigned int keylen) 1211 { 1212 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1213 return NULL; 1214 return vector->p_AESKeyWrap_CreateContext(key, iv, encrypt, keylen); 1215 } 1216 1217 void 1218 AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit) 1219 { 1220 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1221 return; 1222 vector->p_AESKeyWrap_DestroyContext(cx, freeit); 1223 } 1224 1225 SECStatus 1226 AESKeyWrap_Encrypt(AESKeyWrapContext *cx, unsigned char *output, 1227 unsigned int *outputLen, unsigned int maxOutputLen, 1228 const unsigned char *input, unsigned int inputLen) 1229 { 1230 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1231 return SECFailure; 1232 return vector->p_AESKeyWrap_Encrypt(cx, output, outputLen, maxOutputLen, 1233 input, inputLen); 1234 } 1235 SECStatus 1236 AESKeyWrap_Decrypt(AESKeyWrapContext *cx, unsigned char *output, 1237 unsigned int *outputLen, unsigned int maxOutputLen, 1238 const unsigned char *input, unsigned int inputLen) 1239 { 1240 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1241 return SECFailure; 1242 return vector->p_AESKeyWrap_Decrypt(cx, output, outputLen, maxOutputLen, 1243 input, inputLen); 1244 } 1245 1246 PRBool 1247 BLAPI_SHVerify(const char *name, PRFuncPtr addr) 1248 { 1249 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1250 return PR_FALSE; 1251 return vector->p_BLAPI_SHVerify(name, addr); 1252 } 1253 1254 /* 1255 * The Caller is expected to pass NULL as the name, which will 1256 * trigger the p_BLAPI_VerifySelf() to return 'TRUE'. If we really loaded 1257 * from a shared library, BLAPI_VerifySelf will get pick up the real name 1258 * from the static set in freebl_LoadDSO( void ) 1259 */ 1260 PRBool 1261 BLAPI_VerifySelf(const char *name) 1262 { 1263 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1264 return PR_FALSE; 1265 return vector->p_BLAPI_VerifySelf(libraryName); 1266 } 1267 1268 /* ============== New for 3.006 =============================== */ 1269 1270 SECStatus 1271 EC_NewKey(ECParams * params, ECPrivateKey ** privKey) 1272 { 1273 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1274 return SECFailure; 1275 return (vector->p_EC_NewKey)( params, privKey ); 1276 } 1277 1278 SECStatus 1279 EC_NewKeyFromSeed(ECParams * params, ECPrivateKey ** privKey, 1280 const unsigned char *seed, int seedlen) 1281 { 1282 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1283 return SECFailure; 1284 return (vector->p_EC_NewKeyFromSeed)( params, privKey, seed, seedlen ); 1285 } 1286 1287 SECStatus 1288 EC_ValidatePublicKey(ECParams * params, SECItem * publicValue) 1289 { 1290 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1291 return SECFailure; 1292 return (vector->p_EC_ValidatePublicKey)( params, publicValue ); 1293 } 1294 1295 SECStatus 1296 ECDH_Derive(SECItem * publicValue, ECParams * params, SECItem * privateValue, 1297 PRBool withCofactor, SECItem * derivedSecret) 1298 { 1299 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1300 return SECFailure; 1301 return (vector->p_ECDH_Derive)( publicValue, params, privateValue, 1302 withCofactor, derivedSecret ); 1303 } 1304 1305 SECStatus 1306 ECDSA_SignDigest(ECPrivateKey * key, SECItem * signature, 1307 const SECItem * digest) 1308 { 1309 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1310 return SECFailure; 1311 return (vector->p_ECDSA_SignDigest)( key, signature, digest ); 1312 } 1313 1314 SECStatus 1315 ECDSA_VerifyDigest(ECPublicKey * key, const SECItem * signature, 1316 const SECItem * digest) 1317 { 1318 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1319 return SECFailure; 1320 return (vector->p_ECDSA_VerifyDigest)( key, signature, digest ); 1321 } 1322 1323 SECStatus 1324 ECDSA_SignDigestWithSeed(ECPrivateKey * key, SECItem * signature, 1325 const SECItem * digest, const unsigned char *seed, const int seedlen) 1326 { 1327 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1328 return SECFailure; 1329 return (vector->p_ECDSA_SignDigestWithSeed)( key, signature, digest, 1330 seed, seedlen ); 1331 } 1332 1333 /* ============== New for 3.008 =============================== */ 1334 1335 AESContext * 1336 AES_AllocateContext(void) 1337 { 1338 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1339 return NULL; 1340 return (vector->p_AES_AllocateContext)(); 1341 } 1342 1343 AESKeyWrapContext * 1344 AESKeyWrap_AllocateContext(void) 1345 { 1346 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1347 return NULL; 1348 return (vector->p_AESKeyWrap_AllocateContext)(); 1349 } 1350 1351 DESContext * 1352 DES_AllocateContext(void) 1353 { 1354 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1355 return NULL; 1356 return (vector->p_DES_AllocateContext)(); 1357 } 1358 1359 RC2Context * 1360 RC2_AllocateContext(void) 1361 { 1362 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1363 return NULL; 1364 return (vector->p_RC2_AllocateContext)(); 1365 } 1366 1367 RC4Context * 1368 RC4_AllocateContext(void) 1369 { 1370 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1371 return NULL; 1372 return (vector->p_RC4_AllocateContext)(); 1373 } 1374 1375 SECStatus 1376 AES_InitContext(AESContext *cx, const unsigned char *key, 1377 unsigned int keylen, const unsigned char *iv, int mode, 1378 unsigned int encrypt, unsigned int blocklen) 1379 { 1380 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1381 return SECFailure; 1382 return (vector->p_AES_InitContext)(cx, key, keylen, iv, mode, encrypt, 1383 blocklen); 1384 } 1385 1386 SECStatus 1387 AESKeyWrap_InitContext(AESKeyWrapContext *cx, const unsigned char *key, 1388 unsigned int keylen, const unsigned char *iv, int mode, 1389 unsigned int encrypt, unsigned int blocklen) 1390 { 1391 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1392 return SECFailure; 1393 return (vector->p_AESKeyWrap_InitContext)(cx, key, keylen, iv, mode, 1394 encrypt, blocklen); 1395 } 1396 1397 SECStatus 1398 DES_InitContext(DESContext *cx, const unsigned char *key, 1399 unsigned int keylen, const unsigned char *iv, int mode, 1400 unsigned int encrypt, unsigned int xtra) 1401 { 1402 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1403 return SECFailure; 1404 return (vector->p_DES_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra); 1405 } 1406 1407 SECStatus 1408 SEED_InitContext(SEEDContext *cx, const unsigned char *key, 1409 unsigned int keylen, const unsigned char *iv, int mode, 1410 unsigned int encrypt, unsigned int xtra) 1411 { 1412 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1413 return SECFailure; 1414 return (vector->p_SEED_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra); 1415 } 1416 1417 SECStatus 1418 RC2_InitContext(RC2Context *cx, const unsigned char *key, 1419 unsigned int keylen, const unsigned char *iv, int mode, 1420 unsigned int effectiveKeyLen, unsigned int xtra) 1421 { 1422 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1423 return SECFailure; 1424 return (vector->p_RC2_InitContext)(cx, key, keylen, iv, mode, 1425 effectiveKeyLen, xtra); 1426 } 1427 1428 SECStatus 1429 RC4_InitContext(RC4Context *cx, const unsigned char *key, 1430 unsigned int keylen, const unsigned char *x1, int x2, 1431 unsigned int x3, unsigned int x4) 1432 { 1433 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1434 return SECFailure; 1435 return (vector->p_RC4_InitContext)(cx, key, keylen, x1, x2, x3, x4); 1436 } 1437 1438 void 1439 MD2_Clone(MD2Context *dest, MD2Context *src) 1440 { 1441 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1442 return; 1443 (vector->p_MD2_Clone)(dest, src); 1444 } 1445 1446 void 1447 MD5_Clone(MD5Context *dest, MD5Context *src) 1448 { 1449 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1450 return; 1451 (vector->p_MD5_Clone)(dest, src); 1452 } 1453 1454 void 1455 SHA1_Clone(SHA1Context *dest, SHA1Context *src) 1456 { 1457 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1458 return; 1459 (vector->p_SHA1_Clone)(dest, src); 1460 } 1461 1462 void 1463 SHA256_Clone(SHA256Context *dest, SHA256Context *src) 1464 { 1465 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1466 return; 1467 (vector->p_SHA256_Clone)(dest, src); 1468 } 1469 1470 void 1471 SHA384_Clone(SHA384Context *dest, SHA384Context *src) 1472 { 1473 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1474 return; 1475 (vector->p_SHA384_Clone)(dest, src); 1476 } 1477 1478 void 1479 SHA512_Clone(SHA512Context *dest, SHA512Context *src) 1480 { 1481 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1482 return; 1483 (vector->p_SHA512_Clone)(dest, src); 1484 } 1485 1486 SECStatus 1487 TLS_PRF(const SECItem *secret, const char *label, 1488 SECItem *seed, SECItem *result, PRBool isFIPS) 1489 { 1490 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1491 return SECFailure; 1492 return (vector->p_TLS_PRF)(secret, label, seed, result, isFIPS); 1493 } 1494 1495 const SECHashObject * 1496 HASH_GetRawHashObject(HASH_HashType hashType) 1497 { 1498 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1499 return NULL; 1500 return (vector->p_HASH_GetRawHashObject)(hashType); 1501 } 1502 1503 1504 void 1505 HMAC_Destroy(HMACContext *cx, PRBool freeit) 1506 { 1507 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1508 return; 1509 (vector->p_HMAC_Destroy)(cx, freeit); 1510 } 1511 1512 HMACContext * 1513 HMAC_Create(const SECHashObject *hashObj, const unsigned char *secret, 1514 unsigned int secret_len, PRBool isFIPS) 1515 { 1516 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1517 return NULL; 1518 return (vector->p_HMAC_Create)(hashObj, secret, secret_len, isFIPS); 1519 } 1520 1521 SECStatus 1522 HMAC_Init(HMACContext *cx, const SECHashObject *hashObj, 1523 const unsigned char *secret, unsigned int secret_len, PRBool isFIPS) 1524 { 1525 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1526 return SECFailure; 1527 return (vector->p_HMAC_Init)(cx, hashObj, secret, secret_len, isFIPS); 1528 } 1529 1530 void 1531 HMAC_Begin(HMACContext *cx) 1532 { 1533 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1534 return; 1535 (vector->p_HMAC_Begin)(cx); 1536 } 1537 1538 void 1539 HMAC_Update(HMACContext *cx, const unsigned char *data, unsigned int data_len) 1540 { 1541 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1542 return; 1543 (vector->p_HMAC_Update)(cx, data, data_len); 1544 } 1545 1546 SECStatus 1547 HMAC_Finish(HMACContext *cx, unsigned char *result, unsigned int *result_len, 1548 unsigned int max_result_len) 1549 { 1550 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1551 return SECFailure; 1552 return (vector->p_HMAC_Finish)(cx, result, result_len, max_result_len); 1553 } 1554 1555 HMACContext * 1556 HMAC_Clone(HMACContext *cx) 1557 { 1558 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1559 return NULL; 1560 return (vector->p_HMAC_Clone)(cx); 1561 } 1562 1563 void 1564 RNG_SystemInfoForRNG(void) 1565 { 1566 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1567 return ; 1568 (vector->p_RNG_SystemInfoForRNG)(); 1569 1570 } 1571 1572 SECStatus 1573 FIPS186Change_GenerateX(unsigned char *XKEY, const unsigned char *XSEEDj, 1574 unsigned char *x_j) 1575 { 1576 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1577 return SECFailure; 1578 return (vector->p_FIPS186Change_GenerateX)(XKEY, XSEEDj, x_j); 1579 } 1580 1581 SECStatus 1582 FIPS186Change_ReduceModQForDSA(const unsigned char *w, 1583 const unsigned char *q, 1584 unsigned char *xj) 1585 { 1586 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1587 return SECFailure; 1588 return (vector->p_FIPS186Change_ReduceModQForDSA)(w, q, xj); 1589 } 1590 1591 /* === new for Camellia === */ 1592 SECStatus 1593 Camellia_InitContext(CamelliaContext *cx, const unsigned char *key, 1594 unsigned int keylen, const unsigned char *iv, int mode, 1595 unsigned int encrypt, unsigned int unused) 1596 { 1597 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1598 return SECFailure; 1599 return (vector->p_Camellia_InitContext)(cx, key, keylen, iv, mode, encrypt, 1600 unused); 1601 } 1602 1603 CamelliaContext * 1604 Camellia_AllocateContext(void) 1605 { 1606 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1607 return NULL; 1608 return (vector->p_Camellia_AllocateContext)(); 1609 } 1610 1611 1612 CamelliaContext * 1613 Camellia_CreateContext(const unsigned char *key, const unsigned char *iv, 1614 int mode, int encrypt, 1615 unsigned int keylen) 1616 { 1617 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1618 return NULL; 1619 return (vector->p_Camellia_CreateContext)(key, iv, mode, encrypt, keylen); 1620 } 1621 1622 void 1623 Camellia_DestroyContext(CamelliaContext *cx, PRBool freeit) 1624 { 1625 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1626 return ; 1627 (vector->p_Camellia_DestroyContext)(cx, freeit); 1628 } 1629 1630 SECStatus 1631 Camellia_Encrypt(CamelliaContext *cx, unsigned char *output, 1632 unsigned int *outputLen, unsigned int maxOutputLen, 1633 const unsigned char *input, unsigned int inputLen) 1634 { 1635 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1636 return SECFailure; 1637 return (vector->p_Camellia_Encrypt)(cx, output, outputLen, maxOutputLen, 1638 input, inputLen); 1639 } 1640 1641 SECStatus 1642 Camellia_Decrypt(CamelliaContext *cx, unsigned char *output, 1643 unsigned int *outputLen, unsigned int maxOutputLen, 1644 const unsigned char *input, unsigned int inputLen) 1645 { 1646 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1647 return SECFailure; 1648 return (vector->p_Camellia_Decrypt)(cx, output, outputLen, maxOutputLen, 1649 input, inputLen); 1650 } 1651 1652 void BL_SetForkState(PRBool forked) 1653 { 1654 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1655 return; 1656 (vector->p_BL_SetForkState)(forked); 1657 } 1658 1659 SECStatus 1660 PRNGTEST_Instantiate(const PRUint8 *entropy, unsigned int entropy_len, 1661 const PRUint8 *nonce, unsigned int nonce_len, 1662 const PRUint8 *personal_string, unsigned int ps_len) 1663 { 1664 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1665 return SECFailure; 1666 return (vector->p_PRNGTEST_Instantiate)(entropy, entropy_len, 1667 nonce, nonce_len, 1668 personal_string, ps_len); 1669 } 1670 1671 SECStatus 1672 PRNGTEST_Reseed(const PRUint8 *entropy, unsigned int entropy_len, 1673 const PRUint8 *additional, unsigned int additional_len) 1674 { 1675 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1676 return SECFailure; 1677 return (vector->p_PRNGTEST_Reseed)(entropy, entropy_len, 1678 additional, additional_len); 1679 } 1680 1681 SECStatus 1682 PRNGTEST_Generate(PRUint8 *bytes, unsigned int bytes_len, 1683 const PRUint8 *additional, unsigned int additional_len) 1684 { 1685 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1686 return SECFailure; 1687 return (vector->p_PRNGTEST_Generate)(bytes, bytes_len, 1688 additional, additional_len); 1689 } 1690 1691 SECStatus 1692 PRNGTEST_Uninstantiate() 1693 { 1694 if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) 1695 return SECFailure; 1696 return (vector->p_PRNGTEST_Uninstantiate)(); 1697 } 1698 1699 1700