diff --git a/openssl.c b/openssl.c
index b4e33fc..a7c57e7 100644
--- a/openssl.c
+++ b/openssl.c
@@ -135,6 +135,7 @@ ssl_rand_init(void)
 	char *cp;
 	int state = 0;
 
+#ifndef OPENSSL_NO_EGD
 	if ((cp = value("ssl-rand-egd")) != NULL) {
 		cp = expand(cp);
 		if (RAND_egd(cp) == -1) {
@@ -143,7 +144,9 @@ ssl_rand_init(void)
 					cp);
 		} else
 			state = 1;
-	} else if ((cp = value("ssl-rand-file")) != NULL) {
+	} else
+#endif
+	if ((cp = value("ssl-rand-file")) != NULL) {
 		cp = expand(cp);
 		if (RAND_load_file(cp, 1024) == -1) {
 			fprintf(stderr, catgets(catd, CATSET, 246,
@@ -216,11 +219,17 @@ ssl_select_method(const char *uhp)
 
 	cp = ssl_method_string(uhp);
 	if (cp != NULL) {
+#ifndef OPENSSL_NO_SSL2
 		if (equal(cp, "ssl2"))
 			method = SSLv2_client_method();
-		else if (equal(cp, "ssl3"))
+		else
+#endif
+#ifndef OPENSSL_NO_SSL3_METHOD
+		if (equal(cp, "ssl3"))
 			method = SSLv3_client_method();
-		else if (equal(cp, "tls1"))
+		else
+#endif
+		if (equal(cp, "tls1"))
 			method = TLSv1_client_method();
 		else {
 			fprintf(stderr, catgets(catd, CATSET, 244,
