~ubuntu-branches/ubuntu/lucid/seamonkey/lucid-security

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/freebl/loader.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-07-29 21:29:02 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080729212902-spm9kpvchp9udwbw
Tags: 1.1.11+nobinonly-0ubuntu1
* New security upstream release: 1.1.11 (LP: #218534)
  Fixes USN-602-1, USN-619-1, USN-623-1 and USN-629-1
* Refresh diverged patch:
  - update debian/patches/80_security_build.patch
* Fix FTBFS with missing -lfontconfig
  - add debian/patches/11_fix_ftbfs_with_fontconfig.patch
  - update debian/patches/series
* Build with default gcc (hardy: 4.2, intrepid: 4.3)
  - update debian/rules
  - update debian/control

Show diffs side-by-side

added added

removed removed

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