1 /*
2 * ldvector.c - 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 #ifdef FREEBL_NO_DEPEND
9 #include "stubs.h"
10 extern int FREEBL_InitStubs(void);
11 #endif
12
13 #include "loader.h"
14 #include "cmac.h"
15 #include "alghmac.h"
16 #include "hmacct.h"
17 #include "blapii.h"
18 #include "secerr.h"
19
20 SECStatus
FREEBL_Deprecated(void)21 FREEBL_Deprecated(void)
22 {
23
24 PORT_SetError(SEC_ERROR_UNSUPPORTED_KEYALG);
25 return SECFailure;
26 }
27
28 static const struct FREEBLVectorStr vector =
29 {
30
31 sizeof vector,
32 FREEBL_VERSION,
33
34 RSA_NewKey,
35 RSA_PublicKeyOp,
36 RSA_PrivateKeyOp,
37 DSA_NewKey,
38 DSA_SignDigest,
39 DSA_VerifyDigest,
40 DSA_NewKeyFromSeed,
41 DSA_SignDigestWithSeed,
42 DH_GenParam,
43 DH_NewKey,
44 DH_Derive,
45 KEA_Derive,
46 KEA_Verify,
47 RC4_CreateContext,
48 RC4_DestroyContext,
49 RC4_Encrypt,
50 RC4_Decrypt,
51 #ifndef NSS_DISABLE_DEPRECATED_RC2
52 RC2_CreateContext,
53 RC2_DestroyContext,
54 RC2_Encrypt,
55 RC2_Decrypt,
56 #else
57 (F_RC2_CreateContext)FREEBL_Deprecated,
58 (F_RC2_DestroyContext)FREEBL_Deprecated,
59 (F_RC2_Encrypt)FREEBL_Deprecated,
60 (F_RC2_Decrypt)FREEBL_Deprecated,
61 #endif
62 RC5_CreateContext,
63 RC5_DestroyContext,
64 RC5_Encrypt,
65 RC5_Decrypt,
66 DES_CreateContext,
67 DES_DestroyContext,
68 DES_Encrypt,
69 DES_Decrypt,
70 AES_CreateContext,
71 AES_DestroyContext,
72 AES_Encrypt,
73 AES_Decrypt,
74 MD5_Hash,
75 MD5_HashBuf,
76 MD5_NewContext,
77 MD5_DestroyContext,
78 MD5_Begin,
79 MD5_Update,
80 MD5_End,
81 MD5_FlattenSize,
82 MD5_Flatten,
83 MD5_Resurrect,
84 MD5_TraceState,
85 MD2_Hash,
86 MD2_NewContext,
87 MD2_DestroyContext,
88 MD2_Begin,
89 MD2_Update,
90 MD2_End,
91 MD2_FlattenSize,
92 MD2_Flatten,
93 MD2_Resurrect,
94 SHA1_Hash,
95 SHA1_HashBuf,
96 SHA1_NewContext,
97 SHA1_DestroyContext,
98 SHA1_Begin,
99 SHA1_Update,
100 SHA1_End,
101 SHA1_TraceState,
102 SHA1_FlattenSize,
103 SHA1_Flatten,
104 SHA1_Resurrect,
105 RNG_RNGInit,
106 RNG_RandomUpdate,
107 RNG_GenerateGlobalRandomBytes,
108 RNG_RNGShutdown,
109 PQG_ParamGen,
110 PQG_ParamGenSeedLen,
111 PQG_VerifyParams,
112
113 /* End of Version 3.001. */
114
115 RSA_PrivateKeyOpDoubleChecked,
116 RSA_PrivateKeyCheck,
117 BL_Cleanup,
118
119 /* End of Version 3.002. */
120
121 SHA256_NewContext,
122 SHA256_DestroyContext,
123 SHA256_Begin,
124 SHA256_Update,
125 SHA256_End,
126 SHA256_HashBuf,
127 SHA256_Hash,
128 SHA256_TraceState,
129 SHA256_FlattenSize,
130 SHA256_Flatten,
131 SHA256_Resurrect,
132
133 SHA512_NewContext,
134 SHA512_DestroyContext,
135 SHA512_Begin,
136 SHA512_Update,
137 SHA512_End,
138 SHA512_HashBuf,
139 SHA512_Hash,
140 SHA512_TraceState,
141 SHA512_FlattenSize,
142 SHA512_Flatten,
143 SHA512_Resurrect,
144
145 SHA384_NewContext,
146 SHA384_DestroyContext,
147 SHA384_Begin,
148 SHA384_Update,
149 SHA384_End,
150 SHA384_HashBuf,
151 SHA384_Hash,
152 SHA384_TraceState,
153 SHA384_FlattenSize,
154 SHA384_Flatten,
155 SHA384_Resurrect,
156
157 /* End of Version 3.003. */
158
159 AESKeyWrap_CreateContext,
160 AESKeyWrap_DestroyContext,
161 AESKeyWrap_Encrypt,
162 AESKeyWrap_Decrypt,
163
164 /* End of Version 3.004. */
165
166 BLAPI_SHVerify,
167 BLAPI_VerifySelf,
168
169 /* End of Version 3.005. */
170
171 EC_NewKey,
172 EC_NewKeyFromSeed,
173 EC_ValidatePublicKey,
174 ECDH_Derive,
175 ECDSA_SignDigest,
176 ECDSA_VerifyDigest,
177 ECDSA_SignDigestWithSeed,
178
179 /* End of Version 3.006. */
180 /* End of Version 3.007. */
181
182 AES_InitContext,
183 AESKeyWrap_InitContext,
184 DES_InitContext,
185 #ifndef NSS_DISABLE_DEPRECATED_RC2
186 RC2_InitContext,
187 #else
188 (F_RC2_InitContext)FREEBL_Deprecated,
189 #endif
190 RC4_InitContext,
191
192 AES_AllocateContext,
193 AESKeyWrap_AllocateContext,
194 DES_AllocateContext,
195 #ifndef NSS_DISABLE_DEPRECATED_RC2
196 RC2_AllocateContext,
197 #else
198 (F_RC2_AllocateContext)FREEBL_Deprecated,
199 #endif
200 RC4_AllocateContext,
201
202 MD2_Clone,
203 MD5_Clone,
204 SHA1_Clone,
205 SHA256_Clone,
206 SHA384_Clone,
207 SHA512_Clone,
208
209 TLS_PRF,
210 HASH_GetRawHashObject,
211
212 HMAC_Create,
213 HMAC_Init,
214 HMAC_Begin,
215 HMAC_Update,
216 HMAC_Clone,
217 HMAC_Finish,
218 HMAC_Destroy,
219
220 RNG_SystemInfoForRNG,
221
222 /* End of Version 3.008. */
223
224 FIPS186Change_GenerateX,
225 FIPS186Change_ReduceModQForDSA,
226
227 /* End of Version 3.009. */
228 Camellia_InitContext,
229 Camellia_AllocateContext,
230 Camellia_CreateContext,
231 Camellia_DestroyContext,
232 Camellia_Encrypt,
233 Camellia_Decrypt,
234
235 PQG_DestroyParams,
236 PQG_DestroyVerify,
237
238 /* End of Version 3.010. */
239
240 #ifndef NSS_DISABLE_DEPRECATED_SEED
241 SEED_InitContext,
242 SEED_AllocateContext,
243 SEED_CreateContext,
244 SEED_DestroyContext,
245 SEED_Encrypt,
246 SEED_Decrypt,
247 #else
248 (F_SEED_InitContext)FREEBL_Deprecated,
249 (F_SEED_AllocateContext)FREEBL_Deprecated,
250 (F_SEED_CreateContext)FREEBL_Deprecated,
251 (F_SEED_DestroyContext)FREEBL_Deprecated,
252 (F_SEED_Encrypt)FREEBL_Deprecated,
253 (F_SEED_Decrypt)FREEBL_Deprecated,
254 #endif /* NSS_DISABLE_DEPRECATED_SEED */
255
256 BL_Init,
257 BL_SetForkState,
258
259 PRNGTEST_Instantiate,
260 PRNGTEST_Reseed,
261 PRNGTEST_Generate,
262
263 PRNGTEST_Uninstantiate,
264
265 /* End of Version 3.011. */
266
267 RSA_PopulatePrivateKey,
268
269 DSA_NewRandom,
270
271 JPAKE_Sign,
272 JPAKE_Verify,
273 JPAKE_Round2,
274 JPAKE_Final,
275
276 /* End of Version 3.012 */
277
278 TLS_P_hash,
279 SHA224_NewContext,
280 SHA224_DestroyContext,
281 SHA224_Begin,
282 SHA224_Update,
283 SHA224_End,
284 SHA224_HashBuf,
285 SHA224_Hash,
286 SHA224_TraceState,
287 SHA224_FlattenSize,
288 SHA224_Flatten,
289 SHA224_Resurrect,
290 SHA224_Clone,
291 BLAPI_SHVerifyFile,
292
293 /* End of Version 3.013 */
294
295 PQG_ParamGenV2,
296 PRNGTEST_RunHealthTests,
297
298 /* End of Version 3.014 */
299
300 HMAC_ConstantTime,
301 SSLv3_MAC_ConstantTime,
302
303 /* End of Version 3.015 */
304
305 RSA_SignRaw,
306 RSA_CheckSignRaw,
307 RSA_CheckSignRecoverRaw,
308 RSA_EncryptRaw,
309 RSA_DecryptRaw,
310 RSA_EncryptOAEP,
311 RSA_DecryptOAEP,
312 RSA_EncryptBlock,
313 RSA_DecryptBlock,
314 RSA_SignPSS,
315 RSA_CheckSignPSS,
316 RSA_Sign,
317 RSA_CheckSign,
318 RSA_CheckSignRecover,
319
320 /* End of Version 3.016 */
321
322 EC_FillParams,
323 EC_DecodeParams,
324 EC_CopyParams,
325
326 /* End of Version 3.017 */
327
328 ChaCha20Poly1305_InitContext,
329 ChaCha20Poly1305_CreateContext,
330 ChaCha20Poly1305_DestroyContext,
331 ChaCha20Poly1305_Seal,
332 ChaCha20Poly1305_Open,
333
334 /* End of Version 3.018 */
335
336 EC_GetPointSize,
337
338 /* End of Version 3.019 */
339
340 BLAKE2B_Hash,
341 BLAKE2B_HashBuf,
342 BLAKE2B_MAC_HashBuf,
343 BLAKE2B_NewContext,
344 BLAKE2B_DestroyContext,
345 BLAKE2B_Begin,
346 BLAKE2B_MAC_Begin,
347 BLAKE2B_Update,
348 BLAKE2B_End,
349 BLAKE2B_FlattenSize,
350 BLAKE2B_Flatten,
351 BLAKE2B_Resurrect,
352
353 /* End of Version 3.020 */
354
355 ChaCha20_Xor,
356
357 /* End of version 3.021 */
358
359 CMAC_Init,
360 CMAC_Create,
361 CMAC_Begin,
362 CMAC_Update,
363 CMAC_Finish,
364 CMAC_Destroy,
365
366 /* End of version 3.022 */
367 ChaCha20Poly1305_Encrypt,
368 ChaCha20Poly1305_Decrypt,
369 AES_AEAD,
370 AESKeyWrap_EncryptKWP,
371 AESKeyWrap_DecryptKWP,
372
373 /* End of version 3.023 */
374 KEA_PrimeCheck,
375
376 /* End of version 3.024 */
377 ChaCha20_InitContext,
378 ChaCha20_CreateContext,
379 ChaCha20_DestroyContext
380
381 /* End of version 3.025 */
382 };
383
384 const FREEBLVector*
FREEBL_GetVector(void)385 FREEBL_GetVector(void)
386 {
387 #ifdef FREEBL_NO_DEPEND
388 SECStatus rv;
389 #endif
390
391 #define NSS_VERSION_VARIABLE __nss_freebl_version
392 #include "verref.h"
393
394 #ifdef FREEBL_NO_DEPEND
395 /* this entry point is only valid if nspr and nss-util has been loaded */
396 rv = FREEBL_InitStubs();
397 if (rv != SECSuccess) {
398 return NULL;
399 }
400 #endif
401
402 #ifndef NSS_FIPS_DISABLED
403 /* In FIPS mode make sure the Full self tests have been run before
404 * continuing. */
405 BL_POSTRan(PR_FALSE);
406 #endif
407
408 return &vector;
409 }
410
411 #ifdef FREEBL_LOWHASH
412 static const struct NSSLOWVectorStr nssvector =
413 {
414 sizeof nssvector,
415 NSSLOW_VERSION,
416 FREEBL_GetVector,
417 NSSLOW_Init,
418 NSSLOW_Shutdown,
419 NSSLOW_Reset,
420 NSSLOWHASH_NewContext,
421 NSSLOWHASH_Begin,
422 NSSLOWHASH_Update,
423 NSSLOWHASH_End,
424 NSSLOWHASH_Destroy,
425 NSSLOWHASH_Length
426 };
427
428 const NSSLOWVector*
NSSLOW_GetVector(void)429 NSSLOW_GetVector(void)
430 {
431 /* POST check and stub init happens in FREEBL_GetVector() and
432 * NSSLOW_Init() respectively */
433 return &nssvector;
434 }
435 #endif
436