a3ba41c
diff -up openssh-5.2p1/auth2-pubkey.c.fips openssh-5.2p1/auth2-pubkey.c
0a4fa5d
--- openssh-5.2p1/auth2-pubkey.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/auth2-pubkey.c	2009-04-17 14:52:11.000000000 +0200
d93958d
@@ -33,6 +33,7 @@
d93958d
 #include <stdio.h>
d93958d
 #include <stdarg.h>
d93958d
 #include <unistd.h>
d93958d
+#include <openssl/fips.h>
d93958d
 
d93958d
 #include "xmalloc.h"
d93958d
 #include "ssh.h"
d93958d
@@ -243,7 +244,7 @@ user_key_allowed2(struct passwd *pw, Key
d93958d
 			found_key = 1;
d93958d
 			debug("matching key found: file %s, line %lu",
d93958d
 			    file, linenum);
d93958d
-			fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
d93958d
+			fp = key_fingerprint(found, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
d93958d
 			verbose("Found matching %s key: %s",
d93958d
 			    key_type(found), fp);
d93958d
 			xfree(fp);
0a4fa5d
diff -up openssh-5.2p1/cipher.c.fips openssh-5.2p1/cipher.c
0a4fa5d
--- openssh-5.2p1/cipher.c.fips	2009-03-06 18:23:21.000000000 +0100
0a4fa5d
+++ openssh-5.2p1/cipher.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -40,6 +40,7 @@
0a4fa5d
 #include <sys/types.h>
d93958d
 
0a4fa5d
 #include <openssl/md5.h>
d93958d
+#include <openssl/fips.h>
adad2a8
 
0a4fa5d
 #include <string.h>
0a4fa5d
 #include <stdarg.h>
0a4fa5d
@@ -93,6 +94,22 @@ struct Cipher {
0a4fa5d
 	{ NULL,			SSH_CIPHER_INVALID, 0, 0, 0, 0, NULL }
0a4fa5d
 };
adad2a8
 
0a4fa5d
+struct Cipher fips_ciphers[] = {
0a4fa5d
+	{ "none",		SSH_CIPHER_NONE, 8, 0, 0, 0, EVP_enc_null },
0a4fa5d
+	{ "3des",		SSH_CIPHER_3DES, 8, 16, 0, 1, evp_ssh1_3des },
d93958d
+
0a4fa5d
+	{ "3des-cbc",		SSH_CIPHER_SSH2, 8, 24, 0, 1, EVP_des_ede3_cbc },
0a4fa5d
+	{ "aes128-cbc",		SSH_CIPHER_SSH2, 16, 16, 0, 1, EVP_aes_128_cbc },
0a4fa5d
+	{ "aes192-cbc",		SSH_CIPHER_SSH2, 16, 24, 0, 1, EVP_aes_192_cbc },
0a4fa5d
+	{ "aes256-cbc",		SSH_CIPHER_SSH2, 16, 32, 0, 1, EVP_aes_256_cbc },
0a4fa5d
+	{ "rijndael-cbc@lysator.liu.se",
0a4fa5d
+				SSH_CIPHER_SSH2, 16, 32, 0, 1, EVP_aes_256_cbc },
0a4fa5d
+	{ "aes128-ctr",		SSH_CIPHER_SSH2, 16, 16, 0, 0, evp_aes_128_ctr },
0a4fa5d
+	{ "aes192-ctr",		SSH_CIPHER_SSH2, 16, 24, 0, 0, evp_aes_128_ctr },
0a4fa5d
+	{ "aes256-ctr",		SSH_CIPHER_SSH2, 16, 32, 0, 0, evp_aes_128_ctr },
0a4fa5d
+	{ NULL,			SSH_CIPHER_INVALID, 0, 0, 0, 0, NULL }
0a4fa5d
+};
adad2a8
+
0a4fa5d
 /*--*/
adad2a8
 
0a4fa5d
 u_int
0a4fa5d
@@ -135,7 +152,7 @@ Cipher *
0a4fa5d
 cipher_by_name(const char *name)
0a4fa5d
 {
0a4fa5d
 	Cipher *c;
0a4fa5d
-	for (c = ciphers; c->name != NULL; c++)
0a4fa5d
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
0a4fa5d
 		if (strcmp(c->name, name) == 0)
0a4fa5d
 			return c;
0a4fa5d
 	return NULL;
0a4fa5d
@@ -145,7 +162,7 @@ Cipher *
0a4fa5d
 cipher_by_number(int id)
0a4fa5d
 {
0a4fa5d
 	Cipher *c;
0a4fa5d
-	for (c = ciphers; c->name != NULL; c++)
0a4fa5d
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
0a4fa5d
 		if (c->number == id)
0a4fa5d
 			return c;
0a4fa5d
 	return NULL;
0a4fa5d
@@ -189,7 +206,7 @@ cipher_number(const char *name)
0a4fa5d
 	Cipher *c;
0a4fa5d
 	if (name == NULL)
0a4fa5d
 		return -1;
0a4fa5d
-	for (c = ciphers; c->name != NULL; c++)
0a4fa5d
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
0a4fa5d
 		if (strcasecmp(c->name, name) == 0)
0a4fa5d
 			return c->number;
0a4fa5d
 	return -1;
0a4fa5d
diff -up openssh-5.2p1/cipher-ctr.c.fips openssh-5.2p1/cipher-ctr.c
0a4fa5d
--- openssh-5.2p1/cipher-ctr.c.fips	2007-06-14 15:21:33.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/cipher-ctr.c	2009-04-17 23:23:06.000000000 +0200
0a4fa5d
@@ -140,7 +140,8 @@ evp_aes_128_ctr(void)
0a4fa5d
 	aes_ctr.do_cipher = ssh_aes_ctr;
0a4fa5d
 #ifndef SSH_OLD_EVP
0a4fa5d
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
0a4fa5d
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
0a4fa5d
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
0a4fa5d
+	    EVP_CIPH_FLAG_FIPS;
adad2a8
 #endif
0a4fa5d
 	return (&aes_ctr);
0a4fa5d
 }
a3ba41c
diff -up openssh-5.2p1/mac.c.fips openssh-5.2p1/mac.c
a3ba41c
--- openssh-5.2p1/mac.c.fips	2008-06-13 02:58:50.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/mac.c	2009-04-17 14:52:11.000000000 +0200
d93958d
@@ -28,6 +28,7 @@
d93958d
 #include <sys/types.h>
d93958d
 
d93958d
 #include <openssl/hmac.h>
d93958d
+#include <openssl/fips.h>
d93958d
 
d93958d
 #include <stdarg.h>
d93958d
 #include <string.h>
d93958d
@@ -47,14 +48,14 @@
d93958d
 #define SSH_EVP		1	/* OpenSSL EVP-based MAC */
d93958d
 #define SSH_UMAC	2	/* UMAC (not integrated with OpenSSL) */
d93958d
 
d93958d
-struct {
d93958d
+struct Macs {
d93958d
 	char		*name;
d93958d
 	int		type;
d93958d
 	const EVP_MD *	(*mdfunc)(void);
d93958d
 	int		truncatebits;	/* truncate digest if != 0 */
d93958d
 	int		key_len;	/* just for UMAC */
d93958d
 	int		len;		/* just for UMAC */
d93958d
-} macs[] = {
d93958d
+} all_macs[] = {
d93958d
 	{ "hmac-sha1",			SSH_EVP, EVP_sha1, 0, -1, -1 },
d93958d
 	{ "hmac-sha1-96",		SSH_EVP, EVP_sha1, 96, -1, -1 },
d93958d
 	{ "hmac-md5",			SSH_EVP, EVP_md5, 0, -1, -1 },
d93958d
@@ -65,9 +66,15 @@ struct {
d93958d
 	{ NULL,				0, NULL, 0, -1, -1 }
d93958d
 };
d93958d
 
d93958d
+struct Macs fips_macs[] = {
d93958d
+	{ "hmac-sha1",			SSH_EVP, EVP_sha1, 0, -1, -1 },
d93958d
+	{ NULL,				0, NULL, 0, -1, -1 }
d93958d
+};
d93958d
+
d93958d
 static void
d93958d
 mac_setup_by_id(Mac *mac, int which)
d93958d
 {
d93958d
+	struct Macs *macs = FIPS_mode() ? fips_macs : all_macs;
d93958d
 	int evp_len;
d93958d
 	mac->type = macs[which].type;
d93958d
 	if (mac->type == SSH_EVP) {
d93958d
@@ -88,6 +95,7 @@ int
d93958d
 mac_setup(Mac *mac, char *name)
d93958d
 {
d93958d
 	int i;
d93958d
+	struct Macs *macs = FIPS_mode() ? fips_macs : all_macs;
d93958d
 
d93958d
 	for (i = 0; macs[i].name; i++) {
d93958d
 		if (strcmp(name, macs[i].name) == 0) {
0a4fa5d
diff -up openssh-5.2p1/Makefile.in.fips openssh-5.2p1/Makefile.in
0a4fa5d
--- openssh-5.2p1/Makefile.in.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/Makefile.in	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -134,28 +134,28 @@ libssh.a: $(LIBSSH_OBJS)
0a4fa5d
 	$(RANLIB) $@
d93958d
 
0a4fa5d
 ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
0a4fa5d
-	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
+	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
d93958d
 
0a4fa5d
 sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
0a4fa5d
-	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS)
0a4fa5d
+	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) -lfipscheck $(LIBS)
d93958d
 
0a4fa5d
 scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
0a4fa5d
 	$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
d93958d
 
0a4fa5d
 ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o
0a4fa5d
-	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
+	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
a3ba41c
 
0a4fa5d
 ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o
0a4fa5d
-	$(LD) -o $@ ssh-agent.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
+	$(LD) -o $@ ssh-agent.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
a3ba41c
 
0a4fa5d
 ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o
0a4fa5d
-	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
+	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
a3ba41c
 
0a4fa5d
 ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o
0a4fa5d
-	$(LD) -o $@ ssh-keysign.o readconf.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
+	$(LD) -o $@ ssh-keysign.o readconf.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
0a4fa5d
 
0a4fa5d
 ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o
0a4fa5d
-	$(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
0a4fa5d
+	$(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
0a4fa5d
 
0a4fa5d
 sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o
0a4fa5d
 	$(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
0a4fa5d
diff -up openssh-5.2p1/myproposal.h.fips openssh-5.2p1/myproposal.h
0a4fa5d
--- openssh-5.2p1/myproposal.h.fips	2009-01-28 06:33:31.000000000 +0100
0a4fa5d
+++ openssh-5.2p1/myproposal.h	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -53,7 +53,12 @@
0a4fa5d
 	"hmac-sha1-96,hmac-md5-96"
0a4fa5d
 #define	KEX_DEFAULT_COMP	"none,zlib@openssh.com,zlib"
0a4fa5d
 #define	KEX_DEFAULT_LANG	""
0a4fa5d
-
0a4fa5d
+#define	KEX_FIPS_ENCRYPT \
0a4fa5d
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
0a4fa5d
+	"aes128-cbc,3des-cbc," \
0a4fa5d
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se"
0a4fa5d
+#define	KEX_FIPS_MAC \
0a4fa5d
+	"hmac-sha1"
0a4fa5d
 
0a4fa5d
 static char *myproposal[PROPOSAL_MAX] = {
0a4fa5d
 	KEX_DEFAULT_KEX,
a3ba41c
diff -up openssh-5.2p1/nsskeys.c.fips openssh-5.2p1/nsskeys.c
0a4fa5d
--- openssh-5.2p1/nsskeys.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/nsskeys.c	2009-04-17 14:52:11.000000000 +0200
d93958d
@@ -183,8 +183,8 @@ nss_convert_pubkey(Key *k)
d93958d
 			break;
d93958d
 	}
d93958d
 
d93958d
-	p = key_fingerprint(k, SSH_FP_MD5, SSH_FP_HEX);
d93958d
-	debug("fingerprint %u %s", key_size(k), p);
d93958d
+	p = key_fingerprint(k, SSH_FP_SHA1, SSH_FP_HEX);
d93958d
+	debug("SHA1 fingerprint %u %s", key_size(k), p);
d93958d
 	xfree(p);
d93958d
 
d93958d
 	return 0;
a3ba41c
diff -up openssh-5.2p1/openbsd-compat/bsd-arc4random.c.fips openssh-5.2p1/openbsd-compat/bsd-arc4random.c
a3ba41c
--- openssh-5.2p1/openbsd-compat/bsd-arc4random.c.fips	2008-06-04 02:54:00.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/openbsd-compat/bsd-arc4random.c	2009-04-17 14:52:11.000000000 +0200
d93958d
@@ -39,6 +39,7 @@
d93958d
 static int rc4_ready = 0;
d93958d
 static RC4_KEY rc4;
d93958d
 
d93958d
+#if 0
d93958d
 unsigned int
d93958d
 arc4random(void)
d93958d
 {
d93958d
@@ -82,6 +83,32 @@ arc4random_stir(void)
d93958d
 
d93958d
 	rc4_ready = REKEY_BYTES;
d93958d
 }
d93958d
+#else
d93958d
+unsigned int
d93958d
+arc4random(void)
d93958d
+{
d93958d
+	unsigned int r = 0;
d93958d
+	void *rp = &r;
d93958d
+
d93958d
+	if (!rc4_ready) {
d93958d
+		arc4random_stir();
d93958d
+	}
d93958d
+	RAND_bytes(rp, sizeof(r));
d93958d
+
d93958d
+	return(r);
d93958d
+}
d93958d
+
d93958d
+void
d93958d
+arc4random_stir(void)
d93958d
+{
d93958d
+	unsigned char rand_buf[SEED_SIZE];
d93958d
+
d93958d
+	if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
d93958d
+		fatal("Couldn't obtain random bytes (error %ld)",
d93958d
+		    ERR_get_error());
d93958d
+	rc4_ready = 1;
d93958d
+}
d93958d
+#endif
d93958d
 #endif /* !HAVE_ARC4RANDOM */
d93958d
 
d93958d
 #ifndef ARC4RANDOM_BUF
0a4fa5d
diff -up openssh-5.2p1/ssh-add.c.fips openssh-5.2p1/ssh-add.c
0a4fa5d
--- openssh-5.2p1/ssh-add.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/ssh-add.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -42,6 +42,8 @@
0a4fa5d
 #include <sys/param.h>
d93958d
 
d93958d
 #include <openssl/evp.h>
d93958d
+#include <openssl/fips.h>
d93958d
+#include <fipscheck.h>
0a4fa5d
 #include "openbsd-compat/openssl-compat.h"
d93958d
 
0a4fa5d
 #ifdef HAVE_LIBNSS
0a4fa5d
@@ -254,7 +256,7 @@ list_identities(AuthenticationConnection
0a4fa5d
 		    key = ssh_get_next_identity(ac, &comment, version)) {
0a4fa5d
 			had_identities = 1;
0a4fa5d
 			if (do_fp) {
0a4fa5d
-				fp = key_fingerprint(key, SSH_FP_MD5,
0a4fa5d
+				fp = key_fingerprint(key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5,
0a4fa5d
 				    SSH_FP_HEX);
0a4fa5d
 				printf("%d %s %s (%s)\n",
0a4fa5d
 				    key_size(key), fp, comment, key_type(key));
0a4fa5d
@@ -463,10 +465,19 @@ main(int argc, char **argv)
0a4fa5d
 	sanitise_stdfd();
adad2a8
 
0a4fa5d
 	__progname = ssh_get_progname(argv[0]);
0a4fa5d
+	SSLeay_add_all_algorithms();
0a4fa5d
+	if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+		fprintf(stderr,
0a4fa5d
+		    "FIPS integrity verification test failed.\n");
0a4fa5d
+		exit(3);
0a4fa5d
+	}
a3ba41c
+
a3ba41c
 	init_rng();
a3ba41c
 	seed_rng();
d93958d
 
a3ba41c
-	SSLeay_add_all_algorithms();
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
 
0a4fa5d
 	/* At first, get a connection to the authentication agent. */
0a4fa5d
 	ac = ssh_get_authentication_connection();
0a4fa5d
diff -up openssh-5.2p1/ssh-agent.c.fips openssh-5.2p1/ssh-agent.c
0a4fa5d
--- openssh-5.2p1/ssh-agent.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/ssh-agent.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -51,6 +51,8 @@
adad2a8
 
0a4fa5d
 #include <openssl/evp.h>
adad2a8
 #include <openssl/md5.h>
adad2a8
+#include <openssl/fips.h>
0a4fa5d
+#include <fipscheck.h>
0a4fa5d
 #include "openbsd-compat/openssl-compat.h"
adad2a8
 
0a4fa5d
 #include <errno.h>
0a4fa5d
@@ -200,9 +202,9 @@ confirm_key(Identity *id)
0a4fa5d
 	char *p;
0a4fa5d
 	int ret = -1;
adad2a8
 
0a4fa5d
-	p = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX);
0a4fa5d
-	if (ask_permission("Allow use of key %s?\nKey fingerprint %s.",
0a4fa5d
-	    id->comment, p))
0a4fa5d
+	p = key_fingerprint(id->key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
0a4fa5d
+	if (ask_permission("Allow use of key %s?\nKey %sfingerprint %s.",
0a4fa5d
+	    id->comment, FIPS_mode() ? "SHA1 " : "", p))
0a4fa5d
 		ret = 0;
0a4fa5d
 	xfree(p);
adad2a8
 
0a4fa5d
@@ -1196,6 +1198,11 @@ main(int ac, char **av)
0a4fa5d
 #endif
0a4fa5d
 
0a4fa5d
 	SSLeay_add_all_algorithms();
0a4fa5d
+	if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+		fprintf(stderr,
0a4fa5d
+			"FIPS integrity verification test failed.\n");
0a4fa5d
+		exit(3);
0a4fa5d
+	}
0a4fa5d
 
0a4fa5d
 	__progname = ssh_get_progname(av[0]);
0a4fa5d
 	init_rng();
0a4fa5d
@@ -1356,6 +1363,10 @@ main(int ac, char **av)
0a4fa5d
 	/* child */
0a4fa5d
 	log_init(__progname, SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_AUTH, 0);
a3ba41c
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	if (setsid() == -1) {
0a4fa5d
 		error("setsid: %s", strerror(errno));
0a4fa5d
 		cleanup_exit(1);
0a4fa5d
diff -up openssh-5.2p1/ssh.c.fips openssh-5.2p1/ssh.c
0a4fa5d
--- openssh-5.2p1/ssh.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/ssh.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -71,6 +71,8 @@
0a4fa5d
 
0a4fa5d
 #include <openssl/evp.h>
0a4fa5d
 #include <openssl/err.h>
d93958d
+#include <openssl/fips.h>
d93958d
+#include <fipscheck.h>
0a4fa5d
 #include "openbsd-compat/openssl-compat.h"
0a4fa5d
 #include "openbsd-compat/sys-queue.h"
d93958d
 
0a4fa5d
@@ -220,6 +222,10 @@ main(int ac, char **av)
0a4fa5d
 	sanitise_stdfd();
a3ba41c
 
0a4fa5d
 	__progname = ssh_get_progname(av[0]);
adad2a8
+        SSLeay_add_all_algorithms();
d93958d
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+                fatal("FIPS integrity verification test failed.");
d93958d
+        }
adad2a8
 	init_rng();
0a4fa5d
 
0a4fa5d
 	/*
0a4fa5d
@@ -550,7 +556,6 @@ main(int ac, char **av)
0a4fa5d
 	if (!host)
0a4fa5d
 		usage();
0a4fa5d
 
0a4fa5d
-	SSLeay_add_all_algorithms();
0a4fa5d
 	ERR_load_crypto_strings();
0a4fa5d
 
0a4fa5d
 	/* Initialize the command to execute on remote host. */
0a4fa5d
@@ -635,6 +640,10 @@ main(int ac, char **av)
0a4fa5d
 
adad2a8
 	seed_rng();
0a4fa5d
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	if (options.user == NULL)
0a4fa5d
 		options.user = xstrdup(pw->pw_name);
0a4fa5d
 
0a4fa5d
diff -up openssh-5.2p1/sshconnect2.c.fips openssh-5.2p1/sshconnect2.c
0a4fa5d
--- openssh-5.2p1/sshconnect2.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/sshconnect2.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -44,6 +44,8 @@
0a4fa5d
 #include <vis.h>
0a4fa5d
 #endif
0a4fa5d
 
0a4fa5d
+#include <openssl/fips.h>
0a4fa5d
+
0a4fa5d
 #include "openbsd-compat/sys-queue.h"
0a4fa5d
 
0a4fa5d
 #include "xmalloc.h"
0a4fa5d
@@ -115,6 +117,10 @@ ssh_kex2(char *host, struct sockaddr *ho
0a4fa5d
 	if (options.ciphers != NULL) {
0a4fa5d
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
0a4fa5d
+	} else if (FIPS_mode()) {
0a4fa5d
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
0a4fa5d
+
0a4fa5d
 	}
0a4fa5d
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
0a4fa5d
@@ -130,7 +136,11 @@ ssh_kex2(char *host, struct sockaddr *ho
0a4fa5d
 	if (options.macs != NULL) {
0a4fa5d
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
0a4fa5d
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
0a4fa5d
+	} else if (FIPS_mode()) {
0a4fa5d
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
0a4fa5d
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
0a4fa5d
 	}
0a4fa5d
+
0a4fa5d
 	if (options.hostkeyalgorithms != NULL)
0a4fa5d
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
0a4fa5d
 		    options.hostkeyalgorithms;
0a4fa5d
@@ -507,8 +517,8 @@ input_userauth_pk_ok(int type, u_int32_t
0a4fa5d
 		    key->type, pktype);
0a4fa5d
 		goto done;
0a4fa5d
 	}
0a4fa5d
-	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
0a4fa5d
-	debug2("input_userauth_pk_ok: fp %s", fp);
0a4fa5d
+	fp = key_fingerprint(key, SSH_FP_SHA1, SSH_FP_HEX);
0a4fa5d
+	debug2("input_userauth_pk_ok: SHA1 fp %s", fp);
0a4fa5d
 	xfree(fp);
0a4fa5d
 
0a4fa5d
 	/*
a3ba41c
diff -up openssh-5.2p1/sshconnect.c.fips openssh-5.2p1/sshconnect.c
0a4fa5d
--- openssh-5.2p1/sshconnect.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/sshconnect.c	2009-04-17 14:52:11.000000000 +0200
d93958d
@@ -40,6 +40,8 @@
d93958d
 #include <unistd.h>
d93958d
 #include <fcntl.h>
d93958d
 
d93958d
+#include <openssl/fips.h>
d93958d
+
d93958d
 #include "xmalloc.h"
d93958d
 #include "key.h"
d93958d
 #include "hostfile.h"
0f07b4a
@@ -761,6 +763,7 @@ check_host_key(char *hostname, struct so
d93958d
 			goto fail;
d93958d
 		} else if (options.strict_host_key_checking == 2) {
d93958d
 			char msg1[1024], msg2[1024];
d93958d
+			int fips_on = FIPS_mode();
d93958d
 
d93958d
 			if (show_other_keys(host, host_key))
d93958d
 				snprintf(msg1, sizeof(msg1),
0f07b4a
@@ -769,8 +772,8 @@ check_host_key(char *hostname, struct so
d93958d
 			else
d93958d
 				snprintf(msg1, sizeof(msg1), ".");
d93958d
 			/* The default */
d93958d
-			fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
d93958d
-			ra = key_fingerprint(host_key, SSH_FP_MD5,
d93958d
+			fp = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
d93958d
+			ra = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
d93958d
 			    SSH_FP_RANDOMART);
d93958d
 			msg2[0] = '\0';
d93958d
 			if (options.verify_host_key_dns) {
0f07b4a
@@ -786,10 +789,10 @@ check_host_key(char *hostname, struct so
d93958d
 			snprintf(msg, sizeof(msg),
d93958d
 			    "The authenticity of host '%.200s (%s)' can't be "
d93958d
 			    "established%s\n"
d93958d
-			    "%s key fingerprint is %s.%s%s\n%s"
d93958d
+			    "%s key %sfingerprint is %s.%s%s\n%s"
d93958d
 			    "Are you sure you want to continue connecting "
d93958d
 			    "(yes/no)? ",
d93958d
-			    host, ip, msg1, type, fp,
d93958d
+			    host, ip, msg1, type, fips_on ? "SHA1 " : "", fp,
d93958d
 			    options.visual_host_key ? "\n" : "",
d93958d
 			    options.visual_host_key ? ra : "",
d93958d
 			    msg2);
0f07b4a
@@ -1077,17 +1080,18 @@ show_key_from_file(const char *file, con
d93958d
 	Key *found;
d93958d
 	char *fp, *ra;
d93958d
 	int line, ret;
d93958d
+	int fips_on = FIPS_mode();
d93958d
 
d93958d
 	found = key_new(keytype);
d93958d
 	if ((ret = lookup_key_in_hostfile_by_type(file, host,
d93958d
 	    keytype, found, &line))) {
d93958d
-		fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
d93958d
-		ra = key_fingerprint(found, SSH_FP_MD5, SSH_FP_RANDOMART);
d93958d
+		fp = key_fingerprint(found, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
d93958d
+		ra = key_fingerprint(found, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_RANDOMART);
d93958d
 		logit("WARNING: %s key found for host %s\n"
d93958d
 		    "in %s:%d\n"
d93958d
-		    "%s key fingerprint %s.\n%s\n",
d93958d
+		    "%s key %sfingerprint %s.\n%s\n",
d93958d
 		    key_type(found), host, file, line,
d93958d
-		    key_type(found), fp, ra);
d93958d
+		    key_type(found), fips_on ? "SHA1 ":"", fp, ra);
d93958d
 		xfree(ra);
d93958d
 		xfree(fp);
d93958d
 	}
0f07b4a
@@ -1133,8 +1137,9 @@ warn_changed_key(Key *host_key)
d93958d
 {
d93958d
 	char *fp;
d93958d
 	const char *type = key_type(host_key);
d93958d
+	int fips_on = FIPS_mode();
d93958d
 
d93958d
-	fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
d93958d
+	fp = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
d93958d
 
d93958d
 	error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
d93958d
 	error("@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @");
0f07b4a
@@ -1142,8 +1147,8 @@ warn_changed_key(Key *host_key)
d93958d
 	error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");
d93958d
 	error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!");
d93958d
 	error("It is also possible that the %s host key has just been changed.", type);
d93958d
-	error("The fingerprint for the %s key sent by the remote host is\n%s.",
d93958d
-	    type, fp);
d93958d
+	error("The %sfingerprint for the %s key sent by the remote host is\n%s.",
d93958d
+	    fips_on ? "SHA1 ":"", type, fp);
d93958d
 	error("Please contact your system administrator.");
d93958d
 
d93958d
 	xfree(fp);
0a4fa5d
diff -up openssh-5.2p1/sshd.c.fips openssh-5.2p1/sshd.c
0a4fa5d
--- openssh-5.2p1/sshd.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/sshd.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -76,6 +76,8 @@
0a4fa5d
 #include <openssl/bn.h>
0a4fa5d
 #include <openssl/md5.h>
0a4fa5d
 #include <openssl/rand.h>
0a4fa5d
+#include <openssl/fips.h>
0a4fa5d
+#include <fipscheck.h>
0a4fa5d
 #include "openbsd-compat/openssl-compat.h"
0a4fa5d
 
0a4fa5d
 #ifdef HAVE_SECUREWARE
0a4fa5d
@@ -1260,6 +1262,12 @@ main(int ac, char **av)
0a4fa5d
 	(void)set_auth_parameters(ac, av);
0a4fa5d
 #endif
0a4fa5d
 	__progname = ssh_get_progname(av[0]);
0a4fa5d
+
0a4fa5d
+        SSLeay_add_all_algorithms();
0a4fa5d
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+                fatal("FIPS integrity verification test failed.");
0a4fa5d
+        }
0a4fa5d
+
0a4fa5d
 	init_rng();
0a4fa5d
 
0a4fa5d
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
0a4fa5d
@@ -1412,8 +1420,6 @@ main(int ac, char **av)
0a4fa5d
 	else
0a4fa5d
 		closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
0a4fa5d
 
0a4fa5d
-	SSLeay_add_all_algorithms();
0a4fa5d
-
0a4fa5d
 	/*
0a4fa5d
 	 * Force logging to stderr until we have loaded the private host
0a4fa5d
 	 * key (unless started from inetd)
0a4fa5d
@@ -1655,6 +1661,10 @@ main(int ac, char **av)
0a4fa5d
 	/* Initialize the random number generator. */
0a4fa5d
 	arc4random_stir();
0a4fa5d
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	/* Chdir to the root directory so that the current disk can be
0a4fa5d
 	   unmounted if desired. */
0a4fa5d
 	chdir("/");
0a4fa5d
@@ -2182,6 +2192,9 @@ do_ssh2_kex(void)
0a4fa5d
 	if (options.ciphers != NULL) {
0a4fa5d
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
0a4fa5d
+	} else if (FIPS_mode()) {
0a4fa5d
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
0a4fa5d
 	}
0a4fa5d
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
0a4fa5d
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
0a4fa5d
@@ -2191,6 +2204,9 @@ do_ssh2_kex(void)
0a4fa5d
 	if (options.macs != NULL) {
0a4fa5d
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
0a4fa5d
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
0a4fa5d
+	} else if (FIPS_mode()) {
0a4fa5d
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
0a4fa5d
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
0a4fa5d
 	}
0a4fa5d
 	if (options.compression == COMP_NONE) {
0a4fa5d
 		myproposal[PROPOSAL_COMP_ALGS_CTOS] =
0a4fa5d
diff -up openssh-5.2p1/ssh-keygen.c.fips openssh-5.2p1/ssh-keygen.c
0a4fa5d
--- openssh-5.2p1/ssh-keygen.c.fips	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/ssh-keygen.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -21,6 +21,8 @@
0a4fa5d
 
0a4fa5d
 #include <openssl/evp.h>
0a4fa5d
 #include <openssl/pem.h>
0a4fa5d
+#include <openssl/fips.h>
0a4fa5d
+#include <fipscheck.h>
0a4fa5d
 #include "openbsd-compat/openssl-compat.h"
0a4fa5d
 
0a4fa5d
 #include <errno.h>
0a4fa5d
@@ -537,7 +539,7 @@ do_fingerprint(struct passwd *pw)
0a4fa5d
 	enum fp_type fptype;
0a4fa5d
 	struct stat st;
0a4fa5d
 
0a4fa5d
-	fptype = print_bubblebabble ? SSH_FP_SHA1 : SSH_FP_MD5;
0a4fa5d
+	fptype = print_bubblebabble ? SSH_FP_SHA1 : FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5;
0a4fa5d
 	rep =    print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_HEX;
0a4fa5d
 
0a4fa5d
 	if (!have_identity)
0a4fa5d
@@ -1125,11 +1127,21 @@ main(int argc, char **argv)
0a4fa5d
 	__progname = ssh_get_progname(argv[0]);
0a4fa5d
 
0a4fa5d
 	SSLeay_add_all_algorithms();
0a4fa5d
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+                fprintf(stderr,
0a4fa5d
+                    "FIPS integrity verification test failed.\n");
0a4fa5d
+                exit(3);
0a4fa5d
+        }
0a4fa5d
+
0a4fa5d
 	log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
0a4fa5d
 
0a4fa5d
 	init_rng();
0a4fa5d
 	seed_rng();
0a4fa5d
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	/* we need this for the home * directory.  */
0a4fa5d
 	pw = getpwuid(getuid());
0a4fa5d
 	if (!pw) {
0a4fa5d
@@ -1506,14 +1518,15 @@ passphrase_again:
0a4fa5d
 	fclose(f);
0a4fa5d
 
0a4fa5d
 	if (!quiet) {
0a4fa5d
-		char *fp = key_fingerprint(public, SSH_FP_MD5, SSH_FP_HEX);
0a4fa5d
-		char *ra = key_fingerprint(public, SSH_FP_MD5,
0a4fa5d
+		int fips_on = FIPS_mode();
0a4fa5d
+		char *fp = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
0a4fa5d
+		char *ra = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
0a4fa5d
 		    SSH_FP_RANDOMART);
0a4fa5d
 		printf("Your public key has been saved in %s.\n",
0a4fa5d
 		    identity_file);
0a4fa5d
-		printf("The key fingerprint is:\n");
0a4fa5d
+		printf("The key %sfingerprint is:\n", fips_on ? "SHA1 " : "");
0a4fa5d
 		printf("%s %s\n", fp, comment);
0a4fa5d
-		printf("The key's randomart image is:\n");
0a4fa5d
+		printf("The key's %srandomart image is:\n", fips_on ? "SHA1 " :"");
0a4fa5d
 		printf("%s\n", ra);
0a4fa5d
 		xfree(ra);
0a4fa5d
 		xfree(fp);
0a4fa5d
diff -up openssh-5.2p1/ssh-keyscan.c.fips openssh-5.2p1/ssh-keyscan.c
0a4fa5d
--- openssh-5.2p1/ssh-keyscan.c.fips	2009-01-28 06:31:23.000000000 +0100
0a4fa5d
+++ openssh-5.2p1/ssh-keyscan.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -19,6 +19,8 @@
0a4fa5d
 #include <arpa/inet.h>
0a4fa5d
 
0a4fa5d
 #include <openssl/bn.h>
0a4fa5d
+#include <openssl/fips.h>
0a4fa5d
+#include <fipscheck.h>
0a4fa5d
 
0a4fa5d
 #include <netdb.h>
0a4fa5d
 #include <errno.h>
0a4fa5d
@@ -731,6 +733,13 @@ main(int argc, char **argv)
0a4fa5d
 	extern char *optarg;
0a4fa5d
 
0a4fa5d
 	__progname = ssh_get_progname(argv[0]);
0a4fa5d
+        SSLeay_add_all_algorithms();
0a4fa5d
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+                fprintf(stderr,
0a4fa5d
+                    "FIPS integrity verification test failed.\n");
0a4fa5d
+                exit(3);
0a4fa5d
+        }
0a4fa5d
+
0a4fa5d
 	init_rng();
0a4fa5d
 	seed_rng();
0a4fa5d
 	TAILQ_INIT(&tq;;
0a4fa5d
@@ -812,6 +821,10 @@ main(int argc, char **argv)
0a4fa5d
 
0a4fa5d
 	log_init("ssh-keyscan", log_level, SYSLOG_FACILITY_USER, 1);
0a4fa5d
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	maxfd = fdlim_get(1);
0a4fa5d
 	if (maxfd < 0)
0a4fa5d
 		fatal("%s: fdlim_get: bad value", __progname);
0a4fa5d
diff -up openssh-5.2p1/ssh-keysign.c.fips openssh-5.2p1/ssh-keysign.c
0a4fa5d
--- openssh-5.2p1/ssh-keysign.c.fips	2006-09-01 07:38:37.000000000 +0200
0a4fa5d
+++ openssh-5.2p1/ssh-keysign.c	2009-04-17 14:52:11.000000000 +0200
0a4fa5d
@@ -38,6 +38,8 @@
0a4fa5d
 #include <openssl/evp.h>
0a4fa5d
 #include <openssl/rand.h>
0a4fa5d
 #include <openssl/rsa.h>
0a4fa5d
+#include <openssl/fips.h>
0a4fa5d
+#include <fipscheck.h>
0a4fa5d
 
0a4fa5d
 #include "xmalloc.h"
0a4fa5d
 #include "log.h"
0a4fa5d
@@ -175,6 +177,11 @@ main(int argc, char **argv)
0a4fa5d
 
0a4fa5d
 	permanently_set_uid(pw);
0a4fa5d
 
0a4fa5d
+        SSLeay_add_all_algorithms();
0a4fa5d
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
0a4fa5d
+                fatal("FIPS integrity verification test failed");
0a4fa5d
+        }
0a4fa5d
+
0a4fa5d
 	init_rng();
0a4fa5d
 	seed_rng();
0a4fa5d
 	arc4random_stir();
0a4fa5d
@@ -183,6 +190,10 @@ main(int argc, char **argv)
0a4fa5d
 	log_init("ssh-keysign", SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0);
0a4fa5d
 #endif
0a4fa5d
 
0a4fa5d
+	if (FIPS_mode()) {
0a4fa5d
+		logit("FIPS mode initialized");
0a4fa5d
+	}
0a4fa5d
+
0a4fa5d
 	/* verify that ssh-keysign is enabled by the admin */
0a4fa5d
 	initialize_options(&options);
0a4fa5d
 	(void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options, 0);
0a4fa5d
@@ -194,7 +205,6 @@ main(int argc, char **argv)
0a4fa5d
 	if (key_fd[0] == -1 && key_fd[1] == -1)
0a4fa5d
 		fatal("could not open any host key");
0a4fa5d
 
0a4fa5d
-	SSLeay_add_all_algorithms();
0a4fa5d
 	for (i = 0; i < 256; i++)
0a4fa5d
 		rnd[i] = arc4random();
0a4fa5d
 	RAND_seed(rnd, sizeof(rnd));