4 * ssl_init.c Common OpenSSL initialization code for the various
5 * programs which use it.
7 * Moved from ntpd/ntp_crypto.c crypto_setup()
14 #include <ntp_debug.h>
15 #include <lib_strbuf.h>
18 #include "openssl/err.h"
19 #include "openssl/rand.h"
30 ERR_load_crypto_strings();
31 OpenSSL_add_all_algorithms();
38 ssl_check_version(void)
40 if ((SSLeay() ^ OPENSSL_VERSION_NUMBER
) & ~0xff0L
) {
42 "OpenSSL version mismatch. Built against %lx, you have %lx",
43 OPENSSL_VERSION_NUMBER
, SSLeay());
45 "OpenSSL version mismatch. Built against %lx, you have %lx\n",
46 OPENSSL_VERSION_NUMBER
, SSLeay());
55 * keytype_from_text returns OpenSSL NID for digest by name, and
56 * optionally the associated digest length.
58 * Used by ntpd authreadkeys(), ntpq and ntpdc keytype()
69 u_char digest
[EVP_MAX_MD_SIZE
];
75 * OpenSSL digest short names are capitalized, so uppercase the
76 * digest name before passing to OBJ_sn2nid(). If it is not
77 * recognized but begins with 'M' use NID_md5 to be consistent
82 strncpy(upcased
, text
, LIB_BUFLENGTH
);
83 for (pch
= upcased
; '\0' != *pch
; pch
++)
84 *pch
= (char)toupper(*pch
);
85 key_type
= OBJ_sn2nid(upcased
);
90 if (!key_type
&& 'm' == tolower(text
[0]))
96 if (NULL
!= pdigest_len
) {
98 EVP_DigestInit(&ctx
, EVP_get_digestbynid(key_type
));
99 EVP_DigestFinal(&ctx
, digest
, &digest_len
);
100 if (digest_len
+ sizeof(keyid_t
) > MAX_MAC_LEN
) {
102 "key type %s %u octet digests are too big, max %u\n",
103 keytype_name(key_type
), digest_len
,
104 MAX_MAC_LEN
- sizeof(keyid_t
));
106 "key type %s %u octet digests are too big, max %u",
107 keytype_name(key_type
), digest_len
,
108 MAX_MAC_LEN
- sizeof(keyid_t
));
114 *pdigest_len
= digest_len
;
122 * keytype_name returns OpenSSL short name for digest by NID.
124 * Used by ntpq and ntpdc keytype()
131 static const char unknown_type
[] = "(unknown key type)";
136 name
= OBJ_nid2sn(nid
);
139 #else /* !OPENSSL follows */