Index: auth-passwd.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/auth-passwd.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- auth-passwd.c	19 May 2004 13:05:20 -0000	1.1
+++ auth-passwd.c	28 May 2004 16:11:40 -0000	1.3
@@ -144,8 +144,16 @@
 		return (1);
 
 	/* Encrypt the candidate password using the proper salt. */
+#ifdef OPENSSL_FIPS
+	/* In FIPS mode we enable MD5 *only* for use with the existing
+	   credentials maintained externally by the O/S */
+	FIPS_allow_md5(1);
+#endif
 	encrypted_password = xcrypt(password,
 	    (pw_password[0] && pw_password[1]) ? pw_password : "xx");
+#ifdef OPENSSL_FIPS
+	FIPS_allow_md5(0);
+#endif
 
 	/*
 	 * Authentication is accepted if the encrypted passwords
Index: ChangeLog
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ChangeLog,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- ChangeLog	19 May 2004 13:05:16 -0000	1.1
+++ ChangeLog	28 May 2004 13:30:29 -0000	1.3
@@ -1,3 +1,6 @@
+20040419
+ - Ben Laurie <ben@algroup.co.uk>, Steve Marquess <marquess@ieee.org>; Add
+    support for OPENSSL FIPS mode
 20040224
  - (dtucker) OpenBSD CVS Sync
    - markus@cvs.openbsd.org 2004/02/19 21:15:04
Index: cipher.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/cipher.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- cipher.c	19 May 2004 13:05:26 -0000	1.1
+++ cipher.c	28 May 2004 13:30:29 -0000	1.2
@@ -40,6 +40,7 @@
 #include "xmalloc.h"
 #include "log.h"
 #include "cipher.h"
+#include "fips.h"
 
 #include <openssl/md5.h>
 
@@ -75,38 +76,39 @@
 	u_int	block_size;
 	u_int	key_len;
 	const EVP_CIPHER	*(*evptype)(void);
+	u_int	fips_allowed;
 } ciphers[] = {
-	{ "none", 		SSH_CIPHER_NONE, 8, 0, EVP_enc_null },
-	{ "des", 		SSH_CIPHER_DES, 8, 8, EVP_des_cbc },
-	{ "3des", 		SSH_CIPHER_3DES, 8, 16, evp_ssh1_3des },
-	{ "blowfish", 		SSH_CIPHER_BLOWFISH, 8, 32, evp_ssh1_bf },
-
-	{ "3des-cbc", 		SSH_CIPHER_SSH2, 8, 24, EVP_des_ede3_cbc },
-	{ "blowfish-cbc", 	SSH_CIPHER_SSH2, 8, 16, EVP_bf_cbc },
-	{ "cast128-cbc", 	SSH_CIPHER_SSH2, 8, 16, EVP_cast5_cbc },
-	{ "arcfour", 		SSH_CIPHER_SSH2, 8, 16, EVP_rc4 },
+	{ "none", 		SSH_CIPHER_NONE, 8, 0, EVP_enc_null, 1, },
+	{ "des", 		SSH_CIPHER_DES, 8, 8, EVP_des_cbc, 1, },
+	{ "3des", 		SSH_CIPHER_3DES, 8, 16, evp_ssh1_3des, 1, },
+	{ "blowfish", 		SSH_CIPHER_BLOWFISH, 8, 32, evp_ssh1_bf, 0, },
+
+	{ "3des-cbc", 		SSH_CIPHER_SSH2, 8, 24, EVP_des_ede3_cbc, 1, },
+	{ "blowfish-cbc", 	SSH_CIPHER_SSH2, 8, 16, EVP_bf_cbc, 0, },
+	{ "cast128-cbc", 	SSH_CIPHER_SSH2, 8, 16, EVP_cast5_cbc, 0, },
+	{ "arcfour", 		SSH_CIPHER_SSH2, 8, 16, EVP_rc4, 0, },
 #if OPENSSL_VERSION_NUMBER < 0x00907000L
-	{ "aes128-cbc", 	SSH_CIPHER_SSH2, 16, 16, evp_rijndael },
-	{ "aes192-cbc", 	SSH_CIPHER_SSH2, 16, 24, evp_rijndael },
-	{ "aes256-cbc", 	SSH_CIPHER_SSH2, 16, 32, evp_rijndael },
+	{ "aes128-cbc", 	SSH_CIPHER_SSH2, 16, 16, evp_rijndael, 1, },
+	{ "aes192-cbc", 	SSH_CIPHER_SSH2, 16, 24, evp_rijndael, 1, },
+	{ "aes256-cbc", 	SSH_CIPHER_SSH2, 16, 32, evp_rijndael, 1, },
 	{ "rijndael-cbc@lysator.liu.se",
-				SSH_CIPHER_SSH2, 16, 32, evp_rijndael },
+				SSH_CIPHER_SSH2, 16, 32, evp_rijndael, 0, },
 #else
-	{ "aes128-cbc",		SSH_CIPHER_SSH2, 16, 16, EVP_aes_128_cbc },
-	{ "aes192-cbc",		SSH_CIPHER_SSH2, 16, 24, EVP_aes_192_cbc },
-	{ "aes256-cbc",		SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc },
+	{ "aes128-cbc",		SSH_CIPHER_SSH2, 16, 16, EVP_aes_128_cbc, 1, },
+	{ "aes192-cbc",		SSH_CIPHER_SSH2, 16, 24, EVP_aes_192_cbc, 1, },
+	{ "aes256-cbc",		SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc, 1, },
 	{ "rijndael-cbc@lysator.liu.se",
-				SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc },
+				SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc, 0, },
 #endif
 #if OPENSSL_VERSION_NUMBER >= 0x00905000L
-	{ "aes128-ctr", 	SSH_CIPHER_SSH2, 16, 16, evp_aes_128_ctr },
-	{ "aes192-ctr", 	SSH_CIPHER_SSH2, 16, 24, evp_aes_128_ctr },
-	{ "aes256-ctr", 	SSH_CIPHER_SSH2, 16, 32, evp_aes_128_ctr },
+	{ "aes128-ctr", 	SSH_CIPHER_SSH2, 16, 16, evp_aes_128_ctr, 1, },
+	{ "aes192-ctr", 	SSH_CIPHER_SSH2, 16, 24, evp_aes_128_ctr, 1, },
+	{ "aes256-ctr", 	SSH_CIPHER_SSH2, 16, 32, evp_aes_128_ctr, 1, },
 #endif
 #if defined(EVP_CTRL_SET_ACSS_MODE)
-	{ "acss@openssh.org",	SSH_CIPHER_SSH2, 16, 5, EVP_acss },
+	{ "acss@openssh.org",	SSH_CIPHER_SSH2, 16, 5, EVP_acss, 0, },
 #endif
-	{ NULL,			SSH_CIPHER_ILLEGAL, 0, 0, NULL }
+	{ NULL,			SSH_CIPHER_ILLEGAL, 0, 0, NULL, 0, }
 };
 
 /*--*/
