summaryrefslogtreecommitdiff
path: root/src/sys-crypto-md.h
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-10-21 18:18:40 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2020-10-21 18:18:40 -0400
commit23fdff645a41a84edfbb4a445014cdcee3a3bade (patch)
treeff57aec9d77e48a15ca59955fa7028063f52cb19 /src/sys-crypto-md.h
parent9868d3b348c05c54e58bf0a070366fc7cfdb54e6 (diff)
downloadlighttpd-git-23fdff645a41a84edfbb4a445014cdcee3a3bade.tar.gz
[core] init NSS lib for basic crypto algorithms
basic algorithms fail if NSS library has not been init'd (WTH) lighttpd defers initialization of rand and crypto until first use to attempt to avoid long, blocking init at startup while waiting for sufficient system entropy to become available
Diffstat (limited to 'src/sys-crypto-md.h')
-rw-r--r--src/sys-crypto-md.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/sys-crypto-md.h b/src/sys-crypto-md.h
index 9a2c2418..db1247dd 100644
--- a/src/sys-crypto-md.h
+++ b/src/sys-crypto-md.h
@@ -571,12 +571,28 @@ SHA256_Update(SHA256_CTX *ctx, const void *data, size_t length)
#elif defined(USE_NSS_CRYPTO)
+/* basic algorithms fail if NSS library has not been init'd (WTH).
+ * lighttpd defers initialization of rand and crypto until first use
+ * to attempt to avoid long, blocking init at startup while waiting
+ * for sufficient system entropy to become available */
+#include <nss3/nss.h> /* NSS_IsInitialized() NSS_NoDB_Init() */
+#include <stdlib.h> /* abort() */
+__attribute_cold__
+static inline void
+nss_requires_explicit_init_for_basic_crypto_wth(void)
+{
+ if (NSS_NoDB_Init(NULL) < 0)
+ abort();
+}
+
#include <nss3/sechash.h>
#define NSS_gen_hashfuncs(name, typ) \
static inline int \
name##_Init(void **ctx) \
{ \
+ if (!NSS_IsInitialized()) \
+ nss_requires_explicit_init_for_basic_crypto_wth(); \
const SECHashObject * const hashObj = HASH_GetHashObject(typ); \
return ((*ctx=hashObj->create()) != NULL) ? (hashObj->begin(*ctx),1) : 0; \
} \