2
* loader.c - load platform dependent DSO containing freebl implementation.
4
* ***** BEGIN LICENSE BLOCK *****
5
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
7
* The contents of this file are subject to the Mozilla Public License Version
8
* 1.1 (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
10
* http://www.mozilla.org/MPL/
12
* Software distributed under the License is distributed on an "AS IS" basis,
13
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
* for the specific language governing rights and limitations under the
17
* The Original Code is the Netscape security libraries.
19
* The Initial Developer of the Original Code is
20
* Netscape Communications Corporation.
21
* Portions created by the Initial Developer are Copyright (C) 2000
22
* the Initial Developer. All Rights Reserved.
25
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
27
* Alternatively, the contents of this file may be used under the terms of
28
* either the GNU General Public License Version 2 or later (the "GPL"), or
29
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
* in which case the provisions of the GPL or the LGPL are applicable instead
31
* of those above. If you wish to allow use of your version of this file only
32
* under the terms of either the GPL or the LGPL, and not to allow others to
33
* use your version of this file under the terms of the MPL, indicate your
34
* decision by deleting the provisions above and replace them with the notice
35
* and other provisions required by the GPL or the LGPL. If you do not delete
36
* the provisions above, a recipient may use your version of this file under
37
* the terms of any one of the MPL, the GPL or the LGPL.
39
* ***** END LICENSE BLOCK ***** */
40
/* $Id: loader.c,v 1.26.2.4 2006/10/02 21:17:58 julien.pierre.bugs%sun.com Exp $ */
47
static const char* default_name =
48
SHLIB_PREFIX"freebl"SHLIB_VERSION"."SHLIB_SUFFIX;
50
/* getLibName() returns the name of the library to load. */
52
#if defined(SOLARIS) && defined(__sparc)
55
#include <sys/systeminfo.h>
58
#if defined(NSS_USE_64)
60
const static char fpu_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
61
const static char int_hybrid_shared_lib[] = "libfreebl_64int_3.so";
62
const static char non_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
64
const static char int_hybrid_isa[] = "sparcv9";
65
const static char fpu_hybrid_isa[] = "sparcv9+vis";
69
const static char fpu_hybrid_shared_lib[] = "libfreebl_32fpu_3.so";
70
const static char int_hybrid_shared_lib[] = "libfreebl_32int64_3.so";
71
const static char non_hybrid_shared_lib[] = "libfreebl_32int_3.so";
73
const static char int_hybrid_isa[] = "sparcv8plus";
74
const static char fpu_hybrid_isa[] = "sparcv8plus+vis";
81
char * found_int_hybrid;
82
char * found_fpu_hybrid;
86
buflen = sysinfo(SI_ISALIST, buf, sizeof buf);
89
/* The ISA list is a space separated string of names of ISAs and
90
* ISA extensions, in order of decreasing performance.
91
* There are two different ISAs with which NSS's crypto code can be
92
* accelerated. If both are in the list, we take the first one.
93
* If one is in the list, we use it, and if neither then we use
94
* the base unaccelerated code.
96
found_int_hybrid = strstr(buf, int_hybrid_isa);
97
found_fpu_hybrid = strstr(buf, fpu_hybrid_isa);
98
if (found_fpu_hybrid &&
100
(found_int_hybrid - found_fpu_hybrid) >= 0)) {
101
return fpu_hybrid_shared_lib;
103
if (found_int_hybrid) {
104
return int_hybrid_shared_lib;
106
return non_hybrid_shared_lib;
109
#elif defined(HPUX) && !defined(NSS_USE_64) && !defined(__ia64)
110
/* This code tests to see if we're running on a PA2.x CPU.
111
** It returns true (1) if so, and false (0) otherwise.
116
long cpu = sysconf(_SC_CPU_VERSION);
117
return (cpu == CPU_PA_RISC2_0)
118
? "libfreebl_32fpu_3.sl"
119
: "libfreebl_32int32_3.sl" ;
122
/* default case, for platforms/ABIs that have only one freebl shared lib. */
123
static const char * getLibName(void) { return default_name; }
129
#define BL_MAXSYMLINKS 20
132
* If 'link' is a symbolic link, this function follows the symbolic links
133
* and returns the pathname of the ultimate source of the symbolic links.
134
* If 'link' is not a symbolic link, this function returns NULL.
135
* The caller should call PR_Free to free the string returned by this
138
static char* bl_GetOriginalPathname(const char* link)
140
char* resolved = NULL;
142
PRUint32 iterations = 0;
143
PRInt32 len = 0, retlen = 0;
145
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
148
len = PR_MAX(1024, strlen(link) + 1);
149
resolved = PR_Malloc(len);
150
input = PR_Malloc(len);
151
if (!resolved || !input) {
161
while ( (iterations++ < BL_MAXSYMLINKS) &&
162
( (retlen = readlink(input, resolved, len - 1)) > 0) ) {
164
resolved[retlen] = '\0'; /* NULL termination */
169
if (iterations == 1 && retlen < 0) {
178
* We use PR_GetLibraryFilePathname to get the pathname of the loaded
179
* shared lib that contains this function, and then do a PR_LoadLibrary
180
* with an absolute pathname for the freebl shared library.
186
#include "prsystem.h"
188
const char* softoken=SHLIB_PREFIX"softokn"SOFTOKEN_SHLIB_VERSION"."SHLIB_SUFFIX;
190
static PRLibrary* blLib;
193
* Load the freebl library with the file name 'name' residing in the same
194
* directory as libsoftoken, whose pathname is 'softokenPath'.
197
bl_LoadFreeblLibInSoftokenDir(const char *softokenPath, const char *name)
199
PRLibrary *dlh = NULL;
200
char *fullName = NULL;
204
/* Remove "libsoftokn" from the pathname and add the freebl libname */
205
c = strrchr(softokenPath, PR_GetDirectorySeparator());
207
size_t softoknPathSize = 1 + c - softokenPath;
208
fullName = (char*) PORT_Alloc(strlen(name) + softoknPathSize + 1);
210
memcpy(fullName, softokenPath, softoknPathSize);
211
strcpy(fullName + softoknPathSize, name);
213
PR_fprintf(PR_STDOUT, "\nAttempting to load fully-qualified %s\n",
216
libSpec.type = PR_LibSpec_Pathname;
217
libSpec.value.pathname = fullName;
218
dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
226
bl_LoadLibrary(const char *name)
228
PRLibrary *lib = NULL;
230
char* softokenPath = NULL;
233
/* Get the pathname for the loaded libsoftokn, i.e. /usr/lib/libsoftokn3.so
234
* PR_GetLibraryFilePathname works with either the base library name or a
235
* function pointer, depending on the platform. We can't query an exported
236
* symbol such as NSC_GetFunctionList, because on some platforms we can't
237
* find symbols in loaded implicit dependencies such as libsoftokn.
238
* But we can just get the address of this function !
240
fn_addr = (PRFuncPtr) &bl_LoadLibrary;
241
softokenPath = PR_GetLibraryFilePathname(softoken, fn_addr);
244
lib = bl_LoadFreeblLibInSoftokenDir(softokenPath, name);
248
* If softokenPath is a symbolic link, resolve the symbolic
249
* link and try again.
251
char* originalSoftokenPath = bl_GetOriginalPathname(softokenPath);
252
if (originalSoftokenPath) {
253
PR_Free(softokenPath);
254
softokenPath = originalSoftokenPath;
255
lib = bl_LoadFreeblLibInSoftokenDir(softokenPath, name);
259
PR_Free(softokenPath);
263
PR_fprintf(PR_STDOUT, "\nAttempting to load %s\n", name);
265
libSpec.type = PR_LibSpec_Pathname;
266
libSpec.value.pathname = name;
267
lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
271
PR_fprintf(PR_STDOUT, "\nLoading failed : %s.\n", name);
277
#define LSB(x) ((x)&0xff)
278
#define MSB(x) ((x)>>8)
280
static const FREEBLVector *vector;
281
static const char *libraryName = NULL;
283
/* This function must be run only once. */
284
/* determine if hybrid platform, then actually load the DSO. */
286
freebl_LoadDSO( void )
289
const char * name = getLibName();
292
PR_SetError(PR_LOAD_LIBRARY_ERROR, 0);
296
handle = bl_LoadLibrary(name);
298
PRFuncPtr address = PR_FindFunctionSymbol(handle, "FREEBL_GetVector");
301
FREEBLGetVectorFn * getVector = (FREEBLGetVectorFn *)address;
302
const FREEBLVector * dsoVector = getVector();
304
unsigned short dsoVersion = dsoVector->version;
305
unsigned short myVersion = FREEBL_VERSION;
306
if (MSB(dsoVersion) == MSB(myVersion) &&
307
LSB(dsoVersion) >= LSB(myVersion) &&
308
dsoVector->length >= sizeof(FREEBLVector)) {
316
status = PR_UnloadLibrary(handle);
317
PORT_Assert(PR_SUCCESS == status);
322
static const PRCallOnceType pristineCallOnce;
323
static PRCallOnceType loadFreeBLOnce;
326
freebl_RunLoaderOnce( void )
330
status = PR_CallOnce(&loadFreeBLOnce, &freebl_LoadDSO);
336
RSA_NewKey(int keySizeInBits, SECItem * publicExponent)
338
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
340
return (vector->p_RSA_NewKey)(keySizeInBits, publicExponent);
344
RSA_PublicKeyOp(RSAPublicKey * key,
345
unsigned char * output,
346
const unsigned char * input)
348
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
350
return (vector->p_RSA_PublicKeyOp)(key, output, input);
354
RSA_PrivateKeyOp(RSAPrivateKey * key,
355
unsigned char * output,
356
const unsigned char * input)
358
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
360
return (vector->p_RSA_PrivateKeyOp)(key, output, input);
364
RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey *key,
365
unsigned char *output,
366
const unsigned char *input)
368
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
370
return (vector->p_RSA_PrivateKeyOpDoubleChecked)(key, output, input);
374
RSA_PrivateKeyCheck(RSAPrivateKey *key)
376
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
378
return (vector->p_RSA_PrivateKeyCheck)(key);
382
DSA_NewKey(const PQGParams * params, DSAPrivateKey ** privKey)
384
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
386
return (vector->p_DSA_NewKey)(params, privKey);
390
DSA_SignDigest(DSAPrivateKey * key, SECItem * signature, const SECItem * digest)
392
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
394
return (vector->p_DSA_SignDigest)( key, signature, digest);
398
DSA_VerifyDigest(DSAPublicKey * key, const SECItem * signature,
399
const SECItem * digest)
401
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
403
return (vector->p_DSA_VerifyDigest)( key, signature, digest);
407
DSA_NewKeyFromSeed(const PQGParams *params, const unsigned char * seed,
408
DSAPrivateKey **privKey)
410
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
412
return (vector->p_DSA_NewKeyFromSeed)(params, seed, privKey);
416
DSA_SignDigestWithSeed(DSAPrivateKey * key, SECItem * signature,
417
const SECItem * digest, const unsigned char * seed)
419
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
421
return (vector->p_DSA_SignDigestWithSeed)( key, signature, digest, seed);
425
DH_GenParam(int primeLen, DHParams ** params)
427
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
429
return (vector->p_DH_GenParam)(primeLen, params);
433
DH_NewKey(DHParams * params, DHPrivateKey ** privKey)
435
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
437
return (vector->p_DH_NewKey)( params, privKey);
441
DH_Derive(SECItem * publicValue, SECItem * prime, SECItem * privateValue,
442
SECItem * derivedSecret, unsigned int maxOutBytes)
444
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
446
return (vector->p_DH_Derive)( publicValue, prime, privateValue,
447
derivedSecret, maxOutBytes);
451
KEA_Derive(SECItem *prime, SECItem *public1, SECItem *public2,
452
SECItem *private1, SECItem *private2, SECItem *derivedSecret)
454
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
456
return (vector->p_KEA_Derive)(prime, public1, public2,
457
private1, private2, derivedSecret);
461
KEA_Verify(SECItem *Y, SECItem *prime, SECItem *subPrime)
463
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
465
return (vector->p_KEA_Verify)(Y, prime, subPrime);
469
RC4_CreateContext(const unsigned char *key, int len)
471
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
473
return (vector->p_RC4_CreateContext)(key, len);
477
RC4_DestroyContext(RC4Context *cx, PRBool freeit)
479
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
481
(vector->p_RC4_DestroyContext)(cx, freeit);
485
RC4_Encrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen,
486
unsigned int maxOutputLen, const unsigned char *input,
487
unsigned int inputLen)
489
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
491
return (vector->p_RC4_Encrypt)(cx, output, outputLen, maxOutputLen, input,
496
RC4_Decrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen,
497
unsigned int maxOutputLen, const unsigned char *input,
498
unsigned int inputLen)
500
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
502
return (vector->p_RC4_Decrypt)(cx, output, outputLen, maxOutputLen, input,
507
RC2_CreateContext(const unsigned char *key, unsigned int len,
508
const unsigned char *iv, int mode, unsigned effectiveKeyLen)
510
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
512
return (vector->p_RC2_CreateContext)(key, len, iv, mode, effectiveKeyLen);
516
RC2_DestroyContext(RC2Context *cx, PRBool freeit)
518
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
520
(vector->p_RC2_DestroyContext)(cx, freeit);
524
RC2_Encrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen,
525
unsigned int maxOutputLen, const unsigned char *input,
526
unsigned int inputLen)
528
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
530
return (vector->p_RC2_Encrypt)(cx, output, outputLen, maxOutputLen, input,
535
RC2_Decrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen,
536
unsigned int maxOutputLen, const unsigned char *input,
537
unsigned int inputLen)
539
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
541
return (vector->p_RC2_Decrypt)(cx, output, outputLen, maxOutputLen, input,
546
RC5_CreateContext(const SECItem *key, unsigned int rounds,
547
unsigned int wordSize, const unsigned char *iv, int mode)
549
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
551
return (vector->p_RC5_CreateContext)(key, rounds, wordSize, iv, mode);
555
RC5_DestroyContext(RC5Context *cx, PRBool freeit)
557
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
559
(vector->p_RC5_DestroyContext)(cx, freeit);
563
RC5_Encrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen,
564
unsigned int maxOutputLen, const unsigned char *input,
565
unsigned int inputLen)
567
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
569
return (vector->p_RC5_Encrypt)(cx, output, outputLen, maxOutputLen, input,
574
RC5_Decrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen,
575
unsigned int maxOutputLen, const unsigned char *input,
576
unsigned int inputLen)
578
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
580
return (vector->p_RC5_Decrypt)(cx, output, outputLen, maxOutputLen, input,
585
DES_CreateContext(const unsigned char *key, const unsigned char *iv,
586
int mode, PRBool encrypt)
588
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
590
return (vector->p_DES_CreateContext)(key, iv, mode, encrypt);
594
DES_DestroyContext(DESContext *cx, PRBool freeit)
596
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
598
(vector->p_DES_DestroyContext)(cx, freeit);
602
DES_Encrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen,
603
unsigned int maxOutputLen, const unsigned char *input,
604
unsigned int inputLen)
606
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
608
return (vector->p_DES_Encrypt)(cx, output, outputLen, maxOutputLen, input,
613
DES_Decrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen,
614
unsigned int maxOutputLen, const unsigned char *input,
615
unsigned int inputLen)
617
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
619
return (vector->p_DES_Decrypt)(cx, output, outputLen, maxOutputLen, input,
624
AES_CreateContext(const unsigned char *key, const unsigned char *iv,
625
int mode, int encrypt,
626
unsigned int keylen, unsigned int blocklen)
628
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
630
return (vector->p_AES_CreateContext)(key, iv, mode, encrypt, keylen,
635
AES_DestroyContext(AESContext *cx, PRBool freeit)
637
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
639
(vector->p_AES_DestroyContext)(cx, freeit);
643
AES_Encrypt(AESContext *cx, unsigned char *output,
644
unsigned int *outputLen, unsigned int maxOutputLen,
645
const unsigned char *input, unsigned int inputLen)
647
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
649
return (vector->p_AES_Encrypt)(cx, output, outputLen, maxOutputLen,
654
AES_Decrypt(AESContext *cx, unsigned char *output,
655
unsigned int *outputLen, unsigned int maxOutputLen,
656
const unsigned char *input, unsigned int inputLen)
658
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
660
return (vector->p_AES_Decrypt)(cx, output, outputLen, maxOutputLen,
665
MD5_Hash(unsigned char *dest, const char *src)
667
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
669
return (vector->p_MD5_Hash)(dest, src);
673
MD5_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
675
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
677
return (vector->p_MD5_HashBuf)(dest, src, src_length);
683
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
685
return (vector->p_MD5_NewContext)();
689
MD5_DestroyContext(MD5Context *cx, PRBool freeit)
691
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
693
(vector->p_MD5_DestroyContext)(cx, freeit);
697
MD5_Begin(MD5Context *cx)
699
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
701
(vector->p_MD5_Begin)(cx);
705
MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen)
707
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
709
(vector->p_MD5_Update)(cx, input, inputLen);
713
MD5_End(MD5Context *cx, unsigned char *digest,
714
unsigned int *digestLen, unsigned int maxDigestLen)
716
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
718
(vector->p_MD5_End)(cx, digest, digestLen, maxDigestLen);
722
MD5_FlattenSize(MD5Context *cx)
724
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
726
return (vector->p_MD5_FlattenSize)(cx);
730
MD5_Flatten(MD5Context *cx,unsigned char *space)
732
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
734
return (vector->p_MD5_Flatten)(cx, space);
738
MD5_Resurrect(unsigned char *space, void *arg)
740
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
742
return (vector->p_MD5_Resurrect)(space, arg);
746
MD5_TraceState(MD5Context *cx)
748
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
750
(vector->p_MD5_TraceState)(cx);
754
MD2_Hash(unsigned char *dest, const char *src)
756
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
758
return (vector->p_MD2_Hash)(dest, src);
764
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
766
return (vector->p_MD2_NewContext)();
770
MD2_DestroyContext(MD2Context *cx, PRBool freeit)
772
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
774
(vector->p_MD2_DestroyContext)(cx, freeit);
778
MD2_Begin(MD2Context *cx)
780
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
782
(vector->p_MD2_Begin)(cx);
786
MD2_Update(MD2Context *cx, const unsigned char *input, unsigned int inputLen)
788
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
790
(vector->p_MD2_Update)(cx, input, inputLen);
794
MD2_End(MD2Context *cx, unsigned char *digest,
795
unsigned int *digestLen, unsigned int maxDigestLen)
797
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
799
(vector->p_MD2_End)(cx, digest, digestLen, maxDigestLen);
803
MD2_FlattenSize(MD2Context *cx)
805
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
807
return (vector->p_MD2_FlattenSize)(cx);
811
MD2_Flatten(MD2Context *cx,unsigned char *space)
813
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
815
return (vector->p_MD2_Flatten)(cx, space);
819
MD2_Resurrect(unsigned char *space, void *arg)
821
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
823
return (vector->p_MD2_Resurrect)(space, arg);
828
SHA1_Hash(unsigned char *dest, const char *src)
830
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
832
return (vector->p_SHA1_Hash)(dest, src);
836
SHA1_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
838
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
840
return (vector->p_SHA1_HashBuf)(dest, src, src_length);
844
SHA1_NewContext(void)
846
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
848
return (vector->p_SHA1_NewContext)();
852
SHA1_DestroyContext(SHA1Context *cx, PRBool freeit)
854
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
856
(vector->p_SHA1_DestroyContext)(cx, freeit);
860
SHA1_Begin(SHA1Context *cx)
862
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
864
(vector->p_SHA1_Begin)(cx);
868
SHA1_Update(SHA1Context *cx, const unsigned char *input,
869
unsigned int inputLen)
871
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
873
(vector->p_SHA1_Update)(cx, input, inputLen);
877
SHA1_End(SHA1Context *cx, unsigned char *digest,
878
unsigned int *digestLen, unsigned int maxDigestLen)
880
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
882
(vector->p_SHA1_End)(cx, digest, digestLen, maxDigestLen);
886
SHA1_TraceState(SHA1Context *cx)
888
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
890
(vector->p_SHA1_TraceState)(cx);
894
SHA1_FlattenSize(SHA1Context *cx)
896
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
898
return (vector->p_SHA1_FlattenSize)(cx);
902
SHA1_Flatten(SHA1Context *cx,unsigned char *space)
904
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
906
return (vector->p_SHA1_Flatten)(cx, space);
910
SHA1_Resurrect(unsigned char *space, void *arg)
912
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
914
return (vector->p_SHA1_Resurrect)(space, arg);
920
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
922
return (vector->p_RNG_RNGInit)();
926
RNG_RandomUpdate(const void *data, size_t bytes)
928
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
930
return (vector->p_RNG_RandomUpdate)(data, bytes);
934
RNG_GenerateGlobalRandomBytes(void *dest, size_t len)
936
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
938
return (vector->p_RNG_GenerateGlobalRandomBytes)(dest, len);
942
RNG_RNGShutdown(void)
944
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
946
(vector->p_RNG_RNGShutdown)();
950
PQG_ParamGen(unsigned int j, PQGParams **pParams, PQGVerify **pVfy)
952
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
954
return (vector->p_PQG_ParamGen)(j, pParams, pVfy);
958
PQG_ParamGenSeedLen( unsigned int j, unsigned int seedBytes,
959
PQGParams **pParams, PQGVerify **pVfy)
961
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
963
return (vector->p_PQG_ParamGenSeedLen)(j, seedBytes, pParams, pVfy);
967
PQG_VerifyParams(const PQGParams *params, const PQGVerify *vfy,
970
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
972
return (vector->p_PQG_VerifyParams)(params, vfy, result);
978
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
980
(vector->p_BL_Cleanup)();
986
/* This function is not thread-safe, but doesn't need to be, because it is
987
* only called from functions that are also defined as not thread-safe,
988
* namely C_Finalize in softoken, and the SSL bypass shutdown callback called
989
* from NSS_Shutdown. */
991
/* If an SSL socket is configured with SSL_BYPASS_PKCS11, but the application
992
* never does a handshake on it, BL_Unload will be called even though freebl
993
* was never loaded. So, don't assert blLib. */
995
PRStatus status = PR_UnloadLibrary(blLib);
996
PORT_Assert(PR_SUCCESS == status);
999
loadFreeBLOnce = pristineCallOnce;
1002
/* ============== New for 3.003 =============================== */
1005
SHA256_Hash(unsigned char *dest, const char *src)
1007
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1009
return (vector->p_SHA256_Hash)(dest, src);
1013
SHA256_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
1015
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1017
return (vector->p_SHA256_HashBuf)(dest, src, src_length);
1021
SHA256_NewContext(void)
1023
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1025
return (vector->p_SHA256_NewContext)();
1029
SHA256_DestroyContext(SHA256Context *cx, PRBool freeit)
1031
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1033
(vector->p_SHA256_DestroyContext)(cx, freeit);
1037
SHA256_Begin(SHA256Context *cx)
1039
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1041
(vector->p_SHA256_Begin)(cx);
1045
SHA256_Update(SHA256Context *cx, const unsigned char *input,
1046
unsigned int inputLen)
1048
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1050
(vector->p_SHA256_Update)(cx, input, inputLen);
1054
SHA256_End(SHA256Context *cx, unsigned char *digest,
1055
unsigned int *digestLen, unsigned int maxDigestLen)
1057
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1059
(vector->p_SHA256_End)(cx, digest, digestLen, maxDigestLen);
1063
SHA256_TraceState(SHA256Context *cx)
1065
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1067
(vector->p_SHA256_TraceState)(cx);
1071
SHA256_FlattenSize(SHA256Context *cx)
1073
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1075
return (vector->p_SHA256_FlattenSize)(cx);
1079
SHA256_Flatten(SHA256Context *cx,unsigned char *space)
1081
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1083
return (vector->p_SHA256_Flatten)(cx, space);
1087
SHA256_Resurrect(unsigned char *space, void *arg)
1089
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1091
return (vector->p_SHA256_Resurrect)(space, arg);
1095
SHA512_Hash(unsigned char *dest, const char *src)
1097
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1099
return (vector->p_SHA512_Hash)(dest, src);
1103
SHA512_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
1105
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1107
return (vector->p_SHA512_HashBuf)(dest, src, src_length);
1111
SHA512_NewContext(void)
1113
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1115
return (vector->p_SHA512_NewContext)();
1119
SHA512_DestroyContext(SHA512Context *cx, PRBool freeit)
1121
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1123
(vector->p_SHA512_DestroyContext)(cx, freeit);
1127
SHA512_Begin(SHA512Context *cx)
1129
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1131
(vector->p_SHA512_Begin)(cx);
1135
SHA512_Update(SHA512Context *cx, const unsigned char *input,
1136
unsigned int inputLen)
1138
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1140
(vector->p_SHA512_Update)(cx, input, inputLen);
1144
SHA512_End(SHA512Context *cx, unsigned char *digest,
1145
unsigned int *digestLen, unsigned int maxDigestLen)
1147
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1149
(vector->p_SHA512_End)(cx, digest, digestLen, maxDigestLen);
1153
SHA512_TraceState(SHA512Context *cx)
1155
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1157
(vector->p_SHA512_TraceState)(cx);
1161
SHA512_FlattenSize(SHA512Context *cx)
1163
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1165
return (vector->p_SHA512_FlattenSize)(cx);
1169
SHA512_Flatten(SHA512Context *cx,unsigned char *space)
1171
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1173
return (vector->p_SHA512_Flatten)(cx, space);
1177
SHA512_Resurrect(unsigned char *space, void *arg)
1179
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1181
return (vector->p_SHA512_Resurrect)(space, arg);
1186
SHA384_Hash(unsigned char *dest, const char *src)
1188
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1190
return (vector->p_SHA384_Hash)(dest, src);
1194
SHA384_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
1196
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1198
return (vector->p_SHA384_HashBuf)(dest, src, src_length);
1202
SHA384_NewContext(void)
1204
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1206
return (vector->p_SHA384_NewContext)();
1210
SHA384_DestroyContext(SHA384Context *cx, PRBool freeit)
1212
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1214
(vector->p_SHA384_DestroyContext)(cx, freeit);
1218
SHA384_Begin(SHA384Context *cx)
1220
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1222
(vector->p_SHA384_Begin)(cx);
1226
SHA384_Update(SHA384Context *cx, const unsigned char *input,
1227
unsigned int inputLen)
1229
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1231
(vector->p_SHA384_Update)(cx, input, inputLen);
1235
SHA384_End(SHA384Context *cx, unsigned char *digest,
1236
unsigned int *digestLen, unsigned int maxDigestLen)
1238
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1240
(vector->p_SHA384_End)(cx, digest, digestLen, maxDigestLen);
1244
SHA384_TraceState(SHA384Context *cx)
1246
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1248
(vector->p_SHA384_TraceState)(cx);
1252
SHA384_FlattenSize(SHA384Context *cx)
1254
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1256
return (vector->p_SHA384_FlattenSize)(cx);
1260
SHA384_Flatten(SHA384Context *cx,unsigned char *space)
1262
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1264
return (vector->p_SHA384_Flatten)(cx, space);
1268
SHA384_Resurrect(unsigned char *space, void *arg)
1270
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1272
return (vector->p_SHA384_Resurrect)(space, arg);
1277
AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv,
1278
int encrypt, unsigned int keylen)
1280
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1282
return vector->p_AESKeyWrap_CreateContext(key, iv, encrypt, keylen);
1286
AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit)
1288
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1290
vector->p_AESKeyWrap_DestroyContext(cx, freeit);
1294
AESKeyWrap_Encrypt(AESKeyWrapContext *cx, unsigned char *output,
1295
unsigned int *outputLen, unsigned int maxOutputLen,
1296
const unsigned char *input, unsigned int inputLen)
1298
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1300
return vector->p_AESKeyWrap_Encrypt(cx, output, outputLen, maxOutputLen,
1304
AESKeyWrap_Decrypt(AESKeyWrapContext *cx, unsigned char *output,
1305
unsigned int *outputLen, unsigned int maxOutputLen,
1306
const unsigned char *input, unsigned int inputLen)
1308
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1310
return vector->p_AESKeyWrap_Decrypt(cx, output, outputLen, maxOutputLen,
1315
BLAPI_SHVerify(const char *name, PRFuncPtr addr)
1317
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1319
return vector->p_BLAPI_SHVerify(name, addr);
1323
* The Caller is expected to pass NULL as the name, which will
1324
* trigger the p_BLAPI_VerifySelf() to return 'TRUE'. If we really loaded
1325
* from a shared library, BLAPI_VerifySelf will get pick up the real name
1326
* from the static set in freebl_LoadDSO( void )
1329
BLAPI_VerifySelf(const char *name)
1331
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1333
return vector->p_BLAPI_VerifySelf(libraryName);
1336
/* ============== New for 3.006 =============================== */
1339
EC_NewKey(ECParams * params, ECPrivateKey ** privKey)
1341
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1343
return (vector->p_EC_NewKey)( params, privKey );
1347
EC_NewKeyFromSeed(ECParams * params, ECPrivateKey ** privKey,
1348
const unsigned char *seed, int seedlen)
1350
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1352
return (vector->p_EC_NewKeyFromSeed)( params, privKey, seed, seedlen );
1356
EC_ValidatePublicKey(ECParams * params, SECItem * publicValue)
1358
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1360
return (vector->p_EC_ValidatePublicKey)( params, publicValue );
1364
ECDH_Derive(SECItem * publicValue, ECParams * params, SECItem * privateValue,
1365
PRBool withCofactor, SECItem * derivedSecret)
1367
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1369
return (vector->p_ECDH_Derive)( publicValue, params, privateValue,
1370
withCofactor, derivedSecret );
1374
ECDSA_SignDigest(ECPrivateKey * key, SECItem * signature,
1375
const SECItem * digest)
1377
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1379
return (vector->p_ECDSA_SignDigest)( key, signature, digest );
1383
ECDSA_VerifyDigest(ECPublicKey * key, const SECItem * signature,
1384
const SECItem * digest)
1386
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1388
return (vector->p_ECDSA_VerifyDigest)( key, signature, digest );
1392
ECDSA_SignDigestWithSeed(ECPrivateKey * key, SECItem * signature,
1393
const SECItem * digest, const unsigned char *seed, const int seedlen)
1395
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1397
return (vector->p_ECDSA_SignDigestWithSeed)( key, signature, digest,
1401
/* ============== New for 3.008 =============================== */
1404
AES_AllocateContext(void)
1406
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1408
return (vector->p_AES_AllocateContext)();
1412
AESKeyWrap_AllocateContext(void)
1414
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1416
return (vector->p_AESKeyWrap_AllocateContext)();
1420
DES_AllocateContext(void)
1422
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1424
return (vector->p_DES_AllocateContext)();
1428
RC2_AllocateContext(void)
1430
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1432
return (vector->p_RC2_AllocateContext)();
1436
RC4_AllocateContext(void)
1438
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1440
return (vector->p_RC4_AllocateContext)();
1444
AES_InitContext(AESContext *cx, const unsigned char *key,
1445
unsigned int keylen, const unsigned char *iv, int mode,
1446
unsigned int encrypt, unsigned int blocklen)
1448
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1450
return (vector->p_AES_InitContext)(cx, key, keylen, iv, mode, encrypt,
1455
AESKeyWrap_InitContext(AESKeyWrapContext *cx, const unsigned char *key,
1456
unsigned int keylen, const unsigned char *iv, int mode,
1457
unsigned int encrypt, unsigned int blocklen)
1459
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1461
return (vector->p_AESKeyWrap_InitContext)(cx, key, keylen, iv, mode,
1466
DES_InitContext(DESContext *cx, const unsigned char *key,
1467
unsigned int keylen, const unsigned char *iv, int mode,
1468
unsigned int encrypt, unsigned int xtra)
1470
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1472
return (vector->p_DES_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra);
1476
RC2_InitContext(RC2Context *cx, const unsigned char *key,
1477
unsigned int keylen, const unsigned char *iv, int mode,
1478
unsigned int effectiveKeyLen, unsigned int xtra)
1480
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1482
return (vector->p_RC2_InitContext)(cx, key, keylen, iv, mode,
1483
effectiveKeyLen, xtra);
1487
RC4_InitContext(RC4Context *cx, const unsigned char *key,
1488
unsigned int keylen, const unsigned char *x1, int x2,
1489
unsigned int x3, unsigned int x4)
1491
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1493
return (vector->p_RC4_InitContext)(cx, key, keylen, x1, x2, x3, x4);
1497
MD2_Clone(MD2Context *dest, MD2Context *src)
1499
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1501
(vector->p_MD2_Clone)(dest, src);
1505
MD5_Clone(MD5Context *dest, MD5Context *src)
1507
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1509
(vector->p_MD5_Clone)(dest, src);
1513
SHA1_Clone(SHA1Context *dest, SHA1Context *src)
1515
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1517
(vector->p_SHA1_Clone)(dest, src);
1521
SHA256_Clone(SHA256Context *dest, SHA256Context *src)
1523
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1525
(vector->p_SHA256_Clone)(dest, src);
1529
SHA384_Clone(SHA384Context *dest, SHA384Context *src)
1531
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1533
(vector->p_SHA384_Clone)(dest, src);
1537
SHA512_Clone(SHA512Context *dest, SHA512Context *src)
1539
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1541
(vector->p_SHA512_Clone)(dest, src);
1545
TLS_PRF(const SECItem *secret, const char *label,
1546
SECItem *seed, SECItem *result, PRBool isFIPS)
1548
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1550
return (vector->p_TLS_PRF)(secret, label, seed, result, isFIPS);
1553
const SECHashObject *
1554
HASH_GetRawHashObject(HASH_HashType hashType)
1556
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1558
return (vector->p_HASH_GetRawHashObject)(hashType);
1563
HMAC_Destroy(HMACContext *cx, PRBool freeit)
1565
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1567
(vector->p_HMAC_Destroy)(cx, freeit);
1571
HMAC_Create(const SECHashObject *hashObj, const unsigned char *secret,
1572
unsigned int secret_len, PRBool isFIPS)
1574
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1576
return (vector->p_HMAC_Create)(hashObj, secret, secret_len, isFIPS);
1580
HMAC_Init(HMACContext *cx, const SECHashObject *hashObj,
1581
const unsigned char *secret, unsigned int secret_len, PRBool isFIPS)
1583
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1585
return (vector->p_HMAC_Init)(cx, hashObj, secret, secret_len, isFIPS);
1589
HMAC_Begin(HMACContext *cx)
1591
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1593
(vector->p_HMAC_Begin)(cx);
1597
HMAC_Update(HMACContext *cx, const unsigned char *data, unsigned int data_len)
1599
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1601
(vector->p_HMAC_Update)(cx, data, data_len);
1605
HMAC_Finish(HMACContext *cx, unsigned char *result, unsigned int *result_len,
1606
unsigned int max_result_len)
1608
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1610
return (vector->p_HMAC_Finish)(cx, result, result_len, max_result_len);
1614
HMAC_Clone(HMACContext *cx)
1616
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1618
return (vector->p_HMAC_Clone)(cx);
1622
RNG_SystemInfoForRNG(void)
1624
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1626
(vector->p_RNG_SystemInfoForRNG)();
1631
FIPS186Change_GenerateX(unsigned char *XKEY, const unsigned char *XSEEDj,
1634
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1636
return (vector->p_FIPS186Change_GenerateX)(XKEY, XSEEDj, x_j);
1640
FIPS186Change_ReduceModQForDSA(const unsigned char *w,
1641
const unsigned char *q,
1644
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1646
return (vector->p_FIPS186Change_ReduceModQForDSA)(w, q, xj);