@@ -175,6 +177,13 @@
 	for ((p = strsep(&cp, CIPHER_SEP)); p && *p != '\0';
 	    (p = strsep(&cp, CIPHER_SEP))) {
 		c = cipher_by_name(p);
+#ifdef OPENSSL_FIPS
+		if (fips_mode && !(c->fips_allowed)) {
+			debug("cipher %s disallowed in FIPS mode [%s]", p, names);
+			xfree(ciphers);
+                        return 0;
+		}
+#endif
 		if (c == NULL || c->number != SSH_CIPHER_SSH2) {
 			debug("bad cipher %s [%s]", p, names);
 			xfree(ciphers);
Index: configure.ac
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/configure.ac,v
retrieving revision 1.1
retrieving revision 1.6
diff -u -r1.1 -r1.6
--- configure.ac	19 May 2004 13:05:27 -0000	1.1
+++ configure.ac	28 May 2004 16:11:41 -0000	1.6
@@ -170,6 +170,7 @@
 	LIBS="$LIBS -lsec -lsecpw"
 	AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
 	disable_ptmx_check=yes
+	HPUX=1
 	;;
 *-*-hpux10*)
 	if test -z "$GCC"; then
@@ -184,6 +185,7 @@
 	AC_DEFINE(SPT_TYPE,SPT_PSTAT)
 	LIBS="$LIBS -lsec"
 	AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
+	HPUX=1
 	;;
 *-*-hpux11*)
 	CPPFLAGS="$CPPFLAGS -D_HPUX_SOURCE -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1"
