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