1 /*
2  * loader.c - load platform dependent DSO containing freebl implementation.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #include "loader.h"
9 #include "prmem.h"
10 #include "prerror.h"
11 #include "prinit.h"
12 #include "prenv.h"
13 #include "blname.c"
14 
15 #include "prio.h"
16 #include "prprf.h"
17 #include <stdio.h>
18 #include "prsystem.h"
19 
20 static const char *NameOfThisSharedLib =
21     SHLIB_PREFIX "softokn" SOFTOKEN_SHLIB_VERSION "." SHLIB_SUFFIX;
22 
23 static PRLibrary *blLib = NULL;
24 
25 #define LSB(x) ((x)&0xff)
26 #define MSB(x) ((x) >> 8)
27 
28 static const FREEBLVector *vector;
29 static const char *libraryName = NULL;
30 
31 #include "genload.c"
32 
33 /* This function must be run only once. */
34 /*  determine if hybrid platform, then actually load the DSO. */
35 static PRStatus
freebl_LoadDSO(void)36 freebl_LoadDSO(void)
37 {
38     PRLibrary *handle;
39     const char *name = getLibName();
40 
41     if (!name) {
42         PR_SetError(PR_LOAD_LIBRARY_ERROR, 0);
43         return PR_FAILURE;
44     }
45 
46     handle = loader_LoadLibrary(name);
47     if (handle) {
48         PRFuncPtr address = PR_FindFunctionSymbol(handle, "FREEBL_GetVector");
49         if (address) {
50             FREEBLGetVectorFn *getVector = (FREEBLGetVectorFn *)address;
51             const FREEBLVector *dsoVector = getVector();
52             if (dsoVector) {
53                 unsigned short dsoVersion = dsoVector->version;
54                 unsigned short myVersion = FREEBL_VERSION;
55                 if (MSB(dsoVersion) == MSB(myVersion) &&
56                     LSB(dsoVersion) >= LSB(myVersion) &&
57                     dsoVector->length >= sizeof(FREEBLVector)) {
58                     vector = dsoVector;
59                     libraryName = name;
60                     blLib = handle;
61                     return PR_SUCCESS;
62                 }
63             }
64         }
65 #ifdef DEBUG
66         if (blLib) {
67             PRStatus status = PR_UnloadLibrary(blLib);
68             PORT_Assert(PR_SUCCESS == status);
69         }
70 #else
71         if (blLib)
72             PR_UnloadLibrary(blLib);
73 #endif
74     }
75     return PR_FAILURE;
76 }
77 
78 static const PRCallOnceType pristineCallOnce;
79 static PRCallOnceType loadFreeBLOnce;
80 
81 static PRStatus
freebl_RunLoaderOnce(void)82 freebl_RunLoaderOnce(void)
83 {
84     PRStatus status;
85 
86     status = PR_CallOnce(&loadFreeBLOnce, &freebl_LoadDSO);
87     return status;
88 }
89 
90 SECStatus
BL_Init(void)91 BL_Init(void)
92 {
93     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
94         return SECFailure;
95     return (vector->p_BL_Init)();
96 }
97 
98 RSAPrivateKey *
RSA_NewKey(int keySizeInBits,SECItem * publicExponent)99 RSA_NewKey(int keySizeInBits, SECItem *publicExponent)
100 {
101     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
102         return NULL;
103     return (vector->p_RSA_NewKey)(keySizeInBits, publicExponent);
104 }
105 
106 SECStatus
RSA_PublicKeyOp(RSAPublicKey * key,unsigned char * output,const unsigned char * input)107 RSA_PublicKeyOp(RSAPublicKey *key,
108                 unsigned char *output,
109                 const unsigned char *input)
110 {
111     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
112         return SECFailure;
113     return (vector->p_RSA_PublicKeyOp)(key, output, input);
114 }
115 
116 SECStatus
RSA_PrivateKeyOp(RSAPrivateKey * key,unsigned char * output,const unsigned char * input)117 RSA_PrivateKeyOp(RSAPrivateKey *key,
118                  unsigned char *output,
119                  const unsigned char *input)
120 {
121     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
122         return SECFailure;
123     return (vector->p_RSA_PrivateKeyOp)(key, output, input);
124 }
125 
126 SECStatus
RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey * key,unsigned char * output,const unsigned char * input)127 RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey *key,
128                               unsigned char *output,
129                               const unsigned char *input)
130 {
131     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
132         return SECFailure;
133     return (vector->p_RSA_PrivateKeyOpDoubleChecked)(key, output, input);
134 }
135 
136 SECStatus
RSA_PrivateKeyCheck(const RSAPrivateKey * key)137 RSA_PrivateKeyCheck(const RSAPrivateKey *key)
138 {
139     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
140         return SECFailure;
141     return (vector->p_RSA_PrivateKeyCheck)(key);
142 }
143 
144 SECStatus
DSA_NewKey(const PQGParams * params,DSAPrivateKey ** privKey)145 DSA_NewKey(const PQGParams *params, DSAPrivateKey **privKey)
146 {
147     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
148         return SECFailure;
149     return (vector->p_DSA_NewKey)(params, privKey);
150 }
151 
152 SECStatus
DSA_SignDigest(DSAPrivateKey * key,SECItem * signature,const SECItem * digest)153 DSA_SignDigest(DSAPrivateKey *key, SECItem *signature, const SECItem *digest)
154 {
155     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
156         return SECFailure;
157     return (vector->p_DSA_SignDigest)(key, signature, digest);
158 }
159 
160 SECStatus
DSA_VerifyDigest(DSAPublicKey * key,const SECItem * signature,const SECItem * digest)161 DSA_VerifyDigest(DSAPublicKey *key, const SECItem *signature,
162                  const SECItem *digest)
163 {
164     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
165         return SECFailure;
166     return (vector->p_DSA_VerifyDigest)(key, signature, digest);
167 }
168 
169 SECStatus
DSA_NewKeyFromSeed(const PQGParams * params,const unsigned char * seed,DSAPrivateKey ** privKey)170 DSA_NewKeyFromSeed(const PQGParams *params, const unsigned char *seed,
171                    DSAPrivateKey **privKey)
172 {
173     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
174         return SECFailure;
175     return (vector->p_DSA_NewKeyFromSeed)(params, seed, privKey);
176 }
177 
178 SECStatus
DSA_SignDigestWithSeed(DSAPrivateKey * key,SECItem * signature,const SECItem * digest,const unsigned char * seed)179 DSA_SignDigestWithSeed(DSAPrivateKey *key, SECItem *signature,
180                        const SECItem *digest, const unsigned char *seed)
181 {
182     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
183         return SECFailure;
184     return (vector->p_DSA_SignDigestWithSeed)(key, signature, digest, seed);
185 }
186 
187 SECStatus
DSA_NewRandom(PLArenaPool * arena,const SECItem * q,SECItem * seed)188 DSA_NewRandom(PLArenaPool *arena, const SECItem *q, SECItem *seed)
189 {
190     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
191         return SECFailure;
192     return (vector->p_DSA_NewRandom)(arena, q, seed);
193 }
194 
195 SECStatus
DH_GenParam(int primeLen,DHParams ** params)196 DH_GenParam(int primeLen, DHParams **params)
197 {
198     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
199         return SECFailure;
200     return (vector->p_DH_GenParam)(primeLen, params);
201 }
202 
203 SECStatus
DH_NewKey(DHParams * params,DHPrivateKey ** privKey)204 DH_NewKey(DHParams *params, DHPrivateKey **privKey)
205 {
206     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
207         return SECFailure;
208     return (vector->p_DH_NewKey)(params, privKey);
209 }
210 
211 SECStatus
DH_Derive(SECItem * publicValue,SECItem * prime,SECItem * privateValue,SECItem * derivedSecret,unsigned int maxOutBytes)212 DH_Derive(SECItem *publicValue, SECItem *prime, SECItem *privateValue,
213           SECItem *derivedSecret, unsigned int maxOutBytes)
214 {
215     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
216         return SECFailure;
217     return (vector->p_DH_Derive)(publicValue, prime, privateValue,
218                                  derivedSecret, maxOutBytes);
219 }
220 
221 SECStatus
KEA_Derive(SECItem * prime,SECItem * public1,SECItem * public2,SECItem * private1,SECItem * private2,SECItem * derivedSecret)222 KEA_Derive(SECItem *prime, SECItem *public1, SECItem *public2,
223            SECItem *private1, SECItem *private2, SECItem *derivedSecret)
224 {
225     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
226         return SECFailure;
227     return (vector->p_KEA_Derive)(prime, public1, public2,
228                                   private1, private2, derivedSecret);
229 }
230 
231 PRBool
KEA_Verify(SECItem * Y,SECItem * prime,SECItem * subPrime)232 KEA_Verify(SECItem *Y, SECItem *prime, SECItem *subPrime)
233 {
234     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
235         return PR_FALSE;
236     return (vector->p_KEA_Verify)(Y, prime, subPrime);
237 }
238 
239 PRBool
KEA_PrimeCheck(SECItem * prime)240 KEA_PrimeCheck(SECItem *prime)
241 {
242     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
243         return PR_FALSE;
244     return (vector->p_KEA_PrimeCheck)(prime);
245 }
246 
247 RC4Context *
RC4_CreateContext(const unsigned char * key,int len)248 RC4_CreateContext(const unsigned char *key, int len)
249 {
250     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
251         return NULL;
252     return (vector->p_RC4_CreateContext)(key, len);
253 }
254 
255 void
RC4_DestroyContext(RC4Context * cx,PRBool freeit)256 RC4_DestroyContext(RC4Context *cx, PRBool freeit)
257 {
258     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
259         return;
260     (vector->p_RC4_DestroyContext)(cx, freeit);
261 }
262 
263 SECStatus
RC4_Encrypt(RC4Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)264 RC4_Encrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen,
265             unsigned int maxOutputLen, const unsigned char *input,
266             unsigned int inputLen)
267 {
268     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
269         return SECFailure;
270     return (vector->p_RC4_Encrypt)(cx, output, outputLen, maxOutputLen, input,
271                                    inputLen);
272 }
273 
274 SECStatus
RC4_Decrypt(RC4Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)275 RC4_Decrypt(RC4Context *cx, unsigned char *output, unsigned int *outputLen,
276             unsigned int maxOutputLen, const unsigned char *input,
277             unsigned int inputLen)
278 {
279     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
280         return SECFailure;
281     return (vector->p_RC4_Decrypt)(cx, output, outputLen, maxOutputLen, input,
282                                    inputLen);
283 }
284 
285 RC2Context *
RC2_CreateContext(const unsigned char * key,unsigned int len,const unsigned char * iv,int mode,unsigned effectiveKeyLen)286 RC2_CreateContext(const unsigned char *key, unsigned int len,
287                   const unsigned char *iv, int mode, unsigned effectiveKeyLen)
288 {
289     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
290         return NULL;
291 #ifndef NSS_DISABLE_DEPRECATED_RC2
292     return (vector->p_RC2_CreateContext)(key, len, iv, mode, effectiveKeyLen);
293 #else
294     return NULL;
295 #endif
296 }
297 
298 void
RC2_DestroyContext(RC2Context * cx,PRBool freeit)299 RC2_DestroyContext(RC2Context *cx, PRBool freeit)
300 {
301     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
302         return;
303 #ifndef NSS_DISABLE_DEPRECATED_RC2
304     (vector->p_RC2_DestroyContext)(cx, freeit);
305 #else
306     return;
307 #endif
308 }
309 
310 SECStatus
RC2_Encrypt(RC2Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)311 RC2_Encrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen,
312             unsigned int maxOutputLen, const unsigned char *input,
313             unsigned int inputLen)
314 {
315     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
316         return SECFailure;
317 #ifndef NSS_DISABLE_DEPRECATED_RC2
318     return (vector->p_RC2_Encrypt)(cx, output, outputLen, maxOutputLen, input,
319                                    inputLen);
320 #else
321     return SECFailure;
322 #endif
323 }
324 
325 SECStatus
RC2_Decrypt(RC2Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)326 RC2_Decrypt(RC2Context *cx, unsigned char *output, unsigned int *outputLen,
327             unsigned int maxOutputLen, const unsigned char *input,
328             unsigned int inputLen)
329 {
330     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
331         return SECFailure;
332 #ifndef NSS_DISABLE_DEPRECATED_RC2
333     return (vector->p_RC2_Decrypt)(cx, output, outputLen, maxOutputLen, input,
334                                    inputLen);
335 #else
336     return SECFailure;
337 #endif
338 }
339 
340 RC5Context *
RC5_CreateContext(const SECItem * key,unsigned int rounds,unsigned int wordSize,const unsigned char * iv,int mode)341 RC5_CreateContext(const SECItem *key, unsigned int rounds,
342                   unsigned int wordSize, const unsigned char *iv, int mode)
343 {
344     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
345         return NULL;
346     return (vector->p_RC5_CreateContext)(key, rounds, wordSize, iv, mode);
347 }
348 
349 void
RC5_DestroyContext(RC5Context * cx,PRBool freeit)350 RC5_DestroyContext(RC5Context *cx, PRBool freeit)
351 {
352     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
353         return;
354     (vector->p_RC5_DestroyContext)(cx, freeit);
355 }
356 
357 SECStatus
RC5_Encrypt(RC5Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)358 RC5_Encrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen,
359             unsigned int maxOutputLen, const unsigned char *input,
360             unsigned int inputLen)
361 {
362     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
363         return SECFailure;
364     return (vector->p_RC5_Encrypt)(cx, output, outputLen, maxOutputLen, input,
365                                    inputLen);
366 }
367 
368 SECStatus
RC5_Decrypt(RC5Context * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)369 RC5_Decrypt(RC5Context *cx, unsigned char *output, unsigned int *outputLen,
370             unsigned int maxOutputLen, const unsigned char *input,
371             unsigned int inputLen)
372 {
373     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
374         return SECFailure;
375     return (vector->p_RC5_Decrypt)(cx, output, outputLen, maxOutputLen, input,
376                                    inputLen);
377 }
378 
379 DESContext *
DES_CreateContext(const unsigned char * key,const unsigned char * iv,int mode,PRBool encrypt)380 DES_CreateContext(const unsigned char *key, const unsigned char *iv,
381                   int mode, PRBool encrypt)
382 {
383     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
384         return NULL;
385     return (vector->p_DES_CreateContext)(key, iv, mode, encrypt);
386 }
387 
388 void
DES_DestroyContext(DESContext * cx,PRBool freeit)389 DES_DestroyContext(DESContext *cx, PRBool freeit)
390 {
391     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
392         return;
393     (vector->p_DES_DestroyContext)(cx, freeit);
394 }
395 
396 SECStatus
DES_Encrypt(DESContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)397 DES_Encrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen,
398             unsigned int maxOutputLen, const unsigned char *input,
399             unsigned int inputLen)
400 {
401     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
402         return SECFailure;
403     return (vector->p_DES_Encrypt)(cx, output, outputLen, maxOutputLen, input,
404                                    inputLen);
405 }
406 
407 SECStatus
DES_Decrypt(DESContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)408 DES_Decrypt(DESContext *cx, unsigned char *output, unsigned int *outputLen,
409             unsigned int maxOutputLen, const unsigned char *input,
410             unsigned int inputLen)
411 {
412     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
413         return SECFailure;
414     return (vector->p_DES_Decrypt)(cx, output, outputLen, maxOutputLen, input,
415                                    inputLen);
416 }
417 SEEDContext *
SEED_CreateContext(const unsigned char * key,const unsigned char * iv,int mode,PRBool encrypt)418 SEED_CreateContext(const unsigned char *key, const unsigned char *iv,
419                    int mode, PRBool encrypt)
420 {
421     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
422         return NULL;
423 #ifndef NSS_DISABLE_DEPRECATED_SEED
424     return (vector->p_SEED_CreateContext)(key, iv, mode, encrypt);
425 #else
426     return NULL;
427 #endif
428 }
429 
430 void
SEED_DestroyContext(SEEDContext * cx,PRBool freeit)431 SEED_DestroyContext(SEEDContext *cx, PRBool freeit)
432 {
433     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
434         return;
435 #ifndef NSS_DISABLE_DEPRECATED_SEED
436     (vector->p_SEED_DestroyContext)(cx, freeit);
437 #else
438     return;
439 #endif
440 }
441 
442 SECStatus
SEED_Encrypt(SEEDContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)443 SEED_Encrypt(SEEDContext *cx, unsigned char *output, unsigned int *outputLen,
444              unsigned int maxOutputLen, const unsigned char *input,
445              unsigned int inputLen)
446 {
447     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
448         return SECFailure;
449 #ifndef NSS_DISABLE_DEPRECATED_SEED
450     return (vector->p_SEED_Encrypt)(cx, output, outputLen, maxOutputLen, input,
451                                     inputLen);
452 #else
453     return SECFailure;
454 #endif
455 }
456 
457 SECStatus
SEED_Decrypt(SEEDContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)458 SEED_Decrypt(SEEDContext *cx, unsigned char *output, unsigned int *outputLen,
459              unsigned int maxOutputLen, const unsigned char *input,
460              unsigned int inputLen)
461 {
462     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
463         return SECFailure;
464 #ifndef NSS_DISABLE_DEPRECATED_SEED
465     return (vector->p_SEED_Decrypt)(cx, output, outputLen, maxOutputLen, input,
466                                     inputLen);
467 #else
468     return SECFailure;
469 #endif
470 }
471 
472 AESContext *
AES_CreateContext(const unsigned char * key,const unsigned char * iv,int mode,int encrypt,unsigned int keylen,unsigned int blocklen)473 AES_CreateContext(const unsigned char *key, const unsigned char *iv,
474                   int mode, int encrypt,
475                   unsigned int keylen, unsigned int blocklen)
476 {
477     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
478         return NULL;
479     return (vector->p_AES_CreateContext)(key, iv, mode, encrypt, keylen,
480                                          blocklen);
481 }
482 
483 void
AES_DestroyContext(AESContext * cx,PRBool freeit)484 AES_DestroyContext(AESContext *cx, PRBool freeit)
485 {
486     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
487         return;
488     (vector->p_AES_DestroyContext)(cx, freeit);
489 }
490 
491 SECStatus
AES_Encrypt(AESContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)492 AES_Encrypt(AESContext *cx, unsigned char *output,
493             unsigned int *outputLen, unsigned int maxOutputLen,
494             const unsigned char *input, unsigned int inputLen)
495 {
496     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
497         return SECFailure;
498     return (vector->p_AES_Encrypt)(cx, output, outputLen, maxOutputLen,
499                                    input, inputLen);
500 }
501 
502 SECStatus
AES_Decrypt(AESContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)503 AES_Decrypt(AESContext *cx, unsigned char *output,
504             unsigned int *outputLen, unsigned int maxOutputLen,
505             const unsigned char *input, unsigned int inputLen)
506 {
507     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
508         return SECFailure;
509     return (vector->p_AES_Decrypt)(cx, output, outputLen, maxOutputLen,
510                                    input, inputLen);
511 }
512 
513 SECStatus
AES_AEAD(AESContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen,void * params,unsigned int paramsLen,const unsigned char * aad,unsigned int aadLen)514 AES_AEAD(AESContext *cx, unsigned char *output,
515          unsigned int *outputLen, unsigned int maxOutputLen,
516          const unsigned char *input, unsigned int inputLen,
517          void *params, unsigned int paramsLen,
518          const unsigned char *aad, unsigned int aadLen)
519 {
520     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
521         return SECFailure;
522     return (vector->p_AES_AEAD)(cx, output, outputLen, maxOutputLen, input,
523                                 inputLen, params, paramsLen, aad, aadLen);
524 }
525 
526 SECStatus
MD5_Hash(unsigned char * dest,const char * src)527 MD5_Hash(unsigned char *dest, const char *src)
528 {
529     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
530         return SECFailure;
531     return (vector->p_MD5_Hash)(dest, src);
532 }
533 
534 SECStatus
MD5_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)535 MD5_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
536 {
537     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
538         return SECFailure;
539     return (vector->p_MD5_HashBuf)(dest, src, src_length);
540 }
541 
542 MD5Context *
MD5_NewContext(void)543 MD5_NewContext(void)
544 {
545     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
546         return NULL;
547     return (vector->p_MD5_NewContext)();
548 }
549 
550 void
MD5_DestroyContext(MD5Context * cx,PRBool freeit)551 MD5_DestroyContext(MD5Context *cx, PRBool freeit)
552 {
553     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
554         return;
555     (vector->p_MD5_DestroyContext)(cx, freeit);
556 }
557 
558 void
MD5_Begin(MD5Context * cx)559 MD5_Begin(MD5Context *cx)
560 {
561     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
562         return;
563     (vector->p_MD5_Begin)(cx);
564 }
565 
566 void
MD5_Update(MD5Context * cx,const unsigned char * input,unsigned int inputLen)567 MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen)
568 {
569     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
570         return;
571     (vector->p_MD5_Update)(cx, input, inputLen);
572 }
573 
574 void
MD5_End(MD5Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)575 MD5_End(MD5Context *cx, unsigned char *digest,
576         unsigned int *digestLen, unsigned int maxDigestLen)
577 {
578     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
579         return;
580     (vector->p_MD5_End)(cx, digest, digestLen, maxDigestLen);
581 }
582 
583 unsigned int
MD5_FlattenSize(MD5Context * cx)584 MD5_FlattenSize(MD5Context *cx)
585 {
586     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
587         return 0;
588     return (vector->p_MD5_FlattenSize)(cx);
589 }
590 
591 SECStatus
MD5_Flatten(MD5Context * cx,unsigned char * space)592 MD5_Flatten(MD5Context *cx, unsigned char *space)
593 {
594     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
595         return SECFailure;
596     return (vector->p_MD5_Flatten)(cx, space);
597 }
598 
599 MD5Context *
MD5_Resurrect(unsigned char * space,void * arg)600 MD5_Resurrect(unsigned char *space, void *arg)
601 {
602     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
603         return NULL;
604     return (vector->p_MD5_Resurrect)(space, arg);
605 }
606 
607 void
MD5_TraceState(MD5Context * cx)608 MD5_TraceState(MD5Context *cx)
609 {
610     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
611         return;
612     (vector->p_MD5_TraceState)(cx);
613 }
614 
615 SECStatus
MD2_Hash(unsigned char * dest,const char * src)616 MD2_Hash(unsigned char *dest, const char *src)
617 {
618     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
619         return SECFailure;
620     return (vector->p_MD2_Hash)(dest, src);
621 }
622 
623 MD2Context *
MD2_NewContext(void)624 MD2_NewContext(void)
625 {
626     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
627         return NULL;
628     return (vector->p_MD2_NewContext)();
629 }
630 
631 void
MD2_DestroyContext(MD2Context * cx,PRBool freeit)632 MD2_DestroyContext(MD2Context *cx, PRBool freeit)
633 {
634     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
635         return;
636     (vector->p_MD2_DestroyContext)(cx, freeit);
637 }
638 
639 void
MD2_Begin(MD2Context * cx)640 MD2_Begin(MD2Context *cx)
641 {
642     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
643         return;
644     (vector->p_MD2_Begin)(cx);
645 }
646 
647 void
MD2_Update(MD2Context * cx,const unsigned char * input,unsigned int inputLen)648 MD2_Update(MD2Context *cx, const unsigned char *input, unsigned int inputLen)
649 {
650     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
651         return;
652     (vector->p_MD2_Update)(cx, input, inputLen);
653 }
654 
655 void
MD2_End(MD2Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)656 MD2_End(MD2Context *cx, unsigned char *digest,
657         unsigned int *digestLen, unsigned int maxDigestLen)
658 {
659     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
660         return;
661     (vector->p_MD2_End)(cx, digest, digestLen, maxDigestLen);
662 }
663 
664 unsigned int
MD2_FlattenSize(MD2Context * cx)665 MD2_FlattenSize(MD2Context *cx)
666 {
667     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
668         return 0;
669     return (vector->p_MD2_FlattenSize)(cx);
670 }
671 
672 SECStatus
MD2_Flatten(MD2Context * cx,unsigned char * space)673 MD2_Flatten(MD2Context *cx, unsigned char *space)
674 {
675     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
676         return SECFailure;
677     return (vector->p_MD2_Flatten)(cx, space);
678 }
679 
680 MD2Context *
MD2_Resurrect(unsigned char * space,void * arg)681 MD2_Resurrect(unsigned char *space, void *arg)
682 {
683     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
684         return NULL;
685     return (vector->p_MD2_Resurrect)(space, arg);
686 }
687 
688 SECStatus
SHA1_Hash(unsigned char * dest,const char * src)689 SHA1_Hash(unsigned char *dest, const char *src)
690 {
691     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
692         return SECFailure;
693     return (vector->p_SHA1_Hash)(dest, src);
694 }
695 
696 SECStatus
SHA1_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)697 SHA1_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
698 {
699     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
700         return SECFailure;
701     return (vector->p_SHA1_HashBuf)(dest, src, src_length);
702 }
703 
704 SHA1Context *
SHA1_NewContext(void)705 SHA1_NewContext(void)
706 {
707     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
708         return NULL;
709     return (vector->p_SHA1_NewContext)();
710 }
711 
712 void
SHA1_DestroyContext(SHA1Context * cx,PRBool freeit)713 SHA1_DestroyContext(SHA1Context *cx, PRBool freeit)
714 {
715     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
716         return;
717     (vector->p_SHA1_DestroyContext)(cx, freeit);
718 }
719 
720 void
SHA1_Begin(SHA1Context * cx)721 SHA1_Begin(SHA1Context *cx)
722 {
723     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
724         return;
725     (vector->p_SHA1_Begin)(cx);
726 }
727 
728 void
SHA1_Update(SHA1Context * cx,const unsigned char * input,unsigned int inputLen)729 SHA1_Update(SHA1Context *cx, const unsigned char *input,
730             unsigned int inputLen)
731 {
732     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
733         return;
734     (vector->p_SHA1_Update)(cx, input, inputLen);
735 }
736 
737 void
SHA1_End(SHA1Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)738 SHA1_End(SHA1Context *cx, unsigned char *digest,
739          unsigned int *digestLen, unsigned int maxDigestLen)
740 {
741     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
742         return;
743     (vector->p_SHA1_End)(cx, digest, digestLen, maxDigestLen);
744 }
745 
746 void
SHA1_TraceState(SHA1Context * cx)747 SHA1_TraceState(SHA1Context *cx)
748 {
749     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
750         return;
751     (vector->p_SHA1_TraceState)(cx);
752 }
753 
754 unsigned int
SHA1_FlattenSize(SHA1Context * cx)755 SHA1_FlattenSize(SHA1Context *cx)
756 {
757     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
758         return 0;
759     return (vector->p_SHA1_FlattenSize)(cx);
760 }
761 
762 SECStatus
SHA1_Flatten(SHA1Context * cx,unsigned char * space)763 SHA1_Flatten(SHA1Context *cx, unsigned char *space)
764 {
765     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
766         return SECFailure;
767     return (vector->p_SHA1_Flatten)(cx, space);
768 }
769 
770 SHA1Context *
SHA1_Resurrect(unsigned char * space,void * arg)771 SHA1_Resurrect(unsigned char *space, void *arg)
772 {
773     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
774         return NULL;
775     return (vector->p_SHA1_Resurrect)(space, arg);
776 }
777 
778 SECStatus
RNG_RNGInit(void)779 RNG_RNGInit(void)
780 {
781     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
782         return SECFailure;
783     return (vector->p_RNG_RNGInit)();
784 }
785 
786 SECStatus
RNG_RandomUpdate(const void * data,size_t bytes)787 RNG_RandomUpdate(const void *data, size_t bytes)
788 {
789     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
790         return SECFailure;
791     return (vector->p_RNG_RandomUpdate)(data, bytes);
792 }
793 
794 SECStatus
RNG_GenerateGlobalRandomBytes(void * dest,size_t len)795 RNG_GenerateGlobalRandomBytes(void *dest, size_t len)
796 {
797     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
798         return SECFailure;
799     return (vector->p_RNG_GenerateGlobalRandomBytes)(dest, len);
800 }
801 
802 void
RNG_RNGShutdown(void)803 RNG_RNGShutdown(void)
804 {
805     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
806         return;
807     (vector->p_RNG_RNGShutdown)();
808 }
809 
810 SECStatus
PQG_ParamGen(unsigned int j,PQGParams ** pParams,PQGVerify ** pVfy)811 PQG_ParamGen(unsigned int j, PQGParams **pParams, PQGVerify **pVfy)
812 {
813     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
814         return SECFailure;
815     return (vector->p_PQG_ParamGen)(j, pParams, pVfy);
816 }
817 
818 SECStatus
PQG_ParamGenSeedLen(unsigned int j,unsigned int seedBytes,PQGParams ** pParams,PQGVerify ** pVfy)819 PQG_ParamGenSeedLen(unsigned int j, unsigned int seedBytes,
820                     PQGParams **pParams, PQGVerify **pVfy)
821 {
822     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
823         return SECFailure;
824     return (vector->p_PQG_ParamGenSeedLen)(j, seedBytes, pParams, pVfy);
825 }
826 
827 SECStatus
PQG_VerifyParams(const PQGParams * params,const PQGVerify * vfy,SECStatus * result)828 PQG_VerifyParams(const PQGParams *params, const PQGVerify *vfy,
829                  SECStatus *result)
830 {
831     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
832         return SECFailure;
833     return (vector->p_PQG_VerifyParams)(params, vfy, result);
834 }
835 
836 void
PQG_DestroyParams(PQGParams * params)837 PQG_DestroyParams(PQGParams *params)
838 {
839     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
840         return;
841     (vector->p_PQG_DestroyParams)(params);
842 }
843 
844 void
PQG_DestroyVerify(PQGVerify * vfy)845 PQG_DestroyVerify(PQGVerify *vfy)
846 {
847     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
848         return;
849     (vector->p_PQG_DestroyVerify)(vfy);
850 }
851 
852 void
BL_Cleanup(void)853 BL_Cleanup(void)
854 {
855     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
856         return;
857     (vector->p_BL_Cleanup)();
858 }
859 
860 void
BL_Unload(void)861 BL_Unload(void)
862 {
863     /* This function is not thread-safe, but doesn't need to be, because it is
864      * only called from functions that are also defined as not thread-safe,
865      * namely C_Finalize in softoken, and the SSL bypass shutdown callback called
866      * from NSS_Shutdown. */
867     char *disableUnload = NULL;
868     vector = NULL;
869     disableUnload = PR_GetEnvSecure("NSS_DISABLE_UNLOAD");
870     if (blLib && !disableUnload) {
871 #ifdef DEBUG
872         PRStatus status = PR_UnloadLibrary(blLib);
873         PORT_Assert(PR_SUCCESS == status);
874 #else
875         PR_UnloadLibrary(blLib);
876 #endif
877     }
878     blLib = NULL;
879     loadFreeBLOnce = pristineCallOnce;
880 }
881 
882 /* ============== New for 3.003 =============================== */
883 
884 SECStatus
SHA256_Hash(unsigned char * dest,const char * src)885 SHA256_Hash(unsigned char *dest, const char *src)
886 {
887     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
888         return SECFailure;
889     return (vector->p_SHA256_Hash)(dest, src);
890 }
891 
892 SECStatus
SHA256_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)893 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
894 {
895     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
896         return SECFailure;
897     return (vector->p_SHA256_HashBuf)(dest, src, src_length);
898 }
899 
900 SHA256Context *
SHA256_NewContext(void)901 SHA256_NewContext(void)
902 {
903     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
904         return NULL;
905     return (vector->p_SHA256_NewContext)();
906 }
907 
908 void
SHA256_DestroyContext(SHA256Context * cx,PRBool freeit)909 SHA256_DestroyContext(SHA256Context *cx, PRBool freeit)
910 {
911     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
912         return;
913     (vector->p_SHA256_DestroyContext)(cx, freeit);
914 }
915 
916 void
SHA256_Begin(SHA256Context * cx)917 SHA256_Begin(SHA256Context *cx)
918 {
919     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
920         return;
921     (vector->p_SHA256_Begin)(cx);
922 }
923 
924 void
SHA256_Update(SHA256Context * cx,const unsigned char * input,unsigned int inputLen)925 SHA256_Update(SHA256Context *cx, const unsigned char *input,
926               unsigned int inputLen)
927 {
928     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
929         return;
930     (vector->p_SHA256_Update)(cx, input, inputLen);
931 }
932 
933 void
SHA256_End(SHA256Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)934 SHA256_End(SHA256Context *cx, unsigned char *digest,
935            unsigned int *digestLen, unsigned int maxDigestLen)
936 {
937     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
938         return;
939     (vector->p_SHA256_End)(cx, digest, digestLen, maxDigestLen);
940 }
941 
942 void
SHA256_TraceState(SHA256Context * cx)943 SHA256_TraceState(SHA256Context *cx)
944 {
945     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
946         return;
947     (vector->p_SHA256_TraceState)(cx);
948 }
949 
950 unsigned int
SHA256_FlattenSize(SHA256Context * cx)951 SHA256_FlattenSize(SHA256Context *cx)
952 {
953     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
954         return 0;
955     return (vector->p_SHA256_FlattenSize)(cx);
956 }
957 
958 SECStatus
SHA256_Flatten(SHA256Context * cx,unsigned char * space)959 SHA256_Flatten(SHA256Context *cx, unsigned char *space)
960 {
961     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
962         return SECFailure;
963     return (vector->p_SHA256_Flatten)(cx, space);
964 }
965 
966 SHA256Context *
SHA256_Resurrect(unsigned char * space,void * arg)967 SHA256_Resurrect(unsigned char *space, void *arg)
968 {
969     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
970         return NULL;
971     return (vector->p_SHA256_Resurrect)(space, arg);
972 }
973 
974 SECStatus
SHA512_Hash(unsigned char * dest,const char * src)975 SHA512_Hash(unsigned char *dest, const char *src)
976 {
977     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
978         return SECFailure;
979     return (vector->p_SHA512_Hash)(dest, src);
980 }
981 
982 SECStatus
SHA512_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)983 SHA512_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
984 {
985     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
986         return SECFailure;
987     return (vector->p_SHA512_HashBuf)(dest, src, src_length);
988 }
989 
990 SHA512Context *
SHA512_NewContext(void)991 SHA512_NewContext(void)
992 {
993     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
994         return NULL;
995     return (vector->p_SHA512_NewContext)();
996 }
997 
998 void
SHA512_DestroyContext(SHA512Context * cx,PRBool freeit)999 SHA512_DestroyContext(SHA512Context *cx, PRBool freeit)
1000 {
1001     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1002         return;
1003     (vector->p_SHA512_DestroyContext)(cx, freeit);
1004 }
1005 
1006 void
SHA512_Begin(SHA512Context * cx)1007 SHA512_Begin(SHA512Context *cx)
1008 {
1009     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1010         return;
1011     (vector->p_SHA512_Begin)(cx);
1012 }
1013 
1014 void
SHA512_Update(SHA512Context * cx,const unsigned char * input,unsigned int inputLen)1015 SHA512_Update(SHA512Context *cx, const unsigned char *input,
1016               unsigned int inputLen)
1017 {
1018     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1019         return;
1020     (vector->p_SHA512_Update)(cx, input, inputLen);
1021 }
1022 
1023 void
SHA512_End(SHA512Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)1024 SHA512_End(SHA512Context *cx, unsigned char *digest,
1025            unsigned int *digestLen, unsigned int maxDigestLen)
1026 {
1027     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1028         return;
1029     (vector->p_SHA512_End)(cx, digest, digestLen, maxDigestLen);
1030 }
1031 
1032 void
SHA512_TraceState(SHA512Context * cx)1033 SHA512_TraceState(SHA512Context *cx)
1034 {
1035     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1036         return;
1037     (vector->p_SHA512_TraceState)(cx);
1038 }
1039 
1040 unsigned int
SHA512_FlattenSize(SHA512Context * cx)1041 SHA512_FlattenSize(SHA512Context *cx)
1042 {
1043     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1044         return 0;
1045     return (vector->p_SHA512_FlattenSize)(cx);
1046 }
1047 
1048 SECStatus
SHA512_Flatten(SHA512Context * cx,unsigned char * space)1049 SHA512_Flatten(SHA512Context *cx, unsigned char *space)
1050 {
1051     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1052         return SECFailure;
1053     return (vector->p_SHA512_Flatten)(cx, space);
1054 }
1055 
1056 SHA512Context *
SHA512_Resurrect(unsigned char * space,void * arg)1057 SHA512_Resurrect(unsigned char *space, void *arg)
1058 {
1059     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1060         return NULL;
1061     return (vector->p_SHA512_Resurrect)(space, arg);
1062 }
1063 
1064 SECStatus
SHA384_Hash(unsigned char * dest,const char * src)1065 SHA384_Hash(unsigned char *dest, const char *src)
1066 {
1067     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1068         return SECFailure;
1069     return (vector->p_SHA384_Hash)(dest, src);
1070 }
1071 
1072 SECStatus
SHA384_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)1073 SHA384_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
1074 {
1075     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1076         return SECFailure;
1077     return (vector->p_SHA384_HashBuf)(dest, src, src_length);
1078 }
1079 
1080 SHA384Context *
SHA384_NewContext(void)1081 SHA384_NewContext(void)
1082 {
1083     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1084         return NULL;
1085     return (vector->p_SHA384_NewContext)();
1086 }
1087 
1088 void
SHA384_DestroyContext(SHA384Context * cx,PRBool freeit)1089 SHA384_DestroyContext(SHA384Context *cx, PRBool freeit)
1090 {
1091     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1092         return;
1093     (vector->p_SHA384_DestroyContext)(cx, freeit);
1094 }
1095 
1096 void
SHA384_Begin(SHA384Context * cx)1097 SHA384_Begin(SHA384Context *cx)
1098 {
1099     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1100         return;
1101     (vector->p_SHA384_Begin)(cx);
1102 }
1103 
1104 void
SHA384_Update(SHA384Context * cx,const unsigned char * input,unsigned int inputLen)1105 SHA384_Update(SHA384Context *cx, const unsigned char *input,
1106               unsigned int inputLen)
1107 {
1108     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1109         return;
1110     (vector->p_SHA384_Update)(cx, input, inputLen);
1111 }
1112 
1113 void
SHA384_End(SHA384Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)1114 SHA384_End(SHA384Context *cx, unsigned char *digest,
1115            unsigned int *digestLen, unsigned int maxDigestLen)
1116 {
1117     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1118         return;
1119     (vector->p_SHA384_End)(cx, digest, digestLen, maxDigestLen);
1120 }
1121 
1122 void
SHA384_TraceState(SHA384Context * cx)1123 SHA384_TraceState(SHA384Context *cx)
1124 {
1125     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1126         return;
1127     (vector->p_SHA384_TraceState)(cx);
1128 }
1129 
1130 unsigned int
SHA384_FlattenSize(SHA384Context * cx)1131 SHA384_FlattenSize(SHA384Context *cx)
1132 {
1133     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1134         return 0;
1135     return (vector->p_SHA384_FlattenSize)(cx);
1136 }
1137 
1138 SECStatus
SHA384_Flatten(SHA384Context * cx,unsigned char * space)1139 SHA384_Flatten(SHA384Context *cx, unsigned char *space)
1140 {
1141     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1142         return SECFailure;
1143     return (vector->p_SHA384_Flatten)(cx, space);
1144 }
1145 
1146 SHA384Context *
SHA384_Resurrect(unsigned char * space,void * arg)1147 SHA384_Resurrect(unsigned char *space, void *arg)
1148 {
1149     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1150         return NULL;
1151     return (vector->p_SHA384_Resurrect)(space, arg);
1152 }
1153 
1154 AESKeyWrapContext *
AESKeyWrap_CreateContext(const unsigned char * key,const unsigned char * iv,int encrypt,unsigned int keylen)1155 AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv,
1156                          int encrypt, unsigned int keylen)
1157 {
1158     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1159         return NULL;
1160     return vector->p_AESKeyWrap_CreateContext(key, iv, encrypt, keylen);
1161 }
1162 
1163 void
AESKeyWrap_DestroyContext(AESKeyWrapContext * cx,PRBool freeit)1164 AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit)
1165 {
1166     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1167         return;
1168     vector->p_AESKeyWrap_DestroyContext(cx, freeit);
1169 }
1170 
1171 SECStatus
AESKeyWrap_Encrypt(AESKeyWrapContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1172 AESKeyWrap_Encrypt(AESKeyWrapContext *cx, unsigned char *output,
1173                    unsigned int *outputLen, unsigned int maxOutputLen,
1174                    const unsigned char *input, unsigned int inputLen)
1175 {
1176     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1177         return SECFailure;
1178     return vector->p_AESKeyWrap_Encrypt(cx, output, outputLen, maxOutputLen,
1179                                         input, inputLen);
1180 }
1181 
1182 SECStatus
AESKeyWrap_Decrypt(AESKeyWrapContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1183 AESKeyWrap_Decrypt(AESKeyWrapContext *cx, unsigned char *output,
1184                    unsigned int *outputLen, unsigned int maxOutputLen,
1185                    const unsigned char *input, unsigned int inputLen)
1186 {
1187     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1188         return SECFailure;
1189     return vector->p_AESKeyWrap_Decrypt(cx, output, outputLen, maxOutputLen,
1190                                         input, inputLen);
1191 }
1192 
1193 SECStatus
AESKeyWrap_EncryptKWP(AESKeyWrapContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1194 AESKeyWrap_EncryptKWP(AESKeyWrapContext *cx, unsigned char *output,
1195                       unsigned int *outputLen, unsigned int maxOutputLen,
1196                       const unsigned char *input, unsigned int inputLen)
1197 {
1198     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1199         return SECFailure;
1200     return vector->p_AESKeyWrap_EncryptKWP(cx, output, outputLen, maxOutputLen,
1201                                            input, inputLen);
1202 }
1203 
1204 SECStatus
AESKeyWrap_DecryptKWP(AESKeyWrapContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1205 AESKeyWrap_DecryptKWP(AESKeyWrapContext *cx, unsigned char *output,
1206                       unsigned int *outputLen, unsigned int maxOutputLen,
1207                       const unsigned char *input, unsigned int inputLen)
1208 {
1209     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1210         return SECFailure;
1211     return vector->p_AESKeyWrap_DecryptKWP(cx, output, outputLen, maxOutputLen,
1212                                            input, inputLen);
1213 }
1214 
1215 PRBool
BLAPI_SHVerify(const char * name,PRFuncPtr addr)1216 BLAPI_SHVerify(const char *name, PRFuncPtr addr)
1217 {
1218     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1219         return PR_FALSE;
1220     return vector->p_BLAPI_SHVerify(name, addr);
1221 }
1222 
1223 /*
1224  * The Caller is expected to pass NULL as the name, which will
1225  * trigger the p_BLAPI_VerifySelf() to return 'TRUE'. Pass the real
1226  * name of the shared library we loaded (the static libraryName set
1227  * in freebl_LoadDSO) to p_BLAPI_VerifySelf.
1228  */
1229 PRBool
BLAPI_VerifySelf(const char * name)1230 BLAPI_VerifySelf(const char *name)
1231 {
1232     PORT_Assert(!name);
1233     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1234         return PR_FALSE;
1235     return vector->p_BLAPI_VerifySelf(libraryName);
1236 }
1237 
1238 /* ============== New for 3.006 =============================== */
1239 
1240 SECStatus
EC_NewKey(ECParams * params,ECPrivateKey ** privKey)1241 EC_NewKey(ECParams *params, ECPrivateKey **privKey)
1242 {
1243     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1244         return SECFailure;
1245     return (vector->p_EC_NewKey)(params, privKey);
1246 }
1247 
1248 SECStatus
EC_NewKeyFromSeed(ECParams * params,ECPrivateKey ** privKey,const unsigned char * seed,int seedlen)1249 EC_NewKeyFromSeed(ECParams *params, ECPrivateKey **privKey,
1250                   const unsigned char *seed, int seedlen)
1251 {
1252     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1253         return SECFailure;
1254     return (vector->p_EC_NewKeyFromSeed)(params, privKey, seed, seedlen);
1255 }
1256 
1257 SECStatus
EC_ValidatePublicKey(ECParams * params,SECItem * publicValue)1258 EC_ValidatePublicKey(ECParams *params, SECItem *publicValue)
1259 {
1260     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1261         return SECFailure;
1262     return (vector->p_EC_ValidatePublicKey)(params, publicValue);
1263 }
1264 
1265 SECStatus
ECDH_Derive(SECItem * publicValue,ECParams * params,SECItem * privateValue,PRBool withCofactor,SECItem * derivedSecret)1266 ECDH_Derive(SECItem *publicValue, ECParams *params, SECItem *privateValue,
1267             PRBool withCofactor, SECItem *derivedSecret)
1268 {
1269     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1270         return SECFailure;
1271     return (vector->p_ECDH_Derive)(publicValue, params, privateValue,
1272                                    withCofactor, derivedSecret);
1273 }
1274 
1275 SECStatus
ECDSA_SignDigest(ECPrivateKey * key,SECItem * signature,const SECItem * digest)1276 ECDSA_SignDigest(ECPrivateKey *key, SECItem *signature,
1277                  const SECItem *digest)
1278 {
1279     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1280         return SECFailure;
1281     return (vector->p_ECDSA_SignDigest)(key, signature, digest);
1282 }
1283 
1284 SECStatus
ECDSA_VerifyDigest(ECPublicKey * key,const SECItem * signature,const SECItem * digest)1285 ECDSA_VerifyDigest(ECPublicKey *key, const SECItem *signature,
1286                    const SECItem *digest)
1287 {
1288     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1289         return SECFailure;
1290     return (vector->p_ECDSA_VerifyDigest)(key, signature, digest);
1291 }
1292 
1293 SECStatus
ECDSA_SignDigestWithSeed(ECPrivateKey * key,SECItem * signature,const SECItem * digest,const unsigned char * seed,const int seedlen)1294 ECDSA_SignDigestWithSeed(ECPrivateKey *key, SECItem *signature,
1295                          const SECItem *digest, const unsigned char *seed, const int seedlen)
1296 {
1297     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1298         return SECFailure;
1299     return (vector->p_ECDSA_SignDigestWithSeed)(key, signature, digest,
1300                                                 seed, seedlen);
1301 }
1302 
1303 /* ============== New for 3.008 =============================== */
1304 
1305 AESContext *
AES_AllocateContext(void)1306 AES_AllocateContext(void)
1307 {
1308     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1309         return NULL;
1310     return (vector->p_AES_AllocateContext)();
1311 }
1312 
1313 AESKeyWrapContext *
AESKeyWrap_AllocateContext(void)1314 AESKeyWrap_AllocateContext(void)
1315 {
1316     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1317         return NULL;
1318     return (vector->p_AESKeyWrap_AllocateContext)();
1319 }
1320 
1321 DESContext *
DES_AllocateContext(void)1322 DES_AllocateContext(void)
1323 {
1324     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1325         return NULL;
1326     return (vector->p_DES_AllocateContext)();
1327 }
1328 
1329 RC2Context *
RC2_AllocateContext(void)1330 RC2_AllocateContext(void)
1331 {
1332     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1333         return NULL;
1334 #ifndef NSS_DISABLE_DEPRECATED_RC2
1335     return (vector->p_RC2_AllocateContext)();
1336 #else
1337     return NULL;
1338 #endif
1339 }
1340 
1341 RC4Context *
RC4_AllocateContext(void)1342 RC4_AllocateContext(void)
1343 {
1344     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1345         return NULL;
1346     return (vector->p_RC4_AllocateContext)();
1347 }
1348 
1349 SECStatus
AES_InitContext(AESContext * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int encrypt,unsigned int blocklen)1350 AES_InitContext(AESContext *cx, const unsigned char *key,
1351                 unsigned int keylen, const unsigned char *iv, int mode,
1352                 unsigned int encrypt, unsigned int blocklen)
1353 {
1354     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1355         return SECFailure;
1356     return (vector->p_AES_InitContext)(cx, key, keylen, iv, mode, encrypt,
1357                                        blocklen);
1358 }
1359 
1360 SECStatus
AESKeyWrap_InitContext(AESKeyWrapContext * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int encrypt,unsigned int blocklen)1361 AESKeyWrap_InitContext(AESKeyWrapContext *cx, const unsigned char *key,
1362                        unsigned int keylen, const unsigned char *iv, int mode,
1363                        unsigned int encrypt, unsigned int blocklen)
1364 {
1365     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1366         return SECFailure;
1367     return (vector->p_AESKeyWrap_InitContext)(cx, key, keylen, iv, mode,
1368                                               encrypt, blocklen);
1369 }
1370 
1371 SECStatus
DES_InitContext(DESContext * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int encrypt,unsigned int xtra)1372 DES_InitContext(DESContext *cx, const unsigned char *key,
1373                 unsigned int keylen, const unsigned char *iv, int mode,
1374                 unsigned int encrypt, unsigned int xtra)
1375 {
1376     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1377         return SECFailure;
1378     return (vector->p_DES_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra);
1379 }
1380 
1381 SECStatus
SEED_InitContext(SEEDContext * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int encrypt,unsigned int xtra)1382 SEED_InitContext(SEEDContext *cx, const unsigned char *key,
1383                  unsigned int keylen, const unsigned char *iv, int mode,
1384                  unsigned int encrypt, unsigned int xtra)
1385 {
1386     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1387         return SECFailure;
1388 #ifndef NSS_DISABLE_DEPRECATED_SEED
1389     return (vector->p_SEED_InitContext)(cx, key, keylen, iv, mode, encrypt, xtra);
1390 #else
1391     return SECFailure;
1392 #endif
1393 }
1394 
1395 SECStatus
RC2_InitContext(RC2Context * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int effectiveKeyLen,unsigned int xtra)1396 RC2_InitContext(RC2Context *cx, const unsigned char *key,
1397                 unsigned int keylen, const unsigned char *iv, int mode,
1398                 unsigned int effectiveKeyLen, unsigned int xtra)
1399 {
1400     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1401         return SECFailure;
1402 #ifndef NSS_DISABLE_DEPRECATED_RC2
1403     return (vector->p_RC2_InitContext)(cx, key, keylen, iv, mode,
1404                                        effectiveKeyLen, xtra);
1405 #else
1406     return SECFailure;
1407 #endif
1408 }
1409 
1410 SECStatus
RC4_InitContext(RC4Context * cx,const unsigned char * key,unsigned int keylen,const unsigned char * x1,int x2,unsigned int x3,unsigned int x4)1411 RC4_InitContext(RC4Context *cx, const unsigned char *key,
1412                 unsigned int keylen, const unsigned char *x1, int x2,
1413                 unsigned int x3, unsigned int x4)
1414 {
1415     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1416         return SECFailure;
1417     return (vector->p_RC4_InitContext)(cx, key, keylen, x1, x2, x3, x4);
1418 }
1419 
1420 void
MD2_Clone(MD2Context * dest,MD2Context * src)1421 MD2_Clone(MD2Context *dest, MD2Context *src)
1422 {
1423     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1424         return;
1425     (vector->p_MD2_Clone)(dest, src);
1426 }
1427 
1428 void
MD5_Clone(MD5Context * dest,MD5Context * src)1429 MD5_Clone(MD5Context *dest, MD5Context *src)
1430 {
1431     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1432         return;
1433     (vector->p_MD5_Clone)(dest, src);
1434 }
1435 
1436 void
SHA1_Clone(SHA1Context * dest,SHA1Context * src)1437 SHA1_Clone(SHA1Context *dest, SHA1Context *src)
1438 {
1439     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1440         return;
1441     (vector->p_SHA1_Clone)(dest, src);
1442 }
1443 
1444 void
SHA256_Clone(SHA256Context * dest,SHA256Context * src)1445 SHA256_Clone(SHA256Context *dest, SHA256Context *src)
1446 {
1447     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1448         return;
1449     (vector->p_SHA256_Clone)(dest, src);
1450 }
1451 
1452 void
SHA384_Clone(SHA384Context * dest,SHA384Context * src)1453 SHA384_Clone(SHA384Context *dest, SHA384Context *src)
1454 {
1455     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1456         return;
1457     (vector->p_SHA384_Clone)(dest, src);
1458 }
1459 
1460 void
SHA512_Clone(SHA512Context * dest,SHA512Context * src)1461 SHA512_Clone(SHA512Context *dest, SHA512Context *src)
1462 {
1463     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1464         return;
1465     (vector->p_SHA512_Clone)(dest, src);
1466 }
1467 
1468 SECStatus
TLS_PRF(const SECItem * secret,const char * label,SECItem * seed,SECItem * result,PRBool isFIPS)1469 TLS_PRF(const SECItem *secret, const char *label,
1470         SECItem *seed, SECItem *result, PRBool isFIPS)
1471 {
1472     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1473         return SECFailure;
1474     return (vector->p_TLS_PRF)(secret, label, seed, result, isFIPS);
1475 }
1476 
1477 const SECHashObject *
HASH_GetRawHashObject(HASH_HashType hashType)1478 HASH_GetRawHashObject(HASH_HashType hashType)
1479 {
1480     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1481         return NULL;
1482     return (vector->p_HASH_GetRawHashObject)(hashType);
1483 }
1484 
1485 void
HMAC_Destroy(HMACContext * cx,PRBool freeit)1486 HMAC_Destroy(HMACContext *cx, PRBool freeit)
1487 {
1488     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1489         return;
1490     (vector->p_HMAC_Destroy)(cx, freeit);
1491 }
1492 
1493 HMACContext *
HMAC_Create(const SECHashObject * hashObj,const unsigned char * secret,unsigned int secret_len,PRBool isFIPS)1494 HMAC_Create(const SECHashObject *hashObj, const unsigned char *secret,
1495             unsigned int secret_len, PRBool isFIPS)
1496 {
1497     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1498         return NULL;
1499     return (vector->p_HMAC_Create)(hashObj, secret, secret_len, isFIPS);
1500 }
1501 
1502 SECStatus
HMAC_Init(HMACContext * cx,const SECHashObject * hashObj,const unsigned char * secret,unsigned int secret_len,PRBool isFIPS)1503 HMAC_Init(HMACContext *cx, const SECHashObject *hashObj,
1504           const unsigned char *secret, unsigned int secret_len, PRBool isFIPS)
1505 {
1506     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1507         return SECFailure;
1508     return (vector->p_HMAC_Init)(cx, hashObj, secret, secret_len, isFIPS);
1509 }
1510 
1511 void
HMAC_Begin(HMACContext * cx)1512 HMAC_Begin(HMACContext *cx)
1513 {
1514     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1515         return;
1516     (vector->p_HMAC_Begin)(cx);
1517 }
1518 
1519 void
HMAC_Update(HMACContext * cx,const unsigned char * data,unsigned int data_len)1520 HMAC_Update(HMACContext *cx, const unsigned char *data, unsigned int data_len)
1521 {
1522     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1523         return;
1524     (vector->p_HMAC_Update)(cx, data, data_len);
1525 }
1526 
1527 SECStatus
HMAC_Finish(HMACContext * cx,unsigned char * result,unsigned int * result_len,unsigned int max_result_len)1528 HMAC_Finish(HMACContext *cx, unsigned char *result, unsigned int *result_len,
1529             unsigned int max_result_len)
1530 {
1531     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1532         return SECFailure;
1533     return (vector->p_HMAC_Finish)(cx, result, result_len, max_result_len);
1534 }
1535 
1536 HMACContext *
HMAC_Clone(HMACContext * cx)1537 HMAC_Clone(HMACContext *cx)
1538 {
1539     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1540         return NULL;
1541     return (vector->p_HMAC_Clone)(cx);
1542 }
1543 
1544 void
RNG_SystemInfoForRNG(void)1545 RNG_SystemInfoForRNG(void)
1546 {
1547     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1548         return;
1549     (vector->p_RNG_SystemInfoForRNG)();
1550 }
1551 
1552 SECStatus
FIPS186Change_GenerateX(unsigned char * XKEY,const unsigned char * XSEEDj,unsigned char * x_j)1553 FIPS186Change_GenerateX(unsigned char *XKEY, const unsigned char *XSEEDj,
1554                         unsigned char *x_j)
1555 {
1556     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1557         return SECFailure;
1558     return (vector->p_FIPS186Change_GenerateX)(XKEY, XSEEDj, x_j);
1559 }
1560 
1561 SECStatus
FIPS186Change_ReduceModQForDSA(const unsigned char * w,const unsigned char * q,unsigned char * xj)1562 FIPS186Change_ReduceModQForDSA(const unsigned char *w,
1563                                const unsigned char *q,
1564                                unsigned char *xj)
1565 {
1566     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1567         return SECFailure;
1568     return (vector->p_FIPS186Change_ReduceModQForDSA)(w, q, xj);
1569 }
1570 
1571 /* === new for Camellia === */
1572 SECStatus
Camellia_InitContext(CamelliaContext * cx,const unsigned char * key,unsigned int keylen,const unsigned char * iv,int mode,unsigned int encrypt,unsigned int unused)1573 Camellia_InitContext(CamelliaContext *cx, const unsigned char *key,
1574                      unsigned int keylen, const unsigned char *iv, int mode,
1575                      unsigned int encrypt, unsigned int unused)
1576 {
1577     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1578         return SECFailure;
1579     return (vector->p_Camellia_InitContext)(cx, key, keylen, iv, mode, encrypt,
1580                                             unused);
1581 }
1582 
1583 CamelliaContext *
Camellia_AllocateContext(void)1584 Camellia_AllocateContext(void)
1585 {
1586     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1587         return NULL;
1588     return (vector->p_Camellia_AllocateContext)();
1589 }
1590 
1591 CamelliaContext *
Camellia_CreateContext(const unsigned char * key,const unsigned char * iv,int mode,int encrypt,unsigned int keylen)1592 Camellia_CreateContext(const unsigned char *key, const unsigned char *iv,
1593                        int mode, int encrypt,
1594                        unsigned int keylen)
1595 {
1596     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1597         return NULL;
1598     return (vector->p_Camellia_CreateContext)(key, iv, mode, encrypt, keylen);
1599 }
1600 
1601 void
Camellia_DestroyContext(CamelliaContext * cx,PRBool freeit)1602 Camellia_DestroyContext(CamelliaContext *cx, PRBool freeit)
1603 {
1604     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1605         return;
1606     (vector->p_Camellia_DestroyContext)(cx, freeit);
1607 }
1608 
1609 SECStatus
Camellia_Encrypt(CamelliaContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1610 Camellia_Encrypt(CamelliaContext *cx, unsigned char *output,
1611                  unsigned int *outputLen, unsigned int maxOutputLen,
1612                  const unsigned char *input, unsigned int inputLen)
1613 {
1614     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1615         return SECFailure;
1616     return (vector->p_Camellia_Encrypt)(cx, output, outputLen, maxOutputLen,
1617                                         input, inputLen);
1618 }
1619 
1620 SECStatus
Camellia_Decrypt(CamelliaContext * cx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1621 Camellia_Decrypt(CamelliaContext *cx, unsigned char *output,
1622                  unsigned int *outputLen, unsigned int maxOutputLen,
1623                  const unsigned char *input, unsigned int inputLen)
1624 {
1625     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1626         return SECFailure;
1627     return (vector->p_Camellia_Decrypt)(cx, output, outputLen, maxOutputLen,
1628                                         input, inputLen);
1629 }
1630 
1631 void
BL_SetForkState(PRBool forked)1632 BL_SetForkState(PRBool forked)
1633 {
1634     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1635         return;
1636     (vector->p_BL_SetForkState)(forked);
1637 }
1638 
1639 SECStatus
PRNGTEST_Instantiate(const PRUint8 * entropy,unsigned int entropy_len,const PRUint8 * nonce,unsigned int nonce_len,const PRUint8 * personal_string,unsigned int ps_len)1640 PRNGTEST_Instantiate(const PRUint8 *entropy, unsigned int entropy_len,
1641                      const PRUint8 *nonce, unsigned int nonce_len,
1642                      const PRUint8 *personal_string, unsigned int ps_len)
1643 {
1644     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1645         return SECFailure;
1646     return (vector->p_PRNGTEST_Instantiate)(entropy, entropy_len,
1647                                             nonce, nonce_len,
1648                                             personal_string, ps_len);
1649 }
1650 
1651 SECStatus
PRNGTEST_Reseed(const PRUint8 * entropy,unsigned int entropy_len,const PRUint8 * additional,unsigned int additional_len)1652 PRNGTEST_Reseed(const PRUint8 *entropy, unsigned int entropy_len,
1653                 const PRUint8 *additional, unsigned int additional_len)
1654 {
1655     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1656         return SECFailure;
1657     return (vector->p_PRNGTEST_Reseed)(entropy, entropy_len,
1658                                        additional, additional_len);
1659 }
1660 
1661 SECStatus
PRNGTEST_Generate(PRUint8 * bytes,unsigned int bytes_len,const PRUint8 * additional,unsigned int additional_len)1662 PRNGTEST_Generate(PRUint8 *bytes, unsigned int bytes_len,
1663                   const PRUint8 *additional, unsigned int additional_len)
1664 {
1665     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1666         return SECFailure;
1667     return (vector->p_PRNGTEST_Generate)(bytes, bytes_len,
1668                                          additional, additional_len);
1669 }
1670 
1671 SECStatus
PRNGTEST_Uninstantiate()1672 PRNGTEST_Uninstantiate()
1673 {
1674     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1675         return SECFailure;
1676     return (vector->p_PRNGTEST_Uninstantiate)();
1677 }
1678 
1679 SECStatus
RSA_PopulatePrivateKey(RSAPrivateKey * key)1680 RSA_PopulatePrivateKey(RSAPrivateKey *key)
1681 {
1682     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1683         return SECFailure;
1684     return (vector->p_RSA_PopulatePrivateKey)(key);
1685 }
1686 
1687 SECStatus
JPAKE_Sign(PLArenaPool * arena,const PQGParams * pqg,HASH_HashType hashType,const SECItem * signerID,const SECItem * x,const SECItem * testRandom,const SECItem * gxIn,SECItem * gxOut,SECItem * gv,SECItem * r)1688 JPAKE_Sign(PLArenaPool *arena, const PQGParams *pqg, HASH_HashType hashType,
1689            const SECItem *signerID, const SECItem *x,
1690            const SECItem *testRandom, const SECItem *gxIn, SECItem *gxOut,
1691            SECItem *gv, SECItem *r)
1692 {
1693     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1694         return SECFailure;
1695     return (vector->p_JPAKE_Sign)(arena, pqg, hashType, signerID, x,
1696                                   testRandom, gxIn, gxOut, gv, r);
1697 }
1698 
1699 SECStatus
JPAKE_Verify(PLArenaPool * arena,const PQGParams * pqg,HASH_HashType hashType,const SECItem * signerID,const SECItem * peerID,const SECItem * gx,const SECItem * gv,const SECItem * r)1700 JPAKE_Verify(PLArenaPool *arena, const PQGParams *pqg,
1701              HASH_HashType hashType, const SECItem *signerID,
1702              const SECItem *peerID, const SECItem *gx,
1703              const SECItem *gv, const SECItem *r)
1704 {
1705     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1706         return SECFailure;
1707     return (vector->p_JPAKE_Verify)(arena, pqg, hashType, signerID, peerID,
1708                                     gx, gv, r);
1709 }
1710 
1711 SECStatus
JPAKE_Round2(PLArenaPool * arena,const SECItem * p,const SECItem * q,const SECItem * gx1,const SECItem * gx3,const SECItem * gx4,SECItem * base,const SECItem * x2,const SECItem * s,SECItem * x2s)1712 JPAKE_Round2(PLArenaPool *arena, const SECItem *p, const SECItem *q,
1713              const SECItem *gx1, const SECItem *gx3, const SECItem *gx4,
1714              SECItem *base, const SECItem *x2, const SECItem *s, SECItem *x2s)
1715 {
1716     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1717         return SECFailure;
1718     return (vector->p_JPAKE_Round2)(arena, p, q, gx1, gx3, gx4, base, x2, s, x2s);
1719 }
1720 
1721 SECStatus
JPAKE_Final(PLArenaPool * arena,const SECItem * p,const SECItem * q,const SECItem * x2,const SECItem * gx4,const SECItem * x2s,const SECItem * B,SECItem * K)1722 JPAKE_Final(PLArenaPool *arena, const SECItem *p, const SECItem *q,
1723             const SECItem *x2, const SECItem *gx4, const SECItem *x2s,
1724             const SECItem *B, SECItem *K)
1725 {
1726     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1727         return SECFailure;
1728     return (vector->p_JPAKE_Final)(arena, p, q, x2, gx4, x2s, B, K);
1729 }
1730 
1731 SECStatus
TLS_P_hash(HASH_HashType hashAlg,const SECItem * secret,const char * label,SECItem * seed,SECItem * result,PRBool isFIPS)1732 TLS_P_hash(HASH_HashType hashAlg, const SECItem *secret, const char *label,
1733            SECItem *seed, SECItem *result, PRBool isFIPS)
1734 {
1735     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1736         return SECFailure;
1737     return (vector->p_TLS_P_hash)(hashAlg, secret, label, seed, result, isFIPS);
1738 }
1739 
1740 SECStatus
SHA224_Hash(unsigned char * dest,const char * src)1741 SHA224_Hash(unsigned char *dest, const char *src)
1742 {
1743     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1744         return SECFailure;
1745     return (vector->p_SHA224_Hash)(dest, src);
1746 }
1747 
1748 SECStatus
SHA224_HashBuf(unsigned char * dest,const unsigned char * src,PRUint32 src_length)1749 SHA224_HashBuf(unsigned char *dest, const unsigned char *src, PRUint32 src_length)
1750 {
1751     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1752         return SECFailure;
1753     return (vector->p_SHA224_HashBuf)(dest, src, src_length);
1754 }
1755 
1756 SHA224Context *
SHA224_NewContext(void)1757 SHA224_NewContext(void)
1758 {
1759     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1760         return NULL;
1761     return (vector->p_SHA224_NewContext)();
1762 }
1763 
1764 void
SHA224_DestroyContext(SHA224Context * cx,PRBool freeit)1765 SHA224_DestroyContext(SHA224Context *cx, PRBool freeit)
1766 {
1767     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1768         return;
1769     (vector->p_SHA224_DestroyContext)(cx, freeit);
1770 }
1771 
1772 void
SHA224_Begin(SHA256Context * cx)1773 SHA224_Begin(SHA256Context *cx)
1774 {
1775     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1776         return;
1777     (vector->p_SHA224_Begin)(cx);
1778 }
1779 
1780 void
SHA224_Update(SHA224Context * cx,const unsigned char * input,unsigned int inputLen)1781 SHA224_Update(SHA224Context *cx, const unsigned char *input,
1782               unsigned int inputLen)
1783 {
1784     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1785         return;
1786     (vector->p_SHA224_Update)(cx, input, inputLen);
1787 }
1788 
1789 void
SHA224_End(SHA224Context * cx,unsigned char * digest,unsigned int * digestLen,unsigned int maxDigestLen)1790 SHA224_End(SHA224Context *cx, unsigned char *digest,
1791            unsigned int *digestLen, unsigned int maxDigestLen)
1792 {
1793     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1794         return;
1795     (vector->p_SHA224_End)(cx, digest, digestLen, maxDigestLen);
1796 }
1797 
1798 void
SHA224_TraceState(SHA224Context * cx)1799 SHA224_TraceState(SHA224Context *cx)
1800 {
1801     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1802         return;
1803     (vector->p_SHA224_TraceState)(cx);
1804 }
1805 
1806 unsigned int
SHA224_FlattenSize(SHA224Context * cx)1807 SHA224_FlattenSize(SHA224Context *cx)
1808 {
1809     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1810         return 0;
1811     return (vector->p_SHA224_FlattenSize)(cx);
1812 }
1813 
1814 SECStatus
SHA224_Flatten(SHA224Context * cx,unsigned char * space)1815 SHA224_Flatten(SHA224Context *cx, unsigned char *space)
1816 {
1817     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1818         return SECFailure;
1819     return (vector->p_SHA224_Flatten)(cx, space);
1820 }
1821 
1822 SHA224Context *
SHA224_Resurrect(unsigned char * space,void * arg)1823 SHA224_Resurrect(unsigned char *space, void *arg)
1824 {
1825     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1826         return NULL;
1827     return (vector->p_SHA224_Resurrect)(space, arg);
1828 }
1829 
1830 void
SHA224_Clone(SHA224Context * dest,SHA224Context * src)1831 SHA224_Clone(SHA224Context *dest, SHA224Context *src)
1832 {
1833     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1834         return;
1835     (vector->p_SHA224_Clone)(dest, src);
1836 }
1837 
1838 PRBool
BLAPI_SHVerifyFile(const char * name)1839 BLAPI_SHVerifyFile(const char *name)
1840 {
1841     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1842         return PR_FALSE;
1843     return vector->p_BLAPI_SHVerifyFile(name);
1844 }
1845 
1846 /* === new for DSA-2 === */
1847 SECStatus
PQG_ParamGenV2(unsigned int L,unsigned int N,unsigned int seedBytes,PQGParams ** pParams,PQGVerify ** pVfy)1848 PQG_ParamGenV2(unsigned int L, unsigned int N, unsigned int seedBytes,
1849                PQGParams **pParams, PQGVerify **pVfy)
1850 {
1851     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1852         return SECFailure;
1853     return (vector->p_PQG_ParamGenV2)(L, N, seedBytes, pParams, pVfy);
1854 }
1855 
1856 SECStatus
PRNGTEST_RunHealthTests(void)1857 PRNGTEST_RunHealthTests(void)
1858 {
1859     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1860         return SECFailure;
1861     return vector->p_PRNGTEST_RunHealthTests();
1862 }
1863 
1864 SECStatus
SSLv3_MAC_ConstantTime(unsigned char * result,unsigned int * resultLen,unsigned int maxResultLen,const SECHashObject * hashObj,const unsigned char * secret,unsigned int secretLen,const unsigned char * header,unsigned int headerLen,const unsigned char * body,unsigned int bodyLen,unsigned int bodyTotalLen)1865 SSLv3_MAC_ConstantTime(
1866     unsigned char *result,
1867     unsigned int *resultLen,
1868     unsigned int maxResultLen,
1869     const SECHashObject *hashObj,
1870     const unsigned char *secret,
1871     unsigned int secretLen,
1872     const unsigned char *header,
1873     unsigned int headerLen,
1874     const unsigned char *body,
1875     unsigned int bodyLen,
1876     unsigned int bodyTotalLen)
1877 {
1878     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1879         return SECFailure;
1880     return (vector->p_SSLv3_MAC_ConstantTime)(
1881         result, resultLen, maxResultLen,
1882         hashObj,
1883         secret, secretLen,
1884         header, headerLen,
1885         body, bodyLen, bodyTotalLen);
1886 }
1887 
1888 SECStatus
HMAC_ConstantTime(unsigned char * result,unsigned int * resultLen,unsigned int maxResultLen,const SECHashObject * hashObj,const unsigned char * secret,unsigned int secretLen,const unsigned char * header,unsigned int headerLen,const unsigned char * body,unsigned int bodyLen,unsigned int bodyTotalLen)1889 HMAC_ConstantTime(
1890     unsigned char *result,
1891     unsigned int *resultLen,
1892     unsigned int maxResultLen,
1893     const SECHashObject *hashObj,
1894     const unsigned char *secret,
1895     unsigned int secretLen,
1896     const unsigned char *header,
1897     unsigned int headerLen,
1898     const unsigned char *body,
1899     unsigned int bodyLen,
1900     unsigned int bodyTotalLen)
1901 {
1902     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1903         return SECFailure;
1904     return (vector->p_HMAC_ConstantTime)(
1905         result, resultLen, maxResultLen,
1906         hashObj,
1907         secret, secretLen,
1908         header, headerLen,
1909         body, bodyLen, bodyTotalLen);
1910 }
1911 
1912 SECStatus
RSA_SignRaw(RSAPrivateKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1913 RSA_SignRaw(RSAPrivateKey *key,
1914             unsigned char *output,
1915             unsigned int *outputLen,
1916             unsigned int maxOutputLen,
1917             const unsigned char *input,
1918             unsigned int inputLen)
1919 {
1920     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1921         return SECFailure;
1922     return (vector->p_RSA_SignRaw)(key, output, outputLen, maxOutputLen, input,
1923                                    inputLen);
1924 }
1925 
1926 SECStatus
RSA_CheckSignRaw(RSAPublicKey * key,const unsigned char * sig,unsigned int sigLen,const unsigned char * hash,unsigned int hashLen)1927 RSA_CheckSignRaw(RSAPublicKey *key,
1928                  const unsigned char *sig,
1929                  unsigned int sigLen,
1930                  const unsigned char *hash,
1931                  unsigned int hashLen)
1932 {
1933     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1934         return SECFailure;
1935     return (vector->p_RSA_CheckSignRaw)(key, sig, sigLen, hash, hashLen);
1936 }
1937 
1938 SECStatus
RSA_CheckSignRecoverRaw(RSAPublicKey * key,unsigned char * data,unsigned int * dataLen,unsigned int maxDataLen,const unsigned char * sig,unsigned int sigLen)1939 RSA_CheckSignRecoverRaw(RSAPublicKey *key,
1940                         unsigned char *data,
1941                         unsigned int *dataLen,
1942                         unsigned int maxDataLen,
1943                         const unsigned char *sig,
1944                         unsigned int sigLen)
1945 {
1946     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1947         return SECFailure;
1948     return (vector->p_RSA_CheckSignRecoverRaw)(key, data, dataLen, maxDataLen,
1949                                                sig, sigLen);
1950 }
1951 
1952 SECStatus
RSA_EncryptRaw(RSAPublicKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1953 RSA_EncryptRaw(RSAPublicKey *key,
1954                unsigned char *output,
1955                unsigned int *outputLen,
1956                unsigned int maxOutputLen,
1957                const unsigned char *input,
1958                unsigned int inputLen)
1959 {
1960     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1961         return SECFailure;
1962     return (vector->p_RSA_EncryptRaw)(key, output, outputLen, maxOutputLen,
1963                                       input, inputLen);
1964 }
1965 
1966 SECStatus
RSA_DecryptRaw(RSAPrivateKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1967 RSA_DecryptRaw(RSAPrivateKey *key,
1968                unsigned char *output,
1969                unsigned int *outputLen,
1970                unsigned int maxOutputLen,
1971                const unsigned char *input,
1972                unsigned int inputLen)
1973 {
1974     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1975         return SECFailure;
1976     return (vector->p_RSA_DecryptRaw)(key, output, outputLen, maxOutputLen,
1977                                       input, inputLen);
1978 }
1979 
1980 SECStatus
RSA_EncryptOAEP(RSAPublicKey * key,HASH_HashType hashAlg,HASH_HashType maskHashAlg,const unsigned char * label,unsigned int labelLen,const unsigned char * seed,unsigned int seedLen,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)1981 RSA_EncryptOAEP(RSAPublicKey *key,
1982                 HASH_HashType hashAlg,
1983                 HASH_HashType maskHashAlg,
1984                 const unsigned char *label,
1985                 unsigned int labelLen,
1986                 const unsigned char *seed,
1987                 unsigned int seedLen,
1988                 unsigned char *output,
1989                 unsigned int *outputLen,
1990                 unsigned int maxOutputLen,
1991                 const unsigned char *input,
1992                 unsigned int inputLen)
1993 {
1994     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
1995         return SECFailure;
1996     return (vector->p_RSA_EncryptOAEP)(key, hashAlg, maskHashAlg, label,
1997                                        labelLen, seed, seedLen, output,
1998                                        outputLen, maxOutputLen, input, inputLen);
1999 }
2000 
2001 SECStatus
RSA_DecryptOAEP(RSAPrivateKey * key,HASH_HashType hashAlg,HASH_HashType maskHashAlg,const unsigned char * label,unsigned int labelLen,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)2002 RSA_DecryptOAEP(RSAPrivateKey *key,
2003                 HASH_HashType hashAlg,
2004                 HASH_HashType maskHashAlg,
2005                 const unsigned char *label,
2006                 unsigned int labelLen,
2007                 unsigned char *output,
2008                 unsigned int *outputLen,
2009                 unsigned int maxOutputLen,
2010                 const unsigned char *input,
2011                 unsigned int inputLen)
2012 {
2013     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2014         return SECFailure;
2015     return (vector->p_RSA_DecryptOAEP)(key, hashAlg, maskHashAlg, label,
2016                                        labelLen, output, outputLen,
2017                                        maxOutputLen, input, inputLen);
2018 }
2019 
2020 SECStatus
RSA_EncryptBlock(RSAPublicKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)2021 RSA_EncryptBlock(RSAPublicKey *key,
2022                  unsigned char *output,
2023                  unsigned int *outputLen,
2024                  unsigned int maxOutputLen,
2025                  const unsigned char *input,
2026                  unsigned int inputLen)
2027 {
2028     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2029         return SECFailure;
2030     return (vector->p_RSA_EncryptBlock)(key, output, outputLen, maxOutputLen,
2031                                         input, inputLen);
2032 }
2033 
2034 SECStatus
RSA_DecryptBlock(RSAPrivateKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)2035 RSA_DecryptBlock(RSAPrivateKey *key,
2036                  unsigned char *output,
2037                  unsigned int *outputLen,
2038                  unsigned int maxOutputLen,
2039                  const unsigned char *input,
2040                  unsigned int inputLen)
2041 {
2042     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2043         return SECFailure;
2044     return (vector->p_RSA_DecryptBlock)(key, output, outputLen, maxOutputLen,
2045                                         input, inputLen);
2046 }
2047 
2048 SECStatus
RSA_SignPSS(RSAPrivateKey * key,HASH_HashType hashAlg,HASH_HashType maskHashAlg,const unsigned char * salt,unsigned int saltLen,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)2049 RSA_SignPSS(RSAPrivateKey *key,
2050             HASH_HashType hashAlg,
2051             HASH_HashType maskHashAlg,
2052             const unsigned char *salt,
2053             unsigned int saltLen,
2054             unsigned char *output,
2055             unsigned int *outputLen,
2056             unsigned int maxOutputLen,
2057             const unsigned char *input,
2058             unsigned int inputLen)
2059 {
2060     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2061         return SECFailure;
2062     return (vector->p_RSA_SignPSS)(key, hashAlg, maskHashAlg, salt, saltLen,
2063                                    output, outputLen, maxOutputLen, input,
2064                                    inputLen);
2065 }
2066 
2067 SECStatus
RSA_CheckSignPSS(RSAPublicKey * key,HASH_HashType hashAlg,HASH_HashType maskHashAlg,unsigned int saltLen,const unsigned char * sig,unsigned int sigLen,const unsigned char * hash,unsigned int hashLen)2068 RSA_CheckSignPSS(RSAPublicKey *key,
2069                  HASH_HashType hashAlg,
2070                  HASH_HashType maskHashAlg,
2071                  unsigned int saltLen,
2072                  const unsigned char *sig,
2073                  unsigned int sigLen,
2074                  const unsigned char *hash,
2075                  unsigned int hashLen)
2076 {
2077     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2078         return SECFailure;
2079     return (vector->p_RSA_CheckSignPSS)(key, hashAlg, maskHashAlg, saltLen,
2080                                         sig, sigLen, hash, hashLen);
2081 }
2082 
2083 SECStatus
RSA_Sign(RSAPrivateKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen)2084 RSA_Sign(RSAPrivateKey *key,
2085          unsigned char *output,
2086          unsigned int *outputLen,
2087          unsigned int maxOutputLen,
2088          const unsigned char *input,
2089          unsigned int inputLen)
2090 {
2091     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2092         return SECFailure;
2093     return (vector->p_RSA_Sign)(key, output, outputLen, maxOutputLen, input,
2094                                 inputLen);
2095 }
2096 
2097 SECStatus
RSA_CheckSign(RSAPublicKey * key,const unsigned char * sig,unsigned int sigLen,const unsigned char * data,unsigned int dataLen)2098 RSA_CheckSign(RSAPublicKey *key,
2099               const unsigned char *sig,
2100               unsigned int sigLen,
2101               const unsigned char *data,
2102               unsigned int dataLen)
2103 {
2104     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2105         return SECFailure;
2106     return (vector->p_RSA_CheckSign)(key, sig, sigLen, data, dataLen);
2107 }
2108 
2109 SECStatus
RSA_CheckSignRecover(RSAPublicKey * key,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * sig,unsigned int sigLen)2110 RSA_CheckSignRecover(RSAPublicKey *key,
2111                      unsigned char *output,
2112                      unsigned int *outputLen,
2113                      unsigned int maxOutputLen,
2114                      const unsigned char *sig,
2115                      unsigned int sigLen)
2116 {
2117     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2118         return SECFailure;
2119     return (vector->p_RSA_CheckSignRecover)(key, output, outputLen, maxOutputLen,
2120                                             sig, sigLen);
2121 }
2122 
2123 SECStatus
EC_FillParams(PLArenaPool * arena,const SECItem * encodedParams,ECParams * params)2124 EC_FillParams(PLArenaPool *arena,
2125               const SECItem *encodedParams,
2126               ECParams *params)
2127 {
2128     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2129         return SECFailure;
2130     return (vector->p_EC_FillParams)(arena, encodedParams, params);
2131 }
2132 
2133 SECStatus
EC_DecodeParams(const SECItem * encodedParams,ECParams ** ecparams)2134 EC_DecodeParams(const SECItem *encodedParams,
2135                 ECParams **ecparams)
2136 {
2137     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2138         return SECFailure;
2139     return (vector->p_EC_DecodeParams)(encodedParams, ecparams);
2140 }
2141 
2142 SECStatus
EC_CopyParams(PLArenaPool * arena,ECParams * dstParams,const ECParams * srcParams)2143 EC_CopyParams(PLArenaPool *arena, ECParams *dstParams,
2144               const ECParams *srcParams)
2145 {
2146     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2147         return SECFailure;
2148     return (vector->p_EC_CopyParams)(arena, dstParams, srcParams);
2149 }
2150 
2151 SECStatus
ChaCha20_Xor(unsigned char * output,const unsigned char * block,unsigned int len,const unsigned char * k,const unsigned char * nonce,PRUint32 ctr)2152 ChaCha20_Xor(unsigned char *output, const unsigned char *block, unsigned int len,
2153              const unsigned char *k, const unsigned char *nonce, PRUint32 ctr)
2154 {
2155     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2156         return SECFailure;
2157     }
2158     return (vector->p_ChaCha20_Xor)(output, block, len, k, nonce, ctr);
2159 }
2160 
2161 SECStatus
ChaCha20_InitContext(ChaCha20Context * ctx,const unsigned char * key,unsigned int keyLen,const unsigned char * nonce,unsigned int nonceLen,PRUint32 ctr)2162 ChaCha20_InitContext(ChaCha20Context *ctx, const unsigned char *key,
2163                      unsigned int keyLen,
2164                      const unsigned char *nonce,
2165                      unsigned int nonceLen,
2166                      PRUint32 ctr)
2167 {
2168     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2169         return SECFailure;
2170     return (vector->p_ChaCha20_InitContext)(ctx, key, keyLen, nonce, nonceLen, ctr);
2171 }
2172 
2173 ChaCha20Context *
ChaCha20_CreateContext(const unsigned char * key,unsigned int keyLen,const unsigned char * nonce,unsigned int nonceLen,PRUint32 ctr)2174 ChaCha20_CreateContext(const unsigned char *key, unsigned int keyLen,
2175                        const unsigned char *nonce, unsigned int nonceLen,
2176                        PRUint32 ctr)
2177 {
2178     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2179         return NULL;
2180     return (vector->p_ChaCha20_CreateContext)(key, keyLen, nonce, nonceLen, ctr);
2181 }
2182 
2183 void
ChaCha20_DestroyContext(ChaCha20Context * ctx,PRBool freeit)2184 ChaCha20_DestroyContext(ChaCha20Context *ctx, PRBool freeit)
2185 {
2186     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2187         return;
2188     (vector->p_ChaCha20_DestroyContext)(ctx, freeit);
2189 }
2190 
2191 SECStatus
ChaCha20Poly1305_InitContext(ChaCha20Poly1305Context * ctx,const unsigned char * key,unsigned int keyLen,unsigned int tagLen)2192 ChaCha20Poly1305_InitContext(ChaCha20Poly1305Context *ctx,
2193                              const unsigned char *key, unsigned int keyLen,
2194                              unsigned int tagLen)
2195 {
2196     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2197         return SECFailure;
2198     return (vector->p_ChaCha20Poly1305_InitContext)(ctx, key, keyLen, tagLen);
2199 }
2200 
2201 ChaCha20Poly1305Context *
ChaCha20Poly1305_CreateContext(const unsigned char * key,unsigned int keyLen,unsigned int tagLen)2202 ChaCha20Poly1305_CreateContext(const unsigned char *key, unsigned int keyLen,
2203                                unsigned int tagLen)
2204 {
2205     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2206         return NULL;
2207     return (vector->p_ChaCha20Poly1305_CreateContext)(key, keyLen, tagLen);
2208 }
2209 
2210 void
ChaCha20Poly1305_DestroyContext(ChaCha20Poly1305Context * ctx,PRBool freeit)2211 ChaCha20Poly1305_DestroyContext(ChaCha20Poly1305Context *ctx, PRBool freeit)
2212 {
2213     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2214         return;
2215     (vector->p_ChaCha20Poly1305_DestroyContext)(ctx, freeit);
2216 }
2217 
2218 SECStatus
ChaCha20Poly1305_Seal(const ChaCha20Poly1305Context * ctx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen,const unsigned char * nonce,unsigned int nonceLen,const unsigned char * ad,unsigned int adLen)2219 ChaCha20Poly1305_Seal(const ChaCha20Poly1305Context *ctx,
2220                       unsigned char *output, unsigned int *outputLen,
2221                       unsigned int maxOutputLen,
2222                       const unsigned char *input, unsigned int inputLen,
2223                       const unsigned char *nonce, unsigned int nonceLen,
2224                       const unsigned char *ad, unsigned int adLen)
2225 {
2226     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2227         return SECFailure;
2228     return (vector->p_ChaCha20Poly1305_Seal)(
2229         ctx, output, outputLen, maxOutputLen, input, inputLen,
2230         nonce, nonceLen, ad, adLen);
2231 }
2232 
2233 SECStatus
ChaCha20Poly1305_Open(const ChaCha20Poly1305Context * ctx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen,const unsigned char * nonce,unsigned int nonceLen,const unsigned char * ad,unsigned int adLen)2234 ChaCha20Poly1305_Open(const ChaCha20Poly1305Context *ctx,
2235                       unsigned char *output, unsigned int *outputLen,
2236                       unsigned int maxOutputLen,
2237                       const unsigned char *input, unsigned int inputLen,
2238                       const unsigned char *nonce, unsigned int nonceLen,
2239                       const unsigned char *ad, unsigned int adLen)
2240 {
2241     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2242         return SECFailure;
2243     return (vector->p_ChaCha20Poly1305_Open)(
2244         ctx, output, outputLen, maxOutputLen, input, inputLen,
2245         nonce, nonceLen, ad, adLen);
2246 }
2247 
2248 SECStatus
ChaCha20Poly1305_Encrypt(const ChaCha20Poly1305Context * ctx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen,const unsigned char * nonce,unsigned int nonceLen,const unsigned char * ad,unsigned int adLen,unsigned char * tagOut)2249 ChaCha20Poly1305_Encrypt(const ChaCha20Poly1305Context *ctx,
2250                          unsigned char *output, unsigned int *outputLen,
2251                          unsigned int maxOutputLen,
2252                          const unsigned char *input, unsigned int inputLen,
2253                          const unsigned char *nonce, unsigned int nonceLen,
2254                          const unsigned char *ad, unsigned int adLen,
2255                          unsigned char *tagOut)
2256 {
2257     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2258         return SECFailure;
2259     return (vector->p_ChaCha20Poly1305_Encrypt)(
2260         ctx, output, outputLen, maxOutputLen, input, inputLen,
2261         nonce, nonceLen, ad, adLen, tagOut);
2262 }
2263 
2264 SECStatus
ChaCha20Poly1305_Decrypt(const ChaCha20Poly1305Context * ctx,unsigned char * output,unsigned int * outputLen,unsigned int maxOutputLen,const unsigned char * input,unsigned int inputLen,const unsigned char * nonce,unsigned int nonceLen,const unsigned char * ad,unsigned int adLen,unsigned char * tagIn)2265 ChaCha20Poly1305_Decrypt(const ChaCha20Poly1305Context *ctx,
2266                          unsigned char *output, unsigned int *outputLen,
2267                          unsigned int maxOutputLen,
2268                          const unsigned char *input, unsigned int inputLen,
2269                          const unsigned char *nonce, unsigned int nonceLen,
2270                          const unsigned char *ad, unsigned int adLen,
2271                          unsigned char *tagIn)
2272 {
2273     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2274         return SECFailure;
2275     return (vector->p_ChaCha20Poly1305_Decrypt)(
2276         ctx, output, outputLen, maxOutputLen, input, inputLen,
2277         nonce, nonceLen, ad, adLen, tagIn);
2278 }
2279 
2280 int
EC_GetPointSize(const ECParams * params)2281 EC_GetPointSize(const ECParams *params)
2282 {
2283     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2284         return SECFailure;
2285     return (vector->p_EC_GetPointSize)(params);
2286 }
2287 
2288 SECStatus
BLAKE2B_Hash(unsigned char * dest,const char * src)2289 BLAKE2B_Hash(unsigned char *dest, const char *src)
2290 {
2291     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2292         return SECFailure;
2293     }
2294     return (vector->p_BLAKE2B_Hash)(dest, src);
2295 }
2296 
2297 SECStatus
BLAKE2B_HashBuf(unsigned char * output,const unsigned char * input,PRUint32 inlen)2298 BLAKE2B_HashBuf(unsigned char *output, const unsigned char *input, PRUint32 inlen)
2299 {
2300     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2301         return SECFailure;
2302     }
2303     return (vector->p_BLAKE2B_HashBuf)(output, input, inlen);
2304 }
2305 
2306 SECStatus
BLAKE2B_MAC_HashBuf(unsigned char * output,const unsigned char * input,unsigned int inlen,const unsigned char * key,unsigned int keylen)2307 BLAKE2B_MAC_HashBuf(unsigned char *output, const unsigned char *input,
2308                     unsigned int inlen, const unsigned char *key,
2309                     unsigned int keylen)
2310 {
2311     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2312         return SECFailure;
2313     }
2314     return (vector->p_BLAKE2B_MAC_HashBuf)(output, input, inlen, key, keylen);
2315 }
2316 
2317 BLAKE2BContext *
BLAKE2B_NewContext(void)2318 BLAKE2B_NewContext(void)
2319 {
2320     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2321         return NULL;
2322     }
2323     return (vector->p_BLAKE2B_NewContext)();
2324 }
2325 
2326 void
BLAKE2B_DestroyContext(BLAKE2BContext * ctx,PRBool freeit)2327 BLAKE2B_DestroyContext(BLAKE2BContext *ctx, PRBool freeit)
2328 {
2329     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2330         return;
2331     }
2332     (vector->p_BLAKE2B_DestroyContext)(ctx, freeit);
2333 }
2334 
2335 SECStatus
BLAKE2B_Begin(BLAKE2BContext * ctx)2336 BLAKE2B_Begin(BLAKE2BContext *ctx)
2337 {
2338     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2339         return SECFailure;
2340     }
2341     return (vector->p_BLAKE2B_Begin)(ctx);
2342 }
2343 
2344 SECStatus
BLAKE2B_MAC_Begin(BLAKE2BContext * ctx,const PRUint8 * key,const size_t keylen)2345 BLAKE2B_MAC_Begin(BLAKE2BContext *ctx, const PRUint8 *key, const size_t keylen)
2346 {
2347     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2348         return SECFailure;
2349     }
2350     return (vector->p_BLAKE2B_MAC_Begin)(ctx, key, keylen);
2351 }
2352 
2353 SECStatus
BLAKE2B_Update(BLAKE2BContext * ctx,const unsigned char * in,unsigned int inlen)2354 BLAKE2B_Update(BLAKE2BContext *ctx, const unsigned char *in, unsigned int inlen)
2355 {
2356     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2357         return SECFailure;
2358     }
2359     return (vector->p_BLAKE2B_Update)(ctx, in, inlen);
2360 }
2361 
2362 SECStatus
BLAKE2B_End(BLAKE2BContext * ctx,unsigned char * out,unsigned int * digestLen,size_t maxDigestLen)2363 BLAKE2B_End(BLAKE2BContext *ctx, unsigned char *out,
2364             unsigned int *digestLen, size_t maxDigestLen)
2365 {
2366     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2367         return SECFailure;
2368     }
2369     return (vector->p_BLAKE2B_End)(ctx, out, digestLen, maxDigestLen);
2370 }
2371 
2372 unsigned int
BLAKE2B_FlattenSize(BLAKE2BContext * ctx)2373 BLAKE2B_FlattenSize(BLAKE2BContext *ctx)
2374 {
2375     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2376         return 0;
2377     }
2378     return (vector->p_BLAKE2B_FlattenSize)(ctx);
2379 }
2380 
2381 SECStatus
BLAKE2B_Flatten(BLAKE2BContext * ctx,unsigned char * space)2382 BLAKE2B_Flatten(BLAKE2BContext *ctx, unsigned char *space)
2383 {
2384     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2385         return SECFailure;
2386     }
2387     return (vector->p_BLAKE2B_Flatten)(ctx, space);
2388 }
2389 
2390 BLAKE2BContext *
BLAKE2B_Resurrect(unsigned char * space,void * arg)2391 BLAKE2B_Resurrect(unsigned char *space, void *arg)
2392 {
2393     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) {
2394         return NULL;
2395     }
2396     return (vector->p_BLAKE2B_Resurrect)(space, arg);
2397 }
2398 
2399 /* == New for CMAC == */
2400 SECStatus
CMAC_Init(CMACContext * ctx,CMACCipher type,const unsigned char * key,unsigned int key_len)2401 CMAC_Init(CMACContext *ctx, CMACCipher type, const unsigned char *key,
2402           unsigned int key_len)
2403 {
2404     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2405         return SECFailure;
2406     return (vector->p_CMAC_Init)(ctx, type, key, key_len);
2407 }
2408 
2409 CMACContext *
CMAC_Create(CMACCipher type,const unsigned char * key,unsigned int key_len)2410 CMAC_Create(CMACCipher type, const unsigned char *key, unsigned int key_len)
2411 {
2412     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2413         return NULL;
2414     return (vector->p_CMAC_Create)(type, key, key_len);
2415 }
2416 
2417 SECStatus
CMAC_Begin(CMACContext * ctx)2418 CMAC_Begin(CMACContext *ctx)
2419 {
2420     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2421         return SECFailure;
2422     return (vector->p_CMAC_Begin)(ctx);
2423 }
2424 
2425 SECStatus
CMAC_Update(CMACContext * ctx,const unsigned char * data,unsigned int data_len)2426 CMAC_Update(CMACContext *ctx, const unsigned char *data, unsigned int data_len)
2427 {
2428     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2429         return SECFailure;
2430     return (vector->p_CMAC_Update)(ctx, data, data_len);
2431 }
2432 
2433 SECStatus
CMAC_Finish(CMACContext * ctx,unsigned char * result,unsigned int * result_len,unsigned int max_result_len)2434 CMAC_Finish(CMACContext *ctx, unsigned char *result, unsigned int *result_len,
2435             unsigned int max_result_len)
2436 {
2437     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2438         return SECFailure;
2439     return (vector->p_CMAC_Finish)(ctx, result, result_len, max_result_len);
2440 }
2441 
2442 void
CMAC_Destroy(CMACContext * ctx,PRBool free_it)2443 CMAC_Destroy(CMACContext *ctx, PRBool free_it)
2444 {
2445     if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
2446         return;
2447     (vector->p_CMAC_Destroy)(ctx, free_it);
2448 }
2449