@@ -201,6 +203,7 @@
 	esac
 	LIBS="$LIBS -lsec"
 	AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
+	HPUX=1
 	;;
 *-*-irix5*)
 	PATH="$PATH:/usr/etc"
@@ -1028,6 +1031,8 @@
 	[  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
 	[
 		if test "x$withval" != "xno" ; then
+			ssldir=$withval
+			AC_SUBST(ssldir)
 			if test -d "$withval/lib"; then
 				if test -n "${need_dash_r}"; then
 					LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
@@ -1166,7 +1171,7 @@
 
 ### Configure cryptographic random number support
 
-# Check wheter OpenSSL seeds itself
+# Check whether OpenSSL seeds itself
 AC_MSG_CHECKING([whether OpenSSL's PRNG is internally seeded])
 AC_TRY_RUN(
 	[
@@ -1186,6 +1191,33 @@
 	]
 )
 
+
+# Check for OpenSSL FIPS mode
+AC_ARG_WITH(fips,
+	[  --with-fips             Enable OpenSSL FIPS mode ],
+	[
+		if test "x$withval" != "xno" ; then
+			AC_CACHE_CHECK([for FIPS mode], ac_cv_fips, [
+				AC_TRY_COMPILE(
+					[ #include <openssl/fips.h> ],
+					[ FIPS_mode_set(1,""); ],
+					[ ac_cv_fips="yes" ],
+					[ ac_cv_fips="no" ]
+				)
+			])
+		fi
+	]
+)
+if test "x$ac_cv_fips" = "xyes" ; then
+	CPPFLAGS="$CPPFLAGS -DOPENSSL_FIPS"
+	if test "x$HPUX" = "x" ; then
+		LIBS=`echo $LIBS | sed 's/-lcrypto /-Wl,-Bstatic -lcrypto -Wl,-Bdynamic /'`
+	else
+		LIBS=`echo $LIBS | sed 's/-lcrypto /-Wl,-aarchive -lcrypto -Wl,-adefault /'`
+	fi
+	FIPS_MODE=yes
+	AC_SUBST(FIPS_MODE)
+fi
 
 # Do we want to force the use of the rand helper?
 AC_ARG_WITH(rand-helper,
Index: mac.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/mac.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mac.c	19 May 2004 12:56:12 -0000	1.1
+++ mac.c	28 May 2004 13:30:30 -0000	1.2
@@ -33,19 +33,21 @@
 #include "cipher.h"
 #include "kex.h"
 #include "mac.h"
+#include "fips.h"
 
 struct {
 	char		*name;
 	const EVP_MD *	(*mdfunc)(void);
 	int		truncatebits;	/* truncate digest if != 0 */
+	int		fips_allowed;
 } macs[] = {
-	{ "hmac-sha1",			EVP_sha1, 0, },
-	{ "hmac-sha1-96",		EVP_sha1, 96 },
-	{ "hmac-md5",			EVP_md5, 0 },
-	{ "hmac-md5-96",		EVP_md5, 96 },
-	{ "hmac-ripemd160",		EVP_ripemd160, 0 },
-	{ "hmac-ripemd160@openssh.com",	EVP_ripemd160, 0 },
-	{ NULL,				NULL, 0 }
+	{ "hmac-sha1",			EVP_sha1, 0, 1, },
+	{ "hmac-sha1-96",		EVP_sha1, 96, 1, },
+	{ "hmac-md5",			EVP_md5, 0, 0, },
+	{ "hmac-md5-96",		EVP_md5, 96, 0, },
+	{ "hmac-ripemd160",		EVP_ripemd160, 0, 0, },
+	{ "hmac-ripemd160@openssh.com",	EVP_ripemd160, 0, 0, },
+	{ NULL,				NULL, 0, 0, }
 };
 
 int
@@ -54,6 +56,12 @@
 	int i;
 	for (i = 0; macs[i].name; i++) {
 		if (strcmp(name, macs[i].name) == 0) {
+#ifdef OPENSSL_FIPS
+			if (fips_mode && !macs[i].fips_allowed) {
+				debug2("mac_init: %s disallowed in fips mode", name);
+				return (-1);
+			}
+#endif
 			if (mac != NULL) {
 				mac->md = (*macs[i].mdfunc)();
 				mac->key_len = mac->mac_len = EVP_MD_size(mac->md);
Index: Makefile.in
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/Makefile.in,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- Makefile.in	19 May 2004 13:05:17 -0000	1.1
+++ Makefile.in	24 May 2004 18:54:37 -0000	1.3
@@ -17,6 +17,7 @@
 piddir=@piddir@
 srcdir=@srcdir@
 top_srcdir=@top_srcdir@
+ssldir=@ssldir@
 
 DESTDIR=
 VPATH=@srcdir@
@@ -28,6 +29,7 @@
 PRIVSEP_PATH=@PRIVSEP_PATH@
 SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
 STRIP_OPT=@STRIP_OPT@
+FIPS_MODE=@FIPS_MODE@
 
 PATHS= -DSSHDIR=\"$(sysconfdir)\" \
 	-D_PATH_SSH_PROGRAM=\"$(SSH_PROGRAM)\" \
@@ -133,9 +135,15 @@
 
 ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
 	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
+	if [ ! -z "FIPS_MODE" ]; then \
+		PATH=$(ssldir)/bin:$$PATH $(ssldir)/bin/openssl_fips_fingerprint $(ssldir)/lib/libcrypto.a $@; \
+	fi
 
 sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
 	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS)
+	if [ ! -z "FIPS_MODE" ]; then \
+		PATH=$(ssldir)/bin:$$PATH $(ssldir)/bin/openssl_fips_fingerprint $(ssldir)/lib/libcrypto.a $@; \
+	fi
 
 scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
 	$(LD) -o $@ scp.o progressmeter.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
@@ -246,12 +254,18 @@
 	$(srcdir)/mkinstalldirs $(DESTDIR)$(libexecdir)
 	(umask 022 ; $(srcdir)/mkinstalldirs $(DESTDIR)$(PRIVSEP_PATH))
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh $(DESTDIR)$(bindir)/ssh
+	if [ ! -z "FIPS_MODE" ]; then \
+		$(INSTALL) -m 0755 $(STRIP_OPT) ssh $(DESTDIR)$(bindir)/ssh.sha1; \
+	fi
 	$(INSTALL) -m 0755 $(STRIP_OPT) scp $(DESTDIR)$(bindir)/scp
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh-add $(DESTDIR)$(bindir)/ssh-add
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh-agent $(DESTDIR)$(bindir)/ssh-agent
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh-keygen $(DESTDIR)$(bindir)/ssh-keygen
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh-keyscan $(DESTDIR)$(bindir)/ssh-keyscan
 	$(INSTALL) -m 0755 $(STRIP_OPT) sshd $(DESTDIR)$(sbindir)/sshd
+	if [ ! -z "FIPS_MODE" ]; then \
+		$(INSTALL) -m 0755 $(STRIP_OPT) sshd $(DESTDIR)$(bindir)/sshd.sha1; \
+	fi
 	if test ! -z "$(INSTALL_SSH_RAND_HELPER)" ; then \
 		$(INSTALL) -m 0755 $(STRIP_OPT) ssh-rand-helper $(DESTDIR)$(libexecdir)/ssh-rand-helper ; \
 	fi
Index: myproposal.h
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/myproposal.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- myproposal.h	19 May 2004 12:56:16 -0000	1.1
+++ myproposal.h	24 May 2004 18:54:14 -0000	1.2
@@ -25,14 +25,24 @@
  */
 #define KEX_DEFAULT_KEX		"diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1"
 #define	KEX_DEFAULT_PK_ALG	"ssh-rsa,ssh-dss"
-#define	KEX_DEFAULT_ENCRYPT \
+#ifndef OPENSSL_FIPS
+  #define	KEX_DEFAULT_ENCRYPT \
 	"aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour," \
 	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
 	"aes128-ctr,aes192-ctr,aes256-ctr"
-#define	KEX_DEFAULT_MAC \
+  #define	KEX_DEFAULT_MAC \
 	"hmac-md5,hmac-sha1,hmac-ripemd160," \
 	"hmac-ripemd160@openssh.com," \
 	"hmac-sha1-96,hmac-md5-96"
+#else
+  #define	KEX_DEFAULT_ENCRYPT \
+	"aes128-cbc,3des-cbc," \
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
+	"aes128-ctr,aes192-ctr,aes256-ctr"
+  #define	KEX_DEFAULT_MAC \
+	"hmac-sha1," \
+	"hmac-sha1-96"
+#endif
 #define	KEX_DEFAULT_COMP	"none,zlib"
 #define	KEX_DEFAULT_LANG	""
 
Index: readconf.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/readconf.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- readconf.c	19 May 2004 12:56:18 -0000	1.1
+++ readconf.c	28 May 2004 13:30:30 -0000	1.3
@@ -25,6 +25,7 @@
 #include "misc.h"
 #include "kex.h"
 #include "mac.h"
+#include "fips.h"
 
 /* Format of the configuration file:
 
@@ -938,9 +939,9 @@
 	/* Selected in ssh_login(). */
 	if (options->cipher == -1)
 		options->cipher = SSH_CIPHER_NOT_SET;
-	/* options->ciphers, default set in myproposals.h */
-	/* options->macs, default set in myproposals.h */
-	/* options->hostkeyalgorithms, default set in myproposals.h */
+	/* options->ciphers, default set in myproposal.h */
+	/* options->macs, default set in myproposal.h */
+	/* options->hostkeyalgorithms, default set in myproposal.h */
 	if (options->protocol == SSH_PROTO_UNKNOWN)
 		options->protocol = SSH_PROTO_1|SSH_PROTO_2;
 	if (options->num_identity_files == 0) {
@@ -991,6 +992,8 @@
 		options->server_alive_interval = 0;
 	if (options->server_alive_count_max == -1)
 		options->server_alive_count_max = 3;
+	if (fips_mode && options->macs == NULL)
+		options->macs = "hmac-sha1,hmac-sha1-96";
 	/* options->proxy_command should not be set by default */
 	/* options->user will be set in the main program if appropriate */
 	/* options->hostname will be set in the main program if appropriate */
Index: servconf.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/servconf.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- servconf.c	19 May 2004 12:56:20 -0000	1.1
+++ servconf.c	28 May 2004 13:30:30 -0000	1.3
@@ -23,6 +23,7 @@
 #include "cipher.h"
 #include "kex.h"
 #include "mac.h"
+#include "fips.h"
 
 static void add_listen_addr(ServerOptions *, char *, u_short);
 static void add_one_listen_addr(ServerOptions *, char *, u_short);
@@ -88,7 +89,11 @@
 	options->num_allow_groups = 0;
 	options->num_deny_groups = 0;
 	options->ciphers = NULL;
+#ifdef OPENSSL_FIPS
+	options->macs = "hmac-sha1,hmac-sha1-96";
+#else
 	options->macs = NULL;
+#endif
 	options->protocol = SSH_PROTO_UNKNOWN;
 	options->gateway_ports = -1;
 	options->num_subsystems = 0;
@@ -105,6 +110,15 @@
 	/* Needs to be accessable in many places */
 	use_privsep = -1;
 }
+
+/*
+ * FIPS mode operation indicator
+*/
+#ifdef OPENSSL_FIPS
+fips_mode = 1;
+#else
+fips_mode = 0;
+#endif
 
 void
 fill_default_server_options(ServerOptions *options)
Index: ssh-add.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ssh-add.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- ssh-add.c	19 May 2004 12:56:23 -0000	1.1
+++ ssh-add.c	28 May 2004 16:11:42 -0000	1.3
@@ -49,6 +49,16 @@
 #include "pathnames.h"
 #include "readpass.h"
 #include "misc.h"
+#include "fips.h"
+
+/*
+ * FIPS mode operation
+*/
+#ifdef OPENSSL_FIPS
+	int fips_mode = 1;
+#else
+	int fips_mode = 0;
+#endif
 
 #ifdef HAVE___PROGNAME
 extern char *__progname;
Index: ssh.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ssh.c,v
retrieving revision 1.1
retrieving revision 1.7
diff -u -r1.1 -r1.7
--- ssh.c	19 May 2004 12:56:26 -0000	1.1
+++ ssh.c	3 Jun 2004 13:05:32 -0000	1.7
@@ -44,6 +44,11 @@
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
+#ifdef OPENSSL_FIPS
+#include <openssl/fips.h>
+#include <openssl/rand.h>
+#include <openssl/fips_rand.h>
+#endif
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -68,6 +73,16 @@
 #include "kex.h"
 #include "mac.h"
 #include "sshtty.h"
+#include "fips.h"
+
+/*
+ * FIPS mode operation
+*/
+#ifdef OPENSSL_FIPS
+	int fips_mode = 1;
+#else
+	int fips_mode = 0;
+#endif
 
 #ifdef SMARTCARD
 #include "scard.h"
@@ -173,6 +188,9 @@
 
 	fprintf(stderr, "  -c cipher   Select encryption algorithm\n");
 	fprintf(stderr, "  -m macs     Specify MAC algorithms for protocol version 2.\n");
+#ifdef OPENSSL_FIPS
+	fprintf(stderr, "  -y          Do not enable FIPS mode\n");
+#endif
 	fprintf(stderr, "  -p port     Connect to this port.  Server must be on the same port.\n");
 	fprintf(stderr, "  -L listen-port:host:port   Forward local port to remote address\n");
 	fprintf(stderr, "  -R listen-port:host:port   Forward remote port to local address\n");
@@ -211,7 +229,10 @@
 	int dummy;
 	extern int optind, optreset;
 	extern char *optarg;
+	char *pcmd;
+	unsigned long e;
 
+	pcmd = av[0];
 	__progname = ssh_get_progname(av[0]);
 	init_rng();
 
@@ -264,9 +285,19 @@
 	host = NULL;
 
 again:
+#ifdef OPENSSL_FIPS
+# define FIPS_OPTS "y"
+#else
+# define FIPS_OPTS
+#endif
 	while ((opt = getopt(ac, av,
-	    "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:F:I:L:NPR:TVXY")) != -1) {
+	    "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:F:I:L:NPR:TVXY" FIPS_OPTS)) != -1) {
 		switch (opt) {
+#ifdef OPENSSL_FIPS
+		case 'y':
+			fips_mode = 0;
+			break;
+#endif
 		case '1':
 			options.protocol = SSH_PROTO_1;
 			break;
@@ -509,6 +540,21 @@
 	if (!host)
 		usage();
 
+	seed_rng();
+#ifdef OPENSSL_FIPS
+	if(fips_mode) {
+		if(!FIPS_mode_set(1,pcmd)) {
+			ERR_load_crypto_strings();
+			while((e = ERR_get_error()))
+				logit(ERR_error_string(e,NULL));
+			fatal("Failed to enter FIPS mode.");
+		} else if(!no_tty_flag) {
+			logit("FIPS-140 compliance mode enabled");
+		} else {
+			debug("FIPS-140 compliance mode enabled");
+		}
+	}
+#endif
 	SSLeay_add_all_algorithms();
 	ERR_load_crypto_strings();
 
@@ -587,7 +633,8 @@
 	/* reinit */
 	log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 1);
 
-	seed_rng();
+	/* Moved before FIPS_mode_set()
+	seed_rng();*/
 
 	if (options.user == NULL)
 		options.user = xstrdup(pw->pw_name);
Index: sshd.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/sshd.c,v
retrieving revision 1.1
retrieving revision 1.7
diff -u -r1.1 -r1.7
--- sshd.c	19 May 2004 12:56:29 -0000	1.1
+++ sshd.c	3 Jun 2004 13:05:32 -0000	1.7
@@ -48,6 +48,11 @@
 #include <openssl/bn.h>
 #include <openssl/md5.h>
 #include <openssl/rand.h>
+#ifdef OPENSSL_FIPS
+#include <openssl/fips.h>
+#include <openssl/rand.h>
+#include <openssl/fips_rand.h>
+#endif
 #ifdef HAVE_SECUREWARE
 #include <sys/security.h>
 #include <prot.h>
@@ -374,7 +379,11 @@
 		major = PROTOCOL_MAJOR_1;
 		minor = PROTOCOL_MINOR_1;
 	}
+#ifndef OPENSSL_FIPS
 	snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_VERSION);
+#else
+	snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s FIPS\n", major, minor, SSH_VERSION);
+#endif
 	server_version_string = xstrdup(buf);
 
 	/* Send our protocol version identification. */
@@ -546,7 +555,14 @@
 
 	for (i = 0; i < 256; i++)
 		rnd[i] = arc4random();
+#ifndef OPENSSL_FIPS
 	RAND_seed(rnd, sizeof(rnd));
+#else
+	FIPS_set_prng_key(rnd,rnd+8);
+	FIPS_rand_seed(rnd+16,8);
+	debug2("FIPS rand reseeded");
+#endif
+
 
 	/* Demote the private keys to public keys. */
 	demote_sensitive_data();
@@ -812,6 +828,7 @@
 	Key *key;
 	Authctxt *authctxt;
 	int ret, key_used = 0;
+	unsigned long e;
 
 #ifdef HAVE_SECUREWARE
 	(void)set_auth_parameters(ac, av);
@@ -948,6 +965,17 @@
 #endif
 
 	seed_rng();
+
+#ifdef OPENSSL_FIPS
+	if(!FIPS_mode_set(1,saved_argv[0])) {
+		ERR_load_crypto_strings();
+		while((e = ERR_get_error()))
+			logit(ERR_error_string(e,NULL));
+		fatal("Failed to enter FIPS mode.");
+	} else {
+		logit("FIPS-140 compliance mode enabled");
+	}
+#endif
 
 	/* Read server configuration options from the configuration file. */
 	read_server_config(&options, config_file_name);
Index: ssh-keygen.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ssh-keygen.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- ssh-keygen.c	19 May 2004 12:56:24 -0000	1.1
+++ ssh-keygen.c	28 May 2004 16:11:42 -0000	1.3
@@ -28,6 +28,16 @@
 #include "log.h"
 #include "readpass.h"
 #include "moduli.h"
+#include "fips.h"
+
+/*
+ * FIPS mode operation
+*/
+#ifdef OPENSSL_FIPS
+	int fips_mode = 1;
+#else
+	int fips_mode = 0;
+#endif
 
 #ifdef SMARTCARD
 #include "scard.h"
Index: ssh-keyscan.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ssh-keyscan.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ssh-keyscan.c	19 May 2004 12:56:25 -0000	1.1
+++ ssh-keyscan.c	28 May 2004 13:30:30 -0000	1.2
@@ -28,6 +28,16 @@
 #include "log.h"
 #include "atomicio.h"
 #include "misc.h"
+#include "fips.h"
+
+/*
+ * FIPS mode operation
+*/
+#ifdef OPENSSL_FIPS
+	fips_mode = 1;
+#else
+	fips_mode = 0;
+#endif
 
 /* Flag indicating whether IPv4 or IPv6.  This can be set on the command line.
    Default value is AF_UNSPEC means both IPv4 and IPv6. */
Index: ssh-keysign.c
===================================================================
RCS file: /work/dev/sys/techinf/FIPS-140/OpenSSH/openssh-3.8p1/ssh-keysign.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -u -r1.1 -r1.3
--- ssh-keysign.c	19 May 2004 12:56:25 -0000	1.1
+++ ssh-keysign.c	28 May 2004 16:11:42 -0000	1.3
@@ -41,6 +41,16 @@
 #include "canohost.h"
 #include "pathnames.h"
 #include "readconf.h"
+#include "fips.h"
+
+/*
+ * FIPS operational mode
+*/
+#ifdef OPENSSL_FIPS
+	int fips_mode = 1;
+#else
+	int fips_mode = 0;
+#endif
 
 /* XXX readconf.c needs these */
 uid_t original_real_uid;
--- /dev/null	2003-01-30 05:24:37.000000000 -0500
+++ fips.h	2004-05-26 08:37:23.000000000 -0400
@@ -0,0 +1,3 @@
+/* $OpenBSD: version.h,v 1.40 2004/02/23 15:16:46 markus Exp $ */
+
+extern int fips_mode;
