xref: /lighttpd1.4/src/sys-crypto-md.h (revision d5e899e2)
1 /* sys-crypto-md.h - message digest (MD) wrapper
2  *
3  * message digest (MD) algorithms are not necessarily cryptographically secure
4  * (often provided by crypto libraries, hence this file named sys-crypto-md.h)
5  *
6  * Copyright(c) 2020 Glenn Strauss gstrauss()gluelogic.com  All rights reserved
7  * License: BSD 3-clause (same as lighttpd)
8  */
9 #ifndef LI_SYS_CRYPTO_MD_H
10 #define LI_SYS_CRYPTO_MD_H
11 #include "first.h"
12 
13 #include "sys-crypto.h" /* USE_LIB_CRYPTO */
14 #ifdef USE_LIB_CRYPTO
15 
16 #if defined(USE_NETTLE_CRYPTO)
17 
18 #include <nettle/md4.h>
19 #include <nettle/md5.h>
20 #include <nettle/sha.h>
21 
22 #define USE_LIB_CRYPTO_MD4
23 typedef struct md4_ctx MD4_CTX;
24 static inline int
25 MD4_Init(MD4_CTX *ctx)
26 {
27     nettle_md4_init(ctx);
28     return 1;
29 }
30 static inline int
31 MD4_Final(unsigned char *digest, MD4_CTX *ctx)
32 {
33     nettle_md4_digest(ctx, MD4_DIGEST_SIZE, digest);
34     return 1;
35 }
36 static inline int
37 MD4_Update(MD4_CTX *ctx, const void *data, size_t length)
38 {
39     nettle_md4_update(ctx, length, data);
40     return 1;
41 }
42 
43 #define USE_LIB_CRYPTO_MD5
44 typedef struct md5_ctx MD5_CTX;
45 static inline int
46 MD5_Init(MD5_CTX *ctx)
47 {
48     nettle_md5_init(ctx);
49     return 1;
50 }
51 static inline int
52 MD5_Final(unsigned char *digest, MD5_CTX *ctx)
53 {
54     nettle_md5_digest(ctx, MD5_DIGEST_SIZE, digest);
55     return 1;
56 }
57 static inline int
58 MD5_Update(MD5_CTX *ctx, const void *data, size_t length)
59 {
60     nettle_md5_update(ctx, length, data);
61     return 1;
62 }
63 
64 #define USE_LIB_CRYPTO_SHA1
65 typedef struct sha1_ctx SHA_CTX;
66 static inline int
67 SHA1_Init(SHA_CTX *ctx)
68 {
69     nettle_sha1_init(ctx);
70     return 1;
71 }
72 static inline int
73 SHA1_Final(unsigned char *digest, SHA_CTX *ctx)
74 {
75     nettle_sha1_digest(ctx, SHA1_DIGEST_SIZE, digest);
76     return 1;
77 }
78 static inline int
79 SHA1_Update(SHA_CTX *ctx, const void *data, size_t length)
80 {
81     nettle_sha1_update(ctx, length, data);
82     return 1;
83 }
84 
85 #define USE_LIB_CRYPTO_SHA256
86 typedef struct sha256_ctx SHA256_CTX;
87 static inline int
88 SHA256_Init(SHA256_CTX *ctx)
89 {
90     nettle_sha256_init(ctx);
91     return 1;
92 }
93 static inline int
94 SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
95 {
96     nettle_sha256_digest(ctx, SHA256_DIGEST_SIZE, digest);
97     return 1;
98 }
99 static inline int
100 SHA256_Update(SHA256_CTX *ctx, const void *data, size_t length)
101 {
102     nettle_sha256_update(ctx, length, data);
103     return 1;
104 }
105 
106 #define USE_LIB_CRYPTO_SHA512_256
107 #ifndef SHA512_256_DIGEST_LENGTH
108 #define SHA512_256_DIGEST_LENGTH 32
109 #endif
110 typedef struct sha512_256_ctx SHA512_CTX;    /*(yes, SHA512_CTX)*/
111 static inline int
112 SHA512_256_Init(SHA512_CTX *ctx)
113 {
114     nettle_sha512_256_init(ctx);
115     return 1;
116 }
117 static inline int
118 SHA512_256_Final(unsigned char *digest, SHA512_CTX *ctx)
119 {
120     nettle_sha512_256_digest(ctx, SHA256_DIGEST_SIZE, digest);
121     return 1;
122 }
123 static inline int
124 SHA512_256_Update(SHA512_CTX *ctx, const void *data, size_t length)
125 {
126     nettle_sha512_update(ctx, length, data); /*(yes, nettle_sha512_update())*/
127     return 1;
128 }
129 
130 #elif defined(USE_MBEDTLS_CRYPTO)
131 
132 #include <mbedtls/config.h>
133 
134 #ifdef MBEDTLS_MD4_C
135 #define USE_LIB_CRYPTO_MD4
136 #include <mbedtls/md4.h>
137 typedef struct mbedtls_md4_context MD4_CTX;
138 static inline int
139 MD4_Init(MD4_CTX *ctx)
140 {
141     mbedtls_md4_init(ctx);
142     return (0 == mbedtls_md4_starts_ret(ctx));
143 }
144 static inline int
145 MD4_Final(unsigned char *digest, MD4_CTX *ctx)
146 {
147     int rc = mbedtls_md4_finish_ret(ctx, digest);
148     mbedtls_md4_free(ctx);
149     return (0 == rc);
150 }
151 static inline int
152 MD4_Update(MD4_CTX *ctx, const void *data, size_t length)
153 {
154     return (0 == mbedtls_md4_update_ret(ctx, data, length));
155 }
156 #endif
157 
158 #ifdef MBEDTLS_MD5_C
159 #define USE_LIB_CRYPTO_MD5
160 #include <mbedtls/md5.h>
161 typedef struct mbedtls_md5_context MD5_CTX;
162 static inline int
163 MD5_Init(MD5_CTX *ctx)
164 {
165     mbedtls_md5_init(ctx);
166     return (0 == mbedtls_md5_starts_ret(ctx));
167 }
168 static inline int
169 MD5_Final(unsigned char *digest, MD5_CTX *ctx)
170 {
171     int rc = mbedtls_md5_finish_ret(ctx, digest);
172     mbedtls_md5_free(ctx);
173     return (0 == rc);
174 }
175 static inline int
176 MD5_Update(MD5_CTX *ctx, const void *data, size_t length)
177 {
178     return (0 == mbedtls_md5_update_ret(ctx, data, length));
179 }
180 #endif
181 
182 #ifdef MBEDTLS_SHA1_C
183 #define USE_LIB_CRYPTO_SHA1
184 #include <mbedtls/sha1.h>
185 typedef struct mbedtls_sha1_context SHA_CTX;
186 static inline int
187 SHA1_Init(SHA_CTX *ctx)
188 {
189     mbedtls_sha1_init(ctx);
190     return (0 == mbedtls_sha1_starts_ret(ctx));
191 }
192 static inline int
193 SHA1_Final(unsigned char *digest, SHA_CTX *ctx)
194 {
195     int rc = mbedtls_sha1_finish_ret(ctx, digest);
196     mbedtls_sha1_free(ctx);
197     return (0 == rc);
198 }
199 static inline int
200 SHA1_Update(SHA_CTX *ctx, const void *data, size_t length)
201 {
202     return (0 == mbedtls_sha1_update_ret(ctx, data, length));
203 }
204 #endif
205 
206 #ifdef MBEDTLS_SHA256_C
207 #define USE_LIB_CRYPTO_SHA256
208 #include <mbedtls/sha256.h>
209 typedef struct mbedtls_sha256_context SHA256_CTX;
210 static inline int
211 SHA256_Init(SHA256_CTX *ctx)
212 {
213     mbedtls_sha256_init(ctx);
214     return (0 == mbedtls_sha256_starts_ret(ctx, 0));
215 }
216 static inline int
217 SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
218 {
219     int rc = mbedtls_sha256_finish_ret(ctx, digest);
220     mbedtls_sha256_free(ctx);
221     return (0 == rc);
222 }
223 static inline int
224 SHA256_Update(SHA256_CTX *ctx, const void *data, size_t length)
225 {
226     return (0 == mbedtls_sha256_update_ret(ctx, data, length));
227 }
228 #endif
229 
230 #elif defined(USE_WOLFSSL_CRYPTO)
231 
232 /* WolfSSL compatibility API for OpenSSL unnecessarily bounces through an extra
233  * layer of indirection.  However, to avoid conflicting typedefs when includers
234  * also include headers from the WolfSSL compatibility API for OpenSSL, we
235  * include those headers here, as well, and use the compatibility API typedefs.
236  * (undef of OPENSSL_EXTRA and NO_OLD_WC_NAMES not sufficient, and not friendly
237  *  to do in a header when others might rely on them) */
238 
239 /* workaround fragile code in wolfssl/wolfcrypto/types.h */
240 #if !defined(SIZEOF_LONG) || !defined(SIZEOF_LONG_LONG)
241 #undef SIZEOF_LONG
242 #undef SIZEOF_LONG_LONG
243 #endif
244 
245 #ifndef NO_MD4
246 #include <wolfssl/wolfcrypt/md4.h>
247 #include <wolfssl/openssl/md4.h>
248 #undef MD4_Init
249 #undef MD4_Final
250 #undef MD4_Update
251 #define USE_LIB_CRYPTO_MD4
252 /*typedef Md4 MD4_CTX;*/
253 static inline int
254 MD4_Init(MD4_CTX *ctx)
255 {
256     wc_InitMd4((Md4 *)ctx);
257     return 1;
258 }
259 static inline int
260 MD4_Final(unsigned char *digest, MD4_CTX *ctx)
261 {
262     wc_Md4Final((Md4 *)ctx, digest);
263     return 1;
264 }
265 static inline int
266 MD4_Update(MD4_CTX *ctx, const void *data, size_t length)
267 {
268     wc_Md4Update((Md4 *)ctx, data, length);
269     return 1;
270 }
271 #endif
272 
273 #ifndef NO_MD5
274 #include <wolfssl/wolfcrypt/md5.h>
275 #include <wolfssl/openssl/md5.h>
276 #undef MD5_Init
277 #undef MD5_Final
278 #undef MD5_Update
279 #define USE_LIB_CRYPTO_MD5
280 /*typedef wc_Md5 MD5_CTX;*/
281 static inline int
282 MD5_Init(MD5_CTX *ctx)
283 {
284     return (0 == wc_InitMd5((wc_Md5 *)ctx));
285 }
286 static inline int
287 MD5_Final(unsigned char *digest, MD5_CTX *ctx)
288 {
289     return (0 == wc_Md5Final((wc_Md5 *)ctx, digest));
290 }
291 static inline int
292 MD5_Update(MD5_CTX *ctx, const void *data, size_t length)
293 {
294     wc_Md5Update((wc_Md5 *)ctx, data, length);
295     return 1;
296 }
297 #endif
298 
299 #ifndef NO_SHA
300 #include <wolfssl/wolfcrypt/sha.h>
301 #include <wolfssl/openssl/sha.h>
302 #undef SHA1_Init
303 #undef SHA1_Final
304 #undef SHA1_Update
305 #define USE_LIB_CRYPTO_SHA1
306 /*typedef wc_Sha SHA_CTX;*/
307 static inline int
308 SHA1_Init(SHA_CTX *ctx)
309 {
310     return (0 == wc_InitSha((wc_Sha *)ctx));
311 }
312 static inline int
313 SHA1_Final(unsigned char *digest, SHA_CTX *ctx)
314 {
315     return (0 == wc_ShaFinal((wc_Sha *)ctx, digest));
316 }
317 static inline int
318 SHA1_Update(SHA_CTX *ctx, const void *data, size_t length)
319 {
320     wc_ShaUpdate((wc_Sha *)ctx, data, length);
321     return 1;
322 }
323 #endif
324 
325 #ifndef NO_SHA256
326 #include <wolfssl/wolfcrypt/sha256.h>
327 #include <wolfssl/openssl/sha.h>
328 #undef SHA256_Init
329 #undef SHA256_Final
330 #undef SHA256_Update
331 #define USE_LIB_CRYPTO_SHA256
332 /*typedef wc_Sha256 SHA256_CTX;*/
333 static inline int
334 SHA256_Init(SHA256_CTX *ctx)
335 {
336     return (0 == wc_InitSha256((wc_Sha256 *)ctx));
337 }
338 static inline int
339 SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
340 {
341     return (0 == wc_Sha256Final((wc_Sha256 *)ctx, digest));
342 }
343 static inline int
344 SHA256_Update(SHA256_CTX *ctx, const void *data, size_t length)
345 {
346     wc_Sha256Update((wc_Sha256 *)ctx, data, length);
347     return 1;
348 }
349 #endif
350 
351 #elif defined(USE_OPENSSL_CRYPTO)
352 
353 #include <openssl/md4.h>
354 #include <openssl/md5.h>
355 #include <openssl/sha.h>
356 #ifndef OPENSSL_NO_MD4
357 #define USE_LIB_CRYPTO_MD4
358 #endif
359 #ifndef OPENSSL_NO_MD5
360 #define USE_LIB_CRYPTO_MD5
361 #endif
362 #define USE_LIB_CRYPTO_SHA1
363 #define USE_LIB_CRYPTO_SHA256
364 #ifdef SHA512_256_DIGEST_LENGTH
365 #define USE_LIB_CRYPTO_SHA512_256
366 #endif
367 
368 #include <openssl/opensslv.h>
369 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
370 #include <openssl/evp.h>
371 
372 #ifdef USE_LIB_CRYPTO_MD4
373 #define MD4_CTX EVP_MD4_CTX
374 #define MD4_Init EVP_MD4_Init
375 #define MD4_Final EVP_MD4_Final
376 #define MD4_Update EVP_MD4_Update
377 typedef EVP_MD_CTX * MD4_CTX;
378 static inline int
379 EVP_MD4_Init(EVP_MD4_CTX *ctx)
380 {
381     return ((*ctx = EVP_MD_CTX_new()) != NULL
382             && 1 == EVP_DigestInit_ex(*ctx, EVP_md4(), NULL));
383 }
384 static inline int
385 EVP_MD4_Final(unsigned char *digest, EVP_MD4_CTX *ctx)
386 {
387     /* MD4_DIGEST_LENGTH; EVP_MD_size(EVP_md4()) */
388     int rc = EVP_DigestFinal_ex(*ctx, digest, NULL);
389     EVP_MD_CTX_free(*ctx);
390     return (1 == rc);
391 }
392 static inline int
393 EVP_MD4_Update(EVP_MD4_CTX *ctx, const void *data, size_t length)
394 {
395     return (1 == EVP_DigestUpdate(*ctx, data, length));
396 }
397 #endif
398 
399 #ifdef USE_LIB_CRYPTO_MD5
400 #define MD5_CTX EVP_MD5_CTX
401 #define MD5_Init EVP_MD5_Init
402 #define MD5_Final EVP_MD5_Final
403 #define MD5_Update EVP_MD5_Update
404 typedef EVP_MD_CTX * EVP_MD5_CTX;
405 static inline int
406 EVP_MD5_Init(EVP_MD5_CTX *ctx)
407 {
408     return ((*ctx = EVP_MD_CTX_new()) != NULL
409             && 1 == EVP_DigestInit_ex(*ctx, EVP_md5(), NULL));
410 }
411 static inline int
412 EVP_MD5_Final(unsigned char *digest, EVP_MD5_CTX *ctx)
413 {
414     /* MD5_DIGEST_LENGTH; EVP_MD_size(EVP_md5()) */
415     int rc = EVP_DigestFinal_ex(*ctx, digest, NULL);
416     EVP_MD_CTX_free(*ctx);
417     return (1 == rc);
418 }
419 static inline int
420 EVP_MD5_Update(EVP_MD5_CTX *ctx, const void *data, size_t length)
421 {
422     return (1 == EVP_DigestUpdate(*ctx, data, length));
423 }
424 #endif
425 
426 #ifdef USE_LIB_CRYPTO_SHA1
427 #define SHA_CTX EVP_SHA1_CTX
428 #define SHA1_Init EVP_SHA1_Init
429 #define SHA1_Final EVP_SHA1_Final
430 #define SHA1_Update EVP_SHA1_Update
431 typedef EVP_MD_CTX * EVP_SHA1_CTX;
432 static inline int
433 EVP_SHA1_Init(EVP_SHA1_CTX *ctx)
434 {
435     return ((*ctx = EVP_MD_CTX_new()) != NULL
436             && 1 == EVP_DigestInit_ex(*ctx, EVP_sha1(), NULL));
437 }
438 static inline int
439 EVP_SHA1_Final(unsigned char *digest, EVP_SHA1_CTX *ctx)
440 {
441     /* SHA_DIGEST_LENGTH; EVP_MD_size(EVP_sha1()) */
442     int rc = EVP_DigestFinal_ex(*ctx, digest, NULL);
443     EVP_MD_CTX_free(*ctx);
444     return (1 == rc);
445 }
446 static inline int
447 EVP_SHA1_Update(EVP_SHA1_CTX *ctx, const void *data, size_t length)
448 {
449     return (1 == EVP_DigestUpdate(*ctx, data, length));
450 }
451 #endif
452 
453 #ifdef USE_LIB_CRYPTO_SHA256
454 #define SHA256_CTX EVP_SHA256_CTX
455 #define SHA256_Init EVP_SHA256_Init
456 #define SHA256_Final EVP_SHA256_Final
457 #define SHA256_Update EVP_SHA256_Update
458 typedef EVP_MD_CTX * EVP_SHA256_CTX;
459 static inline int
460 EVP_SHA256_Init(EVP_SHA256_CTX *ctx)
461 {
462     return ((*ctx = EVP_MD_CTX_new()) != NULL
463             && 1 == EVP_DigestInit_ex(*ctx, EVP_sha256(), NULL));
464 }
465 static inline int
466 EVP_SHA256_Final(unsigned char *digest, EVP_SHA256_CTX *ctx)
467 {
468     /* SHA256_DIGEST_LENGTH; EVP_MD_size(EVP_sha256()) */
469     int rc = EVP_DigestFinal_ex(*ctx, digest, NULL);
470     EVP_MD_CTX_free(*ctx);
471     return (1 == rc);
472 }
473 static inline int
474 EVP_SHA256_Update(EVP_SHA256_CTX *ctx, const void *data, size_t length)
475 {
476     return (1 == EVP_DigestUpdate(*ctx, data, length));
477 }
478 #endif
479 
480 #ifdef USE_LIB_CRYPTO_SHA512_256
481 #define SHA512_256_CTX EVP_SHA512_256_CTX
482 #define SHA512_256_Init EVP_SHA512_256_Init
483 #define SHA512_256_Final EVP_SHA512_256_Final
484 #define SHA512_256_Update EVP_SHA512_256_Update
485 typedef EVP_MD_CTX * EVP_SHA512_256_CTX;
486 static inline int
487 EVP_SHA512_256_Init(EVP_SHA512_256_CTX *ctx)
488 {
489     return ((*ctx = EVP_MD_CTX_new()) != NULL
490             && 1 == EVP_DigestInit_ex(*ctx, EVP_sha512_256(), NULL));
491 }
492 static inline int
493 EVP_SHA512_256_Final(unsigned char *digest, EVP_SHA512_256_CTX *ctx)
494 {
495     /* SHA256_DIGEST_LENGTH; EVP_MD_size(EVP_sha512_256()) */
496     int rc = EVP_DigestFinal_ex(*ctx, digest, NULL);
497     EVP_MD_CTX_free(*ctx);
498     return (1 == rc);
499 }
500 static inline int
501 EVP_SHA512_256_Update(EVP_SHA512_256_CTX *ctx, const void *data, size_t length)
502 {
503     return (1 == EVP_DigestUpdate(*ctx, data, length));
504 }
505 #endif
506 
507 #endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
508 
509 #elif defined(USE_GNUTLS_CRYPTO)
510 
511 #include <gnutls/crypto.h>
512 #include "buffer.h"     /* SEGFAULT() */
513 
514 #define USE_LIB_CRYPTO_MD5
515 typedef gnutls_hash_hd_t MD5_CTX;
516 static inline int
517 MD5_Init(MD5_CTX *ctx)
518 {
519     if (gnutls_hash_init(ctx, GNUTLS_DIG_MD5) < 0)
520         SEGFAULT();
521     return 1;
522 }
523 static inline int
524 MD5_Final(unsigned char *digest, MD5_CTX *ctx)
525 {
526     gnutls_hash_deinit(*ctx, digest);
527     return 1;
528 }
529 static inline int
530 MD5_Update(MD5_CTX *ctx, const void *data, size_t length)
531 {
532     gnutls_hash(*ctx, data, length);
533     return 1;
534 }
535 
536 #define USE_LIB_CRYPTO_SHA1
537 typedef gnutls_hash_hd_t SHA_CTX;
538 static inline int
539 SHA1_Init(SHA_CTX *ctx)
540 {
541     if (gnutls_hash_init(ctx, GNUTLS_DIG_SHA1) < 0)
542         SEGFAULT();
543     return 1;
544 }
545 static inline int
546 SHA1_Final(unsigned char *digest, SHA_CTX *ctx)
547 {
548     gnutls_hash_deinit(*ctx, digest);
549     return 1;
550 }
551 static inline int
552 SHA1_Update(SHA_CTX *ctx, const void *data, size_t length)
553 {
554     gnutls_hash(*ctx, data, length);
555     return 1;
556 }
557 
558 #define USE_LIB_CRYPTO_SHA256
559 typedef gnutls_hash_hd_t SHA256_CTX;
560 static inline int
561 SHA256_Init(SHA256_CTX *ctx)
562 {
563     if (gnutls_hash_init(ctx, GNUTLS_DIG_SHA256) < 0)
564         SEGFAULT();
565     return 1;
566 }
567 static inline int
568 SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
569 {
570     gnutls_hash_deinit(*ctx, digest);
571     return 1;
572 }
573 static inline int
574 SHA256_Update(SHA256_CTX *ctx, const void *data, size_t length)
575 {
576     gnutls_hash(*ctx, data, length);
577     return 1;
578 }
579 
580 #elif defined(USE_NSS_CRYPTO)
581 
582 #ifdef __has_include
583 #if __has_include(<nss3/nss.h>)
584 #define NSS_VER_INCLUDE
585 #endif
586 #endif
587 
588 /* basic algorithms fail if NSS library has not been init'd (WTH).
589  * lighttpd defers initialization of rand and crypto until first use
590  * to attempt to avoid long, blocking init at startup while waiting
591  * for sufficient system entropy to become available */
592 #ifdef NSS_VER_INCLUDE
593 #include <nss3/nss.h>   /* NSS_IsInitialized() NSS_NoDB_Init() */
594 #else
595 #include <nss/nss.h>    /* NSS_IsInitialized() NSS_NoDB_Init() */
596 #endif
597 #include <stdlib.h>     /* abort() */
598 __attribute_cold__
599 static inline void
600 nss_requires_explicit_init_for_basic_crypto_wth(void)
601 {
602     if (NSS_NoDB_Init(NULL) < 0)
603         abort();
604 }
605 
606 #ifdef NSS_VER_INCLUDE
607 #include <nss3/sechash.h>
608 #else
609 #include <nss/sechash.h>
610 #endif
611 
612 #define NSS_gen_hashfuncs(name, typ)                                          \
613 static inline int                                                             \
614 name##_Init(void **ctx)                                                       \
615 {                                                                             \
616     if (!NSS_IsInitialized())                                                 \
617         nss_requires_explicit_init_for_basic_crypto_wth();                    \
618     const SECHashObject * const hashObj = HASH_GetHashObject(typ);            \
619     return ((*ctx=hashObj->create()) != NULL) ? (hashObj->begin(*ctx),1) : 0; \
620 }                                                                             \
621 static inline int                                                             \
622 name##_Final(unsigned char *dest, void **ctx)                                 \
623 {                                                                             \
624     const SECHashObject * const hashObj = HASH_GetHashObject(typ);            \
625     unsigned int retLen;                                                      \
626     hashObj->end(*ctx, dest, &retLen, hashObj->length);                       \
627     hashObj->destroy(*ctx, PR_TRUE);                                          \
628     return 1;                                                                 \
629 }                                                                             \
630 static inline int                                                             \
631 name##_Update(void **ctx, const void *src, size_t len)                        \
632 {                                                                             \
633     const SECHashObject * const hashObj = HASH_GetHashObject(typ);            \
634     hashObj->update(*ctx, src, (int)len);                                     \
635     return 1;                                                                 \
636 }                                                                             \
637 typedef void * name##_CTX
638 typedef void * SHA_CTX;
639 
640 #define USE_LIB_CRYPTO_MD5
641 /* MD5_Init()
642  * MD5_Update()
643  * MD5_Final() */
644 NSS_gen_hashfuncs(MD5, HASH_AlgMD5);
645 
646 #define USE_LIB_CRYPTO_SHA1
647 /* SHA1_Init()
648  * SHA1_Update()
649  * SHA1_Final() */
650 NSS_gen_hashfuncs(SHA1, HASH_AlgSHA1);
651 
652 #define USE_LIB_CRYPTO_SHA256
653 /* SHA256_Init()
654  * SHA256_Update()
655  * SHA256_Final() */
656 NSS_gen_hashfuncs(SHA256, HASH_AlgSHA256);
657 
658 #endif
659 
660 #endif /* USE_LIB_CRYPTO */
661 
662 
663 #ifdef USE_LIB_CRYPTO_MD5
664 #ifndef MD5_DIGEST_LENGTH
665 #define MD5_DIGEST_LENGTH 16
666 #endif
667 #include "algo_md5.h" /*(for legacy li_MD5_*() name mangling)*/
668 #else
669 #include "algo_md5.h"
670 #endif
671 
672 
673 #ifdef USE_LIB_CRYPTO_SHA1
674 #ifndef SHA_DIGEST_LENGTH
675 #define SHA_DIGEST_LENGTH 20
676 #endif
677 #else
678 #include "algo_sha1.h"
679 #endif
680 
681 
682 #endif /* LI_SYS_CRYPTO_MD_H */
683