Back to index

lightning-sunbird  0.9+nobinonly
loader.c
Go to the documentation of this file.
00001 /*
00002  * loader.c - load platform dependent DSO containing freebl implementation.
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is the Netscape security libraries.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 2000
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 /* $Id: loader.c,v 1.26.2.4 2006/10/02 21:17:58 julien.pierre.bugs%sun.com Exp $ */
00041 
00042 #include "loader.h"
00043 #include "prmem.h"
00044 #include "prerror.h"
00045 #include "prinit.h"
00046 
00047 static const char* default_name =
00048     SHLIB_PREFIX"freebl"SHLIB_VERSION"."SHLIB_SUFFIX;
00049 
00050 /* getLibName() returns the name of the library to load. */
00051 
00052 #if defined(SOLARIS) && defined(__sparc)
00053 #include <stddef.h>
00054 #include <strings.h>
00055 #include <sys/systeminfo.h>
00056 
00057 
00058 #if defined(NSS_USE_64)
00059 
00060 const static char fpu_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
00061 const static char int_hybrid_shared_lib[] = "libfreebl_64int_3.so";
00062 const static char non_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
00063 
00064 const static char int_hybrid_isa[] = "sparcv9";
00065 const static char fpu_hybrid_isa[] = "sparcv9+vis";
00066 
00067 #else
00068 
00069 const static char fpu_hybrid_shared_lib[] = "libfreebl_32fpu_3.so";
00070 const static char int_hybrid_shared_lib[] = "libfreebl_32int64_3.so";
00071 const static char non_hybrid_shared_lib[] = "libfreebl_32int_3.so";
00072 
00073 const static char int_hybrid_isa[] = "sparcv8plus";
00074 const static char fpu_hybrid_isa[] = "sparcv8plus+vis";
00075 
00076 #endif
00077 
00078 static const char *
00079 getLibName(void)
00080 {
00081     char * found_int_hybrid;
00082     char * found_fpu_hybrid;
00083     long buflen;
00084     char buf[256];
00085 
00086     buflen = sysinfo(SI_ISALIST, buf, sizeof buf);
00087     if (buflen <= 0) 
00088        return NULL;
00089     /* The ISA list is a space separated string of names of ISAs and
00090      * ISA extensions, in order of decreasing performance.
00091      * There are two different ISAs with which NSS's crypto code can be
00092      * accelerated. If both are in the list, we take the first one.
00093      * If one is in the list, we use it, and if neither then we use
00094      * the base unaccelerated code.
00095      */
00096     found_int_hybrid = strstr(buf, int_hybrid_isa);
00097     found_fpu_hybrid = strstr(buf, fpu_hybrid_isa);
00098     if (found_fpu_hybrid && 
00099        (!found_int_hybrid ||
00100         (found_int_hybrid - found_fpu_hybrid) >= 0)) {
00101        return fpu_hybrid_shared_lib;
00102     }
00103     if (found_int_hybrid) {
00104        return int_hybrid_shared_lib;
00105     }
00106     return non_hybrid_shared_lib;
00107 }
00108 
00109 #elif defined(HPUX) && !defined(NSS_USE_64) && !defined(__ia64)
00110 /* This code tests to see if we're running on a PA2.x CPU.
00111 ** It returns true (1) if so, and false (0) otherwise.
00112 */
00113 static const char *
00114 getLibName(void)
00115 {
00116     long cpu = sysconf(_SC_CPU_VERSION);
00117     return (cpu == CPU_PA_RISC2_0) 
00118               ? "libfreebl_32fpu_3.sl"
00119                : "libfreebl_32int32_3.sl" ;
00120 }
00121 #else
00122 /* default case, for platforms/ABIs that have only one freebl shared lib. */
00123 static const char * getLibName(void) { return default_name; }
00124 #endif
00125 
00126 #ifdef XP_UNIX
00127 #include <unistd.h>
00128 
00129 #define BL_MAXSYMLINKS 20
00130 
00131 /*
00132  * If 'link' is a symbolic link, this function follows the symbolic links
00133  * and returns the pathname of the ultimate source of the symbolic links.
00134  * If 'link' is not a symbolic link, this function returns NULL.
00135  * The caller should call PR_Free to free the string returned by this
00136  * function.
00137  */
00138 static char* bl_GetOriginalPathname(const char* link)
00139 {
00140     char* resolved = NULL;
00141     char* input = NULL;
00142     PRUint32 iterations = 0;
00143     PRInt32 len = 0, retlen = 0;
00144     if (!link) {
00145         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
00146         return NULL;
00147     }
00148     len = PR_MAX(1024, strlen(link) + 1);
00149     resolved = PR_Malloc(len);
00150     input = PR_Malloc(len);
00151     if (!resolved || !input) {
00152         if (resolved) {
00153             PR_Free(resolved);
00154         }
00155         if (input) {
00156             PR_Free(input);
00157         }
00158         return NULL;
00159     }
00160     strcpy(input, link);
00161     while ( (iterations++ < BL_MAXSYMLINKS) &&
00162             ( (retlen = readlink(input, resolved, len - 1)) > 0) ) {
00163         char* tmp = input;
00164         resolved[retlen] = '\0'; /* NULL termination */
00165         input = resolved;
00166         resolved = tmp;
00167     }
00168     PR_Free(resolved);
00169     if (iterations == 1 && retlen < 0) {
00170         PR_Free(input);
00171         input = NULL;
00172     }
00173     return input;
00174 }
00175 #endif /* XP_UNIX */
00176 
00177 /*
00178  * We use PR_GetLibraryFilePathname to get the pathname of the loaded 
00179  * shared lib that contains this function, and then do a PR_LoadLibrary
00180  * with an absolute pathname for the freebl shared library.
00181  */
00182 
00183 #include "prio.h"
00184 #include "prprf.h"
00185 #include <stdio.h>
00186 #include "prsystem.h"
00187 
00188 const char* softoken=SHLIB_PREFIX"softokn"SOFTOKEN_SHLIB_VERSION"."SHLIB_SUFFIX;
00189 
00190 static PRLibrary* blLib;
00191 
00192 /*
00193  * Load the freebl library with the file name 'name' residing in the same
00194  * directory as libsoftoken, whose pathname is 'softokenPath'.
00195  */
00196 static PRLibrary *
00197 bl_LoadFreeblLibInSoftokenDir(const char *softokenPath, const char *name)
00198 {
00199     PRLibrary *dlh = NULL;
00200     char *fullName = NULL;
00201     char* c;
00202     PRLibSpec libSpec;
00203 
00204     /* Remove "libsoftokn" from the pathname and add the freebl libname */
00205     c = strrchr(softokenPath, PR_GetDirectorySeparator());
00206     if (c) {
00207         size_t softoknPathSize = 1 + c - softokenPath;
00208         fullName = (char*) PORT_Alloc(strlen(name) + softoknPathSize + 1);
00209         if (fullName) {
00210             memcpy(fullName, softokenPath, softoknPathSize);
00211             strcpy(fullName + softoknPathSize, name); 
00212 #ifdef DEBUG_LOADER
00213             PR_fprintf(PR_STDOUT, "\nAttempting to load fully-qualified %s\n", 
00214                        fullName);
00215 #endif
00216             libSpec.type = PR_LibSpec_Pathname;
00217             libSpec.value.pathname = fullName;
00218             dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
00219             PORT_Free(fullName);
00220         }
00221     }
00222     return dlh;
00223 }
00224 
00225 static PRLibrary *
00226 bl_LoadLibrary(const char *name)
00227 {
00228     PRLibrary *lib = NULL;
00229     PRFuncPtr fn_addr;
00230     char* softokenPath = NULL;
00231     PRLibSpec libSpec;
00232 
00233     /* Get the pathname for the loaded libsoftokn, i.e. /usr/lib/libsoftokn3.so
00234      * PR_GetLibraryFilePathname works with either the base library name or a
00235      * function pointer, depending on the platform. We can't query an exported
00236      * symbol such as NSC_GetFunctionList, because on some platforms we can't
00237      * find symbols in loaded implicit dependencies such as libsoftokn.
00238      * But we can just get the address of this function !
00239      */
00240     fn_addr = (PRFuncPtr) &bl_LoadLibrary;
00241     softokenPath = PR_GetLibraryFilePathname(softoken, fn_addr);
00242 
00243     if (softokenPath) {
00244         lib = bl_LoadFreeblLibInSoftokenDir(softokenPath, name);
00245 #ifdef XP_UNIX
00246         if (!lib) {
00247             /*
00248              * If softokenPath is a symbolic link, resolve the symbolic
00249              * link and try again.
00250              */
00251             char* originalSoftokenPath = bl_GetOriginalPathname(softokenPath);
00252             if (originalSoftokenPath) {
00253                 PR_Free(softokenPath);
00254                 softokenPath = originalSoftokenPath;
00255                 lib = bl_LoadFreeblLibInSoftokenDir(softokenPath, name);
00256             }
00257         }
00258 #endif
00259         PR_Free(softokenPath);
00260     }
00261     if (!lib) {
00262 #ifdef DEBUG_LOADER
00263         PR_fprintf(PR_STDOUT, "\nAttempting to load %s\n", name);
00264 #endif
00265         libSpec.type = PR_LibSpec_Pathname;
00266         libSpec.value.pathname = name;
00267         lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
00268     }
00269     if (NULL == lib) {
00270 #ifdef DEBUG_LOADER
00271         PR_fprintf(PR_STDOUT, "\nLoading failed : %s.\n", name);
00272 #endif
00273     }
00274     return lib;
00275 }
00276 
00277 #define LSB(x) ((x)&0xff)
00278 #define MSB(x) ((x)>>8)
00279 
00280 static const FREEBLVector *vector;
00281 static const char *libraryName = NULL;
00282 
00283 /* This function must be run only once. */
00284 /*  determine if hybrid platform, then actually load the DSO. */
00285 static PRStatus
00286 freebl_LoadDSO( void ) 
00287 {
00288   PRLibrary *  handle;
00289   const char * name = getLibName();
00290 
00291   if (!name) {
00292     PR_SetError(PR_LOAD_LIBRARY_ERROR, 0);
00293     return PR_FAILURE;
00294   }
00295 
00296   handle = bl_LoadLibrary(name);
00297   if (handle) {
00298     PRFuncPtr address = PR_FindFunctionSymbol(handle, "FREEBL_GetVector");
00299     PRStatus status;
00300     if (address) {
00301       FREEBLGetVectorFn  * getVector = (FREEBLGetVectorFn *)address;
00302       const FREEBLVector * dsoVector = getVector();
00303       if (dsoVector) {
00304        unsigned short dsoVersion = dsoVector->version;
00305        unsigned short  myVersion = FREEBL_VERSION;
00306        if (MSB(dsoVersion) == MSB(myVersion) && 
00307            LSB(dsoVersion) >= LSB(myVersion) &&
00308            dsoVector->length >= sizeof(FREEBLVector)) {
00309           vector = dsoVector;
00310          libraryName = name;
00311          blLib = handle;
00312          return PR_SUCCESS;
00313        }
00314       }
00315     }
00316     status = PR_UnloadLibrary(handle);
00317     PORT_Assert(PR_SUCCESS == status);
00318   }
00319   return PR_FAILURE;
00320 }
00321 
00322 static const PRCallOnceType pristineCallOnce;
00323 static PRCallOnceType loadFreeBLOnce;
00324 
00325 static PRStatus
00326 freebl_RunLoaderOnce( void )
00327 {
00328   PRStatus status;
00329 
00330   status = PR_CallOnce(&loadFreeBLOnce, &freebl_LoadDSO);
00331   return status;
00332 }
00333 
00334 
00335 RSAPrivateKey * 
00336 RSA_NewKey(int keySizeInBits, SECItem * publicExponent)
00337 {
00338   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00339       return NULL;
00340   return (vector->p_RSA_NewKey)(keySizeInBits, publicExponent);
00341 }
00342 
00343 SECStatus 
00344 RSA_PublicKeyOp(RSAPublicKey *   key,
00345                              unsigned char *  output,
00346                              const unsigned char *  input)
00347 {
00348   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00349       return SECFailure;
00350   return (vector->p_RSA_PublicKeyOp)(key, output, input);
00351 }
00352 
00353 SECStatus 
00354 RSA_PrivateKeyOp(RSAPrivateKey *  key,
00355                               unsigned char *  output,
00356                               const unsigned char *  input)
00357 {
00358   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00359       return SECFailure;
00360   return (vector->p_RSA_PrivateKeyOp)(key, output, input);
00361 }
00362 
00363 SECStatus
00364 RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey *key,
00365                               unsigned char *output,
00366                               const unsigned char *input)
00367 {
00368   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00369       return SECFailure;
00370   return (vector->p_RSA_PrivateKeyOpDoubleChecked)(key, output, input);
00371 }
00372 
00373 SECStatus
00374 RSA_PrivateKeyCheck(RSAPrivateKey *key)
00375 {
00376   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00377       return SECFailure;
00378   return (vector->p_RSA_PrivateKeyCheck)(key);
00379 }
00380 
00381 SECStatus 
00382 DSA_NewKey(const PQGParams * params, DSAPrivateKey ** privKey)
00383 {
00384   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00385       return SECFailure;
00386   return (vector->p_DSA_NewKey)(params, privKey);
00387 }
00388 
00389 SECStatus 
00390 DSA_SignDigest(DSAPrivateKey * key, SECItem * signature, const SECItem * digest)
00391 {
00392   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00393       return SECFailure;
00394   return (vector->p_DSA_SignDigest)( key,  signature,  digest);
00395 }
00396 
00397 SECStatus 
00398 DSA_VerifyDigest(DSAPublicKey * key, const SECItem * signature, 
00399                  const SECItem * digest)
00400 {
00401   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00402       return SECFailure;
00403   return (vector->p_DSA_VerifyDigest)( key,  signature,  digest);
00404 }
00405 
00406 SECStatus 
00407 DSA_NewKeyFromSeed(const PQGParams *params, const unsigned char * seed,
00408                    DSAPrivateKey **privKey)
00409 {
00410   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00411       return SECFailure;
00412   return (vector->p_DSA_NewKeyFromSeed)(params,  seed, privKey);
00413 }
00414 
00415 SECStatus 
00416 DSA_SignDigestWithSeed(DSAPrivateKey * key, SECItem * signature,
00417                      const SECItem * digest, const unsigned char * seed)
00418 {
00419   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00420       return SECFailure;
00421   return (vector->p_DSA_SignDigestWithSeed)( key, signature, digest, seed);
00422 }
00423 
00424 SECStatus 
00425 DH_GenParam(int primeLen, DHParams ** params)
00426 {
00427   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00428       return SECFailure;
00429   return (vector->p_DH_GenParam)(primeLen, params);
00430 }
00431 
00432 SECStatus 
00433 DH_NewKey(DHParams * params, DHPrivateKey ** privKey)
00434 {
00435   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00436       return SECFailure;
00437   return (vector->p_DH_NewKey)( params, privKey);
00438 }
00439 
00440 SECStatus 
00441 DH_Derive(SECItem * publicValue, SECItem * prime, SECItem * privateValue, 
00442                       SECItem * derivedSecret, unsigned int maxOutBytes)
00443 {
00444   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00445       return SECFailure;
00446   return (vector->p_DH_Derive)( publicValue, prime, privateValue, 
00447                             derivedSecret, maxOutBytes);
00448 }
00449 
00450 SECStatus 
00451 KEA_Derive(SECItem *prime, SECItem *public1, SECItem *public2, 
00452           SECItem *private1, SECItem *private2, SECItem *derivedSecret)
00453 {
00454   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00455       return SECFailure;
00456   return (vector->p_KEA_Derive)(prime, public1, public2, 
00457                                private1, private2, derivedSecret);
00458 }
00459 
00460 PRBool 
00461 KEA_Verify(SECItem *Y, SECItem *prime, SECItem *subPrime)
00462 {
00463   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00464       return PR_FALSE;
00465   return (vector->p_KEA_Verify)(Y, prime, subPrime);
00466 }
00467 
00468 RC4Context *
00469 RC4_CreateContext(const unsigned char *key, int len)
00470 {
00471   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00472       return NULL;
00473   return (vector->p_RC4_CreateContext)(key, len);
00474 }
00475 
00476 void 
00477 RC4_DestroyContext(RC4Context *cx, PRBool freeit)
00478 {
00479   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00480       return;
00481   (vector->p_RC4_DestroyContext)(cx, freeit);
00482 }
00483 
00484 SECStatus 
00485 RC4_Encrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen, 
00486            unsigned int maxOutputLen, const unsigned char *input, 
00487            unsigned int inputLen)
00488 {
00489   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00490       return SECFailure;
00491   return (vector->p_RC4_Encrypt)(cx, output, outputLen, maxOutputLen, input, 
00492                                 inputLen);
00493 }
00494 
00495 SECStatus 
00496 RC4_Decrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen, 
00497            unsigned int maxOutputLen, const unsigned char *input, 
00498            unsigned int inputLen)
00499 {
00500   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00501       return SECFailure;
00502   return (vector->p_RC4_Decrypt)(cx, output, outputLen, maxOutputLen, input, 
00503                                 inputLen);
00504 }
00505 
00506 RC2Context *
00507 RC2_CreateContext(const unsigned char *key, unsigned int len,
00508                 const unsigned char *iv, int mode, unsigned effectiveKeyLen)
00509 {
00510   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00511       return NULL;
00512   return (vector->p_RC2_CreateContext)(key, len, iv, mode, effectiveKeyLen);
00513 }
00514 
00515 void 
00516 RC2_DestroyContext(RC2Context *cx, PRBool freeit)
00517 {
00518   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00519       return;
00520   (vector->p_RC2_DestroyContext)(cx, freeit);
00521 }
00522 
00523 SECStatus 
00524 RC2_Encrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen, 
00525            unsigned int maxOutputLen, const unsigned char *input, 
00526            unsigned int inputLen)
00527 {
00528   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00529       return SECFailure;
00530   return (vector->p_RC2_Encrypt)(cx, output, outputLen, maxOutputLen, input, 
00531                                 inputLen);
00532 }
00533 
00534 SECStatus 
00535 RC2_Decrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen, 
00536            unsigned int maxOutputLen, const unsigned char *input, 
00537            unsigned int inputLen)
00538 {
00539   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00540       return SECFailure;
00541   return (vector->p_RC2_Decrypt)(cx, output, outputLen, maxOutputLen, input, 
00542                                 inputLen);
00543 }
00544 
00545 RC5Context *
00546 RC5_CreateContext(const SECItem *key, unsigned int rounds,
00547                 unsigned int wordSize, const unsigned char *iv, int mode)
00548 {
00549   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00550       return NULL;
00551   return (vector->p_RC5_CreateContext)(key, rounds, wordSize, iv, mode);
00552 }
00553 
00554 void 
00555 RC5_DestroyContext(RC5Context *cx, PRBool freeit)
00556 {
00557   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00558       return;
00559   (vector->p_RC5_DestroyContext)(cx, freeit);
00560 }
00561 
00562 SECStatus 
00563 RC5_Encrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen, 
00564            unsigned int maxOutputLen, const unsigned char *input, 
00565            unsigned int inputLen)
00566 {
00567   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00568       return SECFailure;
00569   return (vector->p_RC5_Encrypt)(cx, output, outputLen, maxOutputLen, input, 
00570                              inputLen);
00571 }
00572 
00573 SECStatus 
00574 RC5_Decrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen, 
00575            unsigned int maxOutputLen, const unsigned char *input, 
00576            unsigned int inputLen)
00577 {
00578   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00579       return SECFailure;
00580   return (vector->p_RC5_Decrypt)(cx, output, outputLen, maxOutputLen, input, 
00581                                 inputLen);
00582 }
00583 
00584 DESContext *
00585 DES_CreateContext(const unsigned char *key, const unsigned char *iv,
00586                 int mode, PRBool encrypt)
00587 {
00588   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00589       return NULL;
00590   return (vector->p_DES_CreateContext)(key, iv, mode, encrypt);
00591 }
00592 
00593 void 
00594 DES_DestroyContext(DESContext *cx, PRBool freeit)
00595 {
00596   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00597       return;
00598   (vector->p_DES_DestroyContext)(cx, freeit);
00599 }
00600 
00601 SECStatus 
00602 DES_Encrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen, 
00603            unsigned int maxOutputLen, const unsigned char *input, 
00604            unsigned int inputLen)
00605 {
00606   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00607       return SECFailure;
00608   return (vector->p_DES_Encrypt)(cx, output, outputLen, maxOutputLen, input, 
00609                                 inputLen);
00610 }
00611 
00612 SECStatus 
00613 DES_Decrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen, 
00614            unsigned int maxOutputLen, const unsigned char *input, 
00615            unsigned int inputLen)
00616 {
00617   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00618       return SECFailure;
00619   return (vector->p_DES_Decrypt)(cx, output, outputLen, maxOutputLen, input, 
00620                                 inputLen);
00621 }
00622 
00623 AESContext *
00624 AES_CreateContext(const unsigned char *key, const unsigned char *iv, 
00625                   int mode, int encrypt,
00626                   unsigned int keylen, unsigned int blocklen)
00627 {
00628   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00629       return NULL;
00630   return (vector->p_AES_CreateContext)(key, iv, mode, encrypt, keylen, 
00631                                    blocklen);
00632 }
00633 
00634 void 
00635 AES_DestroyContext(AESContext *cx, PRBool freeit)
00636 {
00637   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00638       return ;
00639   (vector->p_AES_DestroyContext)(cx, freeit);
00640 }
00641 
00642 SECStatus 
00643 AES_Encrypt(AESContext *cx, unsigned char *output,
00644             unsigned int *outputLen, unsigned int maxOutputLen,
00645             const unsigned char *input, unsigned int inputLen)
00646 {
00647   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00648       return SECFailure;
00649   return (vector->p_AES_Encrypt)(cx, output, outputLen, maxOutputLen, 
00650                              input, inputLen);
00651 }
00652 
00653 SECStatus 
00654 AES_Decrypt(AESContext *cx, unsigned char *output,
00655             unsigned int *outputLen, unsigned int maxOutputLen,
00656             const unsigned char *input, unsigned int inputLen)
00657 {
00658   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00659       return SECFailure;
00660   return (vector->p_AES_Decrypt)(cx, output, outputLen, maxOutputLen, 
00661                              input, inputLen);
00662 }
00663 
00664 SECStatus 
00665 MD5_Hash(unsigned char *dest, const char *src)
00666 {
00667   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00668       return SECFailure;
00669   return (vector->p_MD5_Hash)(dest, src);
00670 }
00671 
00672 SECStatus 
00673 MD5_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
00674 {
00675   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00676       return SECFailure;
00677   return (vector->p_MD5_HashBuf)(dest, src, src_length);
00678 }
00679 
00680 MD5Context *
00681 MD5_NewContext(void)
00682 {
00683   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00684       return NULL;
00685   return (vector->p_MD5_NewContext)();
00686 }
00687 
00688 void 
00689 MD5_DestroyContext(MD5Context *cx, PRBool freeit)
00690 {
00691   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00692       return;
00693   (vector->p_MD5_DestroyContext)(cx, freeit);
00694 }
00695 
00696 void 
00697 MD5_Begin(MD5Context *cx)
00698 {
00699   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00700       return;
00701   (vector->p_MD5_Begin)(cx);
00702 }
00703 
00704 void 
00705 MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen)
00706 {
00707   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00708       return;
00709   (vector->p_MD5_Update)(cx, input, inputLen);
00710 }
00711 
00712 void 
00713 MD5_End(MD5Context *cx, unsigned char *digest,
00714                   unsigned int *digestLen, unsigned int maxDigestLen)
00715 {
00716   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00717       return;
00718   (vector->p_MD5_End)(cx, digest, digestLen, maxDigestLen);
00719 }
00720 
00721 unsigned int 
00722 MD5_FlattenSize(MD5Context *cx)
00723 {
00724   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00725       return 0;
00726   return (vector->p_MD5_FlattenSize)(cx);
00727 }
00728 
00729 SECStatus 
00730 MD5_Flatten(MD5Context *cx,unsigned char *space)
00731 {
00732   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00733       return SECFailure;
00734   return (vector->p_MD5_Flatten)(cx, space);
00735 }
00736 
00737 MD5Context * 
00738 MD5_Resurrect(unsigned char *space, void *arg)
00739 {
00740   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00741       return NULL;
00742   return (vector->p_MD5_Resurrect)(space, arg);
00743 }
00744 
00745 void 
00746 MD5_TraceState(MD5Context *cx)
00747 {
00748   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00749       return ;
00750   (vector->p_MD5_TraceState)(cx);
00751 }
00752 
00753 SECStatus 
00754 MD2_Hash(unsigned char *dest, const char *src)
00755 {
00756   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00757       return SECFailure;
00758   return (vector->p_MD2_Hash)(dest, src);
00759 }
00760 
00761 MD2Context *
00762 MD2_NewContext(void)
00763 {
00764   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00765       return NULL;
00766   return (vector->p_MD2_NewContext)();
00767 }
00768 
00769 void 
00770 MD2_DestroyContext(MD2Context *cx, PRBool freeit)
00771 {
00772   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00773       return ;
00774   (vector->p_MD2_DestroyContext)(cx, freeit);
00775 }
00776 
00777 void 
00778 MD2_Begin(MD2Context *cx)
00779 {
00780   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00781       return ;
00782   (vector->p_MD2_Begin)(cx);
00783 }
00784 
00785 void 
00786 MD2_Update(MD2Context *cx, const unsigned char *input, unsigned int inputLen)
00787 {
00788   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00789       return ;
00790   (vector->p_MD2_Update)(cx, input, inputLen);
00791 }
00792 
00793 void 
00794 MD2_End(MD2Context *cx, unsigned char *digest,
00795                   unsigned int *digestLen, unsigned int maxDigestLen)
00796 {
00797   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00798       return ;
00799   (vector->p_MD2_End)(cx, digest, digestLen, maxDigestLen);
00800 }
00801 
00802 unsigned int 
00803 MD2_FlattenSize(MD2Context *cx)
00804 {
00805   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00806       return 0;
00807   return (vector->p_MD2_FlattenSize)(cx);
00808 }
00809 
00810 SECStatus 
00811 MD2_Flatten(MD2Context *cx,unsigned char *space)
00812 {
00813   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00814       return SECFailure;
00815   return (vector->p_MD2_Flatten)(cx, space);
00816 }
00817 
00818 MD2Context * 
00819 MD2_Resurrect(unsigned char *space, void *arg)
00820 {
00821   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00822       return NULL;
00823   return (vector->p_MD2_Resurrect)(space, arg);
00824 }
00825 
00826 
00827 SECStatus 
00828 SHA1_Hash(unsigned char *dest, const char *src)
00829 {
00830   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00831       return SECFailure;
00832   return (vector->p_SHA1_Hash)(dest, src);
00833 }
00834 
00835 SECStatus 
00836 SHA1_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
00837 {
00838   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00839       return SECFailure;
00840   return (vector->p_SHA1_HashBuf)(dest, src, src_length);
00841 }
00842 
00843 SHA1Context *
00844 SHA1_NewContext(void)
00845 {
00846   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00847       return NULL;
00848   return (vector->p_SHA1_NewContext)();
00849 }
00850 
00851 void 
00852 SHA1_DestroyContext(SHA1Context *cx, PRBool freeit)
00853 {
00854   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00855       return ;
00856   (vector->p_SHA1_DestroyContext)(cx, freeit);
00857 }
00858 
00859 void 
00860 SHA1_Begin(SHA1Context *cx)
00861 {
00862   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00863       return ;
00864   (vector->p_SHA1_Begin)(cx);
00865 }
00866 
00867 void 
00868 SHA1_Update(SHA1Context *cx, const unsigned char *input,
00869                      unsigned int inputLen)
00870 {
00871   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00872       return ;
00873   (vector->p_SHA1_Update)(cx, input, inputLen);
00874 }
00875 
00876 void 
00877 SHA1_End(SHA1Context *cx, unsigned char *digest,
00878                    unsigned int *digestLen, unsigned int maxDigestLen)
00879 {
00880   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00881       return ;
00882   (vector->p_SHA1_End)(cx, digest, digestLen, maxDigestLen);
00883 }
00884 
00885 void 
00886 SHA1_TraceState(SHA1Context *cx)
00887 {
00888   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00889       return ;
00890   (vector->p_SHA1_TraceState)(cx);
00891 }
00892 
00893 unsigned int 
00894 SHA1_FlattenSize(SHA1Context *cx)
00895 {
00896   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00897       return 0;
00898   return (vector->p_SHA1_FlattenSize)(cx);
00899 }
00900 
00901 SECStatus 
00902 SHA1_Flatten(SHA1Context *cx,unsigned char *space)
00903 {
00904   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00905       return SECFailure;
00906   return (vector->p_SHA1_Flatten)(cx, space);
00907 }
00908 
00909 SHA1Context * 
00910 SHA1_Resurrect(unsigned char *space, void *arg)
00911 {
00912   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00913       return NULL;
00914   return (vector->p_SHA1_Resurrect)(space, arg);
00915 }
00916 
00917 SECStatus 
00918 RNG_RNGInit(void)
00919 {
00920   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00921       return SECFailure;
00922   return (vector->p_RNG_RNGInit)();
00923 }
00924 
00925 SECStatus 
00926 RNG_RandomUpdate(const void *data, size_t bytes)
00927 {
00928   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00929       return SECFailure;
00930   return (vector->p_RNG_RandomUpdate)(data, bytes);
00931 }
00932 
00933 SECStatus 
00934 RNG_GenerateGlobalRandomBytes(void *dest, size_t len)
00935 {
00936   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00937       return SECFailure;
00938   return (vector->p_RNG_GenerateGlobalRandomBytes)(dest, len);
00939 }
00940 
00941 void  
00942 RNG_RNGShutdown(void)
00943 {
00944   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00945       return ;
00946   (vector->p_RNG_RNGShutdown)();
00947 }
00948 
00949 SECStatus
00950 PQG_ParamGen(unsigned int j, PQGParams **pParams, PQGVerify **pVfy)
00951 {
00952   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00953       return SECFailure;
00954   return (vector->p_PQG_ParamGen)(j, pParams, pVfy); 
00955 }
00956 
00957 SECStatus
00958 PQG_ParamGenSeedLen( unsigned int j, unsigned int seedBytes, 
00959                      PQGParams **pParams, PQGVerify **pVfy)
00960 {
00961   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00962       return SECFailure;
00963   return (vector->p_PQG_ParamGenSeedLen)(j, seedBytes, pParams, pVfy);
00964 }
00965 
00966 SECStatus   
00967 PQG_VerifyParams(const PQGParams *params, const PQGVerify *vfy, 
00968                SECStatus *result)
00969 {
00970   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00971       return SECFailure;
00972   return (vector->p_PQG_VerifyParams)(params, vfy, result);
00973 }
00974 
00975 void 
00976 BL_Cleanup(void)
00977 {
00978   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
00979       return;
00980   (vector->p_BL_Cleanup)();
00981 }
00982 
00983 void
00984 BL_Unload(void)
00985 {
00986   /* This function is not thread-safe, but doesn't need to be, because it is
00987    * only called from functions that are also defined as not thread-safe,
00988    * namely C_Finalize in softoken, and the SSL bypass shutdown callback called
00989    * from NSS_Shutdown. */
00990   vector = NULL;
00991   /* If an SSL socket is configured with SSL_BYPASS_PKCS11, but the application
00992    * never does a handshake on it, BL_Unload will be called even though freebl
00993    * was never loaded. So, don't assert blLib. */
00994   if (blLib) {
00995       PRStatus status = PR_UnloadLibrary(blLib);
00996       PORT_Assert(PR_SUCCESS == status);
00997       blLib = NULL;
00998   }
00999   loadFreeBLOnce = pristineCallOnce;
01000 }
01001 
01002 /* ============== New for 3.003 =============================== */
01003 
01004 SECStatus 
01005 SHA256_Hash(unsigned char *dest, const char *src)
01006 {
01007   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01008       return SECFailure;
01009   return (vector->p_SHA256_Hash)(dest, src);
01010 }
01011 
01012 SECStatus 
01013 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
01014 {
01015   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01016       return SECFailure;
01017   return (vector->p_SHA256_HashBuf)(dest, src, src_length);
01018 }
01019 
01020 SHA256Context *
01021 SHA256_NewContext(void)
01022 {
01023   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01024       return NULL;
01025   return (vector->p_SHA256_NewContext)();
01026 }
01027 
01028 void 
01029 SHA256_DestroyContext(SHA256Context *cx, PRBool freeit)
01030 {
01031   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01032       return ;
01033   (vector->p_SHA256_DestroyContext)(cx, freeit);
01034 }
01035 
01036 void 
01037 SHA256_Begin(SHA256Context *cx)
01038 {
01039   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01040       return ;
01041   (vector->p_SHA256_Begin)(cx);
01042 }
01043 
01044 void 
01045 SHA256_Update(SHA256Context *cx, const unsigned char *input,
01046                      unsigned int inputLen)
01047 {
01048   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01049       return ;
01050   (vector->p_SHA256_Update)(cx, input, inputLen);
01051 }
01052 
01053 void 
01054 SHA256_End(SHA256Context *cx, unsigned char *digest,
01055                    unsigned int *digestLen, unsigned int maxDigestLen)
01056 {
01057   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01058       return ;
01059   (vector->p_SHA256_End)(cx, digest, digestLen, maxDigestLen);
01060 }
01061 
01062 void 
01063 SHA256_TraceState(SHA256Context *cx)
01064 {
01065   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01066       return ;
01067   (vector->p_SHA256_TraceState)(cx);
01068 }
01069 
01070 unsigned int 
01071 SHA256_FlattenSize(SHA256Context *cx)
01072 {
01073   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01074       return 0;
01075   return (vector->p_SHA256_FlattenSize)(cx);
01076 }
01077 
01078 SECStatus 
01079 SHA256_Flatten(SHA256Context *cx,unsigned char *space)
01080 {
01081   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01082       return SECFailure;
01083   return (vector->p_SHA256_Flatten)(cx, space);
01084 }
01085 
01086 SHA256Context * 
01087 SHA256_Resurrect(unsigned char *space, void *arg)
01088 {
01089   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01090       return NULL;
01091   return (vector->p_SHA256_Resurrect)(space, arg);
01092 }
01093 
01094 SECStatus 
01095 SHA512_Hash(unsigned char *dest, const char *src)
01096 {
01097   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01098       return SECFailure;
01099   return (vector->p_SHA512_Hash)(dest, src);
01100 }
01101 
01102 SECStatus 
01103 SHA512_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
01104 {
01105   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01106       return SECFailure;
01107   return (vector->p_SHA512_HashBuf)(dest, src, src_length);
01108 }
01109 
01110 SHA512Context *
01111 SHA512_NewContext(void)
01112 {
01113   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01114       return NULL;
01115   return (vector->p_SHA512_NewContext)();
01116 }
01117 
01118 void 
01119 SHA512_DestroyContext(SHA512Context *cx, PRBool freeit)
01120 {
01121   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01122       return ;
01123   (vector->p_SHA512_DestroyContext)(cx, freeit);
01124 }
01125 
01126 void 
01127 SHA512_Begin(SHA512Context *cx)
01128 {
01129   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01130       return ;
01131   (vector->p_SHA512_Begin)(cx);
01132 }
01133 
01134 void 
01135 SHA512_Update(SHA512Context *cx, const unsigned char *input,
01136                      unsigned int inputLen)
01137 {
01138   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01139       return ;
01140   (vector->p_SHA512_Update)(cx, input, inputLen);
01141 }
01142 
01143 void 
01144 SHA512_End(SHA512Context *cx, unsigned char *digest,
01145                    unsigned int *digestLen, unsigned int maxDigestLen)
01146 {
01147   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01148       return ;
01149   (vector->p_SHA512_End)(cx, digest, digestLen, maxDigestLen);
01150 }
01151 
01152 void 
01153 SHA512_TraceState(SHA512Context *cx)
01154 {
01155   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01156       return ;
01157   (vector->p_SHA512_TraceState)(cx);
01158 }
01159 
01160 unsigned int 
01161 SHA512_FlattenSize(SHA512Context *cx)
01162 {
01163   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01164       return 0;
01165   return (vector->p_SHA512_FlattenSize)(cx);
01166 }
01167 
01168 SECStatus 
01169 SHA512_Flatten(SHA512Context *cx,unsigned char *space)
01170 {
01171   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01172       return SECFailure;
01173   return (vector->p_SHA512_Flatten)(cx, space);
01174 }
01175 
01176 SHA512Context * 
01177 SHA512_Resurrect(unsigned char *space, void *arg)
01178 {
01179   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01180       return NULL;
01181   return (vector->p_SHA512_Resurrect)(space, arg);
01182 }
01183 
01184 
01185 SECStatus 
01186 SHA384_Hash(unsigned char *dest, const char *src)
01187 {
01188   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01189       return SECFailure;
01190   return (vector->p_SHA384_Hash)(dest, src);
01191 }
01192 
01193 SECStatus 
01194 SHA384_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
01195 {
01196   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01197       return SECFailure;
01198   return (vector->p_SHA384_HashBuf)(dest, src, src_length);
01199 }
01200 
01201 SHA384Context *
01202 SHA384_NewContext(void)
01203 {
01204   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01205       return NULL;
01206   return (vector->p_SHA384_NewContext)();
01207 }
01208 
01209 void 
01210 SHA384_DestroyContext(SHA384Context *cx, PRBool freeit)
01211 {
01212   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01213       return ;
01214   (vector->p_SHA384_DestroyContext)(cx, freeit);
01215 }
01216 
01217 void 
01218 SHA384_Begin(SHA384Context *cx)
01219 {
01220   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01221       return ;
01222   (vector->p_SHA384_Begin)(cx);
01223 }
01224 
01225 void 
01226 SHA384_Update(SHA384Context *cx, const unsigned char *input,
01227                      unsigned int inputLen)
01228 {
01229   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01230       return ;
01231   (vector->p_SHA384_Update)(cx, input, inputLen);
01232 }
01233 
01234 void 
01235 SHA384_End(SHA384Context *cx, unsigned char *digest,
01236                    unsigned int *digestLen, unsigned int maxDigestLen)
01237 {
01238   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01239       return ;
01240   (vector->p_SHA384_End)(cx, digest, digestLen, maxDigestLen);
01241 }
01242 
01243 void 
01244 SHA384_TraceState(SHA384Context *cx)
01245 {
01246   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01247       return ;
01248   (vector->p_SHA384_TraceState)(cx);
01249 }
01250 
01251 unsigned int 
01252 SHA384_FlattenSize(SHA384Context *cx)
01253 {
01254   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01255       return 0;
01256   return (vector->p_SHA384_FlattenSize)(cx);
01257 }
01258 
01259 SECStatus 
01260 SHA384_Flatten(SHA384Context *cx,unsigned char *space)
01261 {
01262   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01263       return SECFailure;
01264   return (vector->p_SHA384_Flatten)(cx, space);
01265 }
01266 
01267 SHA384Context * 
01268 SHA384_Resurrect(unsigned char *space, void *arg)
01269 {
01270   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01271       return NULL;
01272   return (vector->p_SHA384_Resurrect)(space, arg);
01273 }
01274 
01275 
01276 AESKeyWrapContext *
01277 AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv, 
01278                          int encrypt, unsigned int keylen)
01279 {
01280   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01281       return NULL;
01282   return vector->p_AESKeyWrap_CreateContext(key, iv, encrypt, keylen);
01283 }
01284 
01285 void 
01286 AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit)
01287 {
01288   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01289       return;
01290   vector->p_AESKeyWrap_DestroyContext(cx, freeit);
01291 }
01292 
01293 SECStatus 
01294 AESKeyWrap_Encrypt(AESKeyWrapContext *cx, unsigned char *output,
01295                  unsigned int *outputLen, unsigned int maxOutputLen,
01296                  const unsigned char *input, unsigned int inputLen)
01297 {
01298   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01299       return SECFailure;
01300   return vector->p_AESKeyWrap_Encrypt(cx, output, outputLen, maxOutputLen,
01301                                       input, inputLen);
01302 }
01303 SECStatus 
01304 AESKeyWrap_Decrypt(AESKeyWrapContext *cx, unsigned char *output,
01305                  unsigned int *outputLen, unsigned int maxOutputLen,
01306                  const unsigned char *input, unsigned int inputLen)
01307 {
01308   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01309       return SECFailure;
01310   return vector->p_AESKeyWrap_Decrypt(cx, output, outputLen, maxOutputLen,
01311                                     input, inputLen);
01312 }
01313 
01314 PRBool
01315 BLAPI_SHVerify(const char *name, PRFuncPtr addr)
01316 {
01317   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01318       return PR_FALSE;
01319   return vector->p_BLAPI_SHVerify(name, addr);
01320 }
01321 
01322 /*
01323  * The Caller is expected to pass NULL as the name, which will
01324  * trigger the p_BLAPI_VerifySelf() to return 'TRUE'. If we really loaded
01325  * from a shared library, BLAPI_VerifySelf will get pick up the real name
01326  * from the static set in freebl_LoadDSO( void ) 
01327  */
01328 PRBool
01329 BLAPI_VerifySelf(const char *name)
01330 {
01331   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01332       return PR_FALSE;
01333   return vector->p_BLAPI_VerifySelf(libraryName);
01334 }
01335 
01336 /* ============== New for 3.006 =============================== */
01337 
01338 SECStatus 
01339 EC_NewKey(ECParams * params, ECPrivateKey ** privKey)
01340 {
01341   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01342       return SECFailure;
01343   return (vector->p_EC_NewKey)( params, privKey );
01344 }
01345 
01346 SECStatus 
01347 EC_NewKeyFromSeed(ECParams * params, ECPrivateKey ** privKey,
01348     const unsigned char *seed, int seedlen)
01349 {
01350   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01351       return SECFailure;
01352   return (vector->p_EC_NewKeyFromSeed)( params, privKey, seed, seedlen );
01353 }
01354 
01355 SECStatus 
01356 EC_ValidatePublicKey(ECParams * params, SECItem * publicValue)
01357 {
01358   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01359       return SECFailure;
01360   return (vector->p_EC_ValidatePublicKey)( params, publicValue );
01361 }
01362 
01363 SECStatus 
01364 ECDH_Derive(SECItem * publicValue, ECParams * params, SECItem * privateValue,
01365             PRBool withCofactor, SECItem * derivedSecret)
01366 {
01367   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01368       return SECFailure;
01369   return (vector->p_ECDH_Derive)( publicValue, params, privateValue,
01370                                   withCofactor, derivedSecret );
01371 }
01372 
01373 SECStatus
01374 ECDSA_SignDigest(ECPrivateKey * key, SECItem * signature,
01375     const SECItem * digest)
01376 {
01377   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01378       return SECFailure;
01379   return (vector->p_ECDSA_SignDigest)( key, signature, digest );
01380 }
01381 
01382 SECStatus
01383 ECDSA_VerifyDigest(ECPublicKey * key, const SECItem * signature,
01384     const SECItem * digest)
01385 {
01386   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01387       return SECFailure;
01388   return (vector->p_ECDSA_VerifyDigest)( key, signature, digest );
01389 }
01390 
01391 SECStatus
01392 ECDSA_SignDigestWithSeed(ECPrivateKey * key, SECItem * signature,
01393     const SECItem * digest, const unsigned char *seed, const int seedlen)
01394 {
01395   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01396       return SECFailure;
01397   return (vector->p_ECDSA_SignDigestWithSeed)( key, signature, digest, 
01398       seed, seedlen );
01399 }
01400 
01401 /* ============== New for 3.008 =============================== */
01402 
01403 AESContext *
01404 AES_AllocateContext(void)
01405 {
01406   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01407       return NULL;
01408   return (vector->p_AES_AllocateContext)();
01409 }
01410 
01411 AESKeyWrapContext *
01412 AESKeyWrap_AllocateContext(void)
01413 {
01414   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01415       return NULL;
01416   return (vector->p_AESKeyWrap_AllocateContext)();
01417 }
01418 
01419 DESContext *
01420 DES_AllocateContext(void)
01421 {
01422   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01423       return NULL;
01424   return (vector->p_DES_AllocateContext)();
01425 }
01426 
01427 RC2Context *
01428 RC2_AllocateContext(void)
01429 {
01430   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01431       return NULL;
01432   return (vector->p_RC2_AllocateContext)();
01433 }
01434 
01435 RC4Context *
01436 RC4_AllocateContext(void)
01437 {
01438   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01439       return NULL;
01440   return (vector->p_RC4_AllocateContext)();
01441 }
01442 
01443 SECStatus 
01444 AES_InitContext(AESContext *cx, const unsigned char *key, 
01445               unsigned int keylen, const unsigned char *iv, int mode,
01446               unsigned int encrypt, unsigned int blocklen)
01447 {
01448   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01449       return SECFailure;
01450   return (vector->p_AES_InitContext)(cx, key, keylen, iv, mode, encrypt, 
01451                                  blocklen);
01452 }
01453 
01454 SECStatus 
01455 AESKeyWrap_InitContext(AESKeyWrapContext *cx, const unsigned char *key, 
01456               unsigned int keylen, const unsigned char *iv, int mode,
01457               unsigned int encrypt, unsigned int blocklen)
01458 {
01459   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01460       return SECFailure;
01461   return (vector->p_AESKeyWrap_InitContext)(cx, key, keylen, iv, mode, 
01462                                        encrypt, blocklen);
01463 }
01464 
01465 SECStatus 
01466 DES_InitContext(DESContext *cx, const unsigned char *key, 
01467               unsigned int keylen, const unsigned char *iv, int mode,
01468               unsigned int encrypt, unsigned int xtra)
01469 {
01470   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01471       return SECFailure;
01472   return (vector->p_DES_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra);
01473 }
01474 
01475 SECStatus 
01476 RC2_InitContext(RC2Context *cx, const unsigned char *key, 
01477               unsigned int keylen, const unsigned char *iv, int mode,
01478               unsigned int effectiveKeyLen, unsigned int xtra)
01479 {
01480   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01481       return SECFailure;
01482   return (vector->p_RC2_InitContext)(cx, key, keylen, iv, mode, 
01483                                  effectiveKeyLen, xtra);
01484 }
01485 
01486 SECStatus 
01487 RC4_InitContext(RC4Context *cx, const unsigned char *key, 
01488               unsigned int keylen, const unsigned char *x1, int x2,
01489               unsigned int x3, unsigned int x4)
01490 {
01491   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01492       return SECFailure;
01493   return (vector->p_RC4_InitContext)(cx, key, keylen, x1, x2, x3, x4);
01494 }
01495 
01496 void 
01497 MD2_Clone(MD2Context *dest, MD2Context *src)
01498 {
01499   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01500       return;
01501   (vector->p_MD2_Clone)(dest, src);
01502 }
01503 
01504 void 
01505 MD5_Clone(MD5Context *dest, MD5Context *src)
01506 {
01507   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01508       return;
01509   (vector->p_MD5_Clone)(dest, src);
01510 }
01511 
01512 void 
01513 SHA1_Clone(SHA1Context *dest, SHA1Context *src)
01514 {
01515   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01516       return;
01517   (vector->p_SHA1_Clone)(dest, src);
01518 }
01519 
01520 void 
01521 SHA256_Clone(SHA256Context *dest, SHA256Context *src)
01522 {
01523   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01524       return;
01525   (vector->p_SHA256_Clone)(dest, src);
01526 }
01527 
01528 void 
01529 SHA384_Clone(SHA384Context *dest, SHA384Context *src)
01530 {
01531   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01532       return;
01533   (vector->p_SHA384_Clone)(dest, src);
01534 }
01535 
01536 void 
01537 SHA512_Clone(SHA512Context *dest, SHA512Context *src)
01538 {
01539   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01540       return;
01541   (vector->p_SHA512_Clone)(dest, src);
01542 }
01543 
01544 SECStatus 
01545 TLS_PRF(const SECItem *secret, const char *label, 
01546                    SECItem *seed, SECItem *result, PRBool isFIPS)
01547 {
01548   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01549       return SECFailure;
01550   return (vector->p_TLS_PRF)(secret, label, seed, result, isFIPS);
01551 }
01552 
01553 const SECHashObject *
01554 HASH_GetRawHashObject(HASH_HashType hashType)
01555 {
01556   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01557       return NULL;
01558   return (vector->p_HASH_GetRawHashObject)(hashType);
01559 }
01560 
01561 
01562 void
01563 HMAC_Destroy(HMACContext *cx, PRBool freeit)
01564 {
01565   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01566       return;
01567   (vector->p_HMAC_Destroy)(cx, freeit);
01568 }
01569 
01570 HMACContext *
01571 HMAC_Create(const SECHashObject *hashObj, const unsigned char *secret, 
01572            unsigned int secret_len, PRBool isFIPS)
01573 {
01574   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01575       return NULL;
01576   return (vector->p_HMAC_Create)(hashObj, secret, secret_len, isFIPS);
01577 }
01578 
01579 SECStatus
01580 HMAC_Init(HMACContext *cx, const SECHashObject *hashObj, 
01581          const unsigned char *secret, unsigned int secret_len, PRBool isFIPS)
01582 {
01583   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01584       return SECFailure;
01585   return (vector->p_HMAC_Init)(cx, hashObj, secret, secret_len, isFIPS);
01586 }
01587 
01588 void
01589 HMAC_Begin(HMACContext *cx)
01590 {
01591   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01592       return;
01593   (vector->p_HMAC_Begin)(cx);
01594 }
01595 
01596 void 
01597 HMAC_Update(HMACContext *cx, const unsigned char *data, unsigned int data_len)
01598 {
01599   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01600       return;
01601   (vector->p_HMAC_Update)(cx, data, data_len);
01602 }
01603 
01604 SECStatus
01605 HMAC_Finish(HMACContext *cx, unsigned char *result, unsigned int *result_len,
01606            unsigned int max_result_len)
01607 {
01608   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01609       return SECFailure;
01610   return (vector->p_HMAC_Finish)(cx, result, result_len, max_result_len);
01611 }
01612 
01613 HMACContext *
01614 HMAC_Clone(HMACContext *cx)
01615 {
01616   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01617       return NULL;
01618   return (vector->p_HMAC_Clone)(cx);
01619 }
01620 
01621 void
01622 RNG_SystemInfoForRNG(void)
01623 {
01624   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01625       return ;
01626   (vector->p_RNG_SystemInfoForRNG)();
01627 
01628 }
01629 
01630 SECStatus
01631 FIPS186Change_GenerateX(unsigned char *XKEY, const unsigned char *XSEEDj,
01632                         unsigned char *x_j)
01633 {
01634   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01635       return SECFailure;
01636   return (vector->p_FIPS186Change_GenerateX)(XKEY, XSEEDj, x_j);
01637 }
01638 
01639 SECStatus
01640 FIPS186Change_ReduceModQForDSA(const unsigned char *w,
01641                                const unsigned char *q,
01642                                unsigned char *xj)
01643 {
01644   if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
01645       return SECFailure;
01646   return (vector->p_FIPS186Change_ReduceModQForDSA)(w, q, xj);
01647 }