12a6020
diff -up gnutls-2.12.21/lib/gcrypt/init.c.fips gnutls-2.12.21/lib/gcrypt/init.c
12a6020
--- gnutls-2.12.21/lib/gcrypt/init.c.fips	2012-01-06 20:06:23.000000000 +0100
12a6020
+++ gnutls-2.12.21/lib/gcrypt/init.c	2012-11-09 19:57:54.651624659 +0100
b89d89d
@@ -43,6 +43,8 @@ static struct gcry_thread_cbs gct = {
b89d89d
   .recvmsg = NULL,
b89d89d
 };
b89d89d
 
b89d89d
+int gnutls_gcrypt_fips;
b89d89d
+
b89d89d
 int
b89d89d
 gnutls_crypto_init (void)
b89d89d
 {
b89d89d
@@ -72,6 +74,8 @@ gnutls_crypto_init (void)
b89d89d
           return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY;
b89d89d
         }
b89d89d
 
b89d89d
+      gnutls_gcrypt_fips = gcry_fips_mode_active();
b89d89d
+
b89d89d
       /* for gcrypt in order to be able to allocate memory */
b89d89d
       gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0);
b89d89d
 
12a6020
diff -up gnutls-2.12.21/lib/gnutls_algorithms.c.fips gnutls-2.12.21/lib/gnutls_algorithms.c
12a6020
--- gnutls-2.12.21/lib/gnutls_algorithms.c.fips	2012-01-06 20:06:23.000000000 +0100
12a6020
+++ gnutls-2.12.21/lib/gnutls_algorithms.c	2012-11-28 14:19:34.507948036 +0100
12a6020
@@ -44,11 +44,11 @@ typedef struct
12a6020
 } gnutls_sec_params_entry;
12a6020
 
12a6020
 static const gnutls_sec_params_entry sec_params[] = {
12a6020
-  {"Weak", GNUTLS_SEC_PARAM_WEAK, 64, 816, 1024, 128, 128},
12a6020
-  {"Low", GNUTLS_SEC_PARAM_LOW, 80, 1248, 2048, 160, 160},
12a6020
-  {"Normal", GNUTLS_SEC_PARAM_NORMAL, 112, 2432, 3072, 224, 224},
12a6020
-  {"High", GNUTLS_SEC_PARAM_HIGH, 128, 3248, 3072, 256, 256},
12a6020
-  {"Ultra", GNUTLS_SEC_PARAM_ULTRA, 256, 15424, 3072, 512, 512},
12a6020
+  {"Weak", GNUTLS_SEC_PARAM_WEAK, 64, 1024, 1024, 128, 128},
12a6020
+  {"Low", GNUTLS_SEC_PARAM_LOW, 80, 1280, 2048, 160, 160},
12a6020
+  {"Normal", GNUTLS_SEC_PARAM_NORMAL, 112, 2560, 3072, 224, 224},
12a6020
+  {"High", GNUTLS_SEC_PARAM_HIGH, 128, 3328, 3072, 256, 256},
12a6020
+  {"Ultra", GNUTLS_SEC_PARAM_ULTRA, 256, 15616, 3072, 512, 512},
12a6020
   {NULL, 0, 0, 0, 0, 0}
12a6020
 };
12a6020
 
12a6020
diff -up gnutls-2.12.21/lib/gnutls_priority.c.fips gnutls-2.12.21/lib/gnutls_priority.c
12a6020
--- gnutls-2.12.21/lib/gnutls_priority.c.fips	2012-11-08 17:11:11.000000000 +0100
12a6020
+++ gnutls-2.12.21/lib/gnutls_priority.c	2012-11-09 19:57:54.651624659 +0100
b89d89d
@@ -30,6 +30,7 @@
b89d89d
 #include "gnutls_algorithms.h"
b89d89d
 #include "gnutls_errors.h"
b89d89d
 #include <gnutls_num.h>
b89d89d
+#include <gcrypt.h>
b89d89d
 
b89d89d
 static void
b89d89d
 break_comma_list (char *etag,
b89d89d
@@ -223,6 +224,13 @@ static const int protocol_priority[] = {
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int protocol_priority_fips[] = {
b89d89d
+  GNUTLS_TLS1_2,
b89d89d
+  GNUTLS_TLS1_1,
b89d89d
+  GNUTLS_TLS1_0,
b89d89d
+  0
b89d89d
+};
b89d89d
+
b89d89d
 static const int kx_priority_performance[] = {
b89d89d
   GNUTLS_KX_RSA,
b89d89d
   GNUTLS_KX_DHE_RSA,
b89d89d
@@ -269,6 +277,13 @@ static const int cipher_priority_perform
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int cipher_priority_performance_fips[] = {
b89d89d
+  GNUTLS_CIPHER_AES_128_CBC,
b89d89d
+  GNUTLS_CIPHER_3DES_CBC,
b89d89d
+  GNUTLS_CIPHER_AES_256_CBC,
b89d89d
+  0
b89d89d
+};
b89d89d
+
b89d89d
 static const int cipher_priority_normal[] = {
b89d89d
   GNUTLS_CIPHER_AES_128_CBC,
b89d89d
 #ifdef	ENABLE_CAMELLIA
b89d89d
@@ -284,6 +299,13 @@ static const int cipher_priority_normal[
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int cipher_priority_normal_fips[] = {
b89d89d
+  GNUTLS_CIPHER_AES_128_CBC,
b89d89d
+  GNUTLS_CIPHER_AES_256_CBC,
b89d89d
+  GNUTLS_CIPHER_3DES_CBC,
b89d89d
+  0
b89d89d
+};
b89d89d
+
b89d89d
 static const int cipher_priority_secure128[] = {
b89d89d
   GNUTLS_CIPHER_AES_128_CBC,
b89d89d
 #ifdef	ENABLE_CAMELLIA
b89d89d
@@ -295,6 +317,11 @@ static const int cipher_priority_secure1
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int cipher_priority_secure128_fips[] = {
b89d89d
+  GNUTLS_CIPHER_AES_128_CBC,
b89d89d
+  GNUTLS_CIPHER_3DES_CBC,
b89d89d
+  0
b89d89d
+};
b89d89d
 
b89d89d
 static const int cipher_priority_secure256[] = {
b89d89d
   GNUTLS_CIPHER_AES_256_CBC,
b89d89d
@@ -311,6 +338,13 @@ static const int cipher_priority_secure2
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int cipher_priority_secure256_fips[] = {
b89d89d
+  GNUTLS_CIPHER_AES_256_CBC,
b89d89d
+  GNUTLS_CIPHER_AES_128_CBC,
b89d89d
+  GNUTLS_CIPHER_3DES_CBC,
b89d89d
+  0
b89d89d
+};
b89d89d
+
b89d89d
 /* The same as cipher_priority_security_normal + arcfour-40. */
b89d89d
 static const int cipher_priority_export[] = {
b89d89d
   GNUTLS_CIPHER_AES_128_CBC,
b89d89d
@@ -362,6 +396,12 @@ static const int mac_priority_normal[] =
b89d89d
   0
b89d89d
 };
b89d89d
 
b89d89d
+static const int mac_priority_normal_fips[] = {
b89d89d
+  GNUTLS_MAC_SHA1,
b89d89d
+  GNUTLS_MAC_SHA256,
b89d89d
+  0
b89d89d
+};
b89d89d
+
b89d89d
 
b89d89d
 static const int mac_priority_secure[] = {
b89d89d
   GNUTLS_MAC_SHA256,
b89d89d
@@ -462,6 +502,8 @@ gnutls_priority_set (gnutls_session_t se
b89d89d
 
b89d89d
 #define MAX_ELEMENTS 48
b89d89d
 
b89d89d
+extern int gnutls_gcrypt_fips;
b89d89d
+
b89d89d
 /**
b89d89d
  * gnutls_priority_init:
b89d89d
  * @priority_cache: is a #gnutls_prioritity_t structure.
b89d89d
@@ -561,7 +603,7 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
    */
b89d89d
   if (strcasecmp (broken_list[0], "NONE") != 0)
b89d89d
     {
b89d89d
-      _set_priority (&(*priority_cache)->protocol, protocol_priority);
b89d89d
+      _set_priority (&(*priority_cache)->protocol, gnutls_gcrypt_fips?protocol_priority_fips:protocol_priority);
b89d89d
       _set_priority (&(*priority_cache)->compression, comp_priority);
b89d89d
       _set_priority (&(*priority_cache)->cert_type, cert_type_priority_default);
b89d89d
       _set_priority (&(*priority_cache)->sign_algo, sign_priority_default);
b89d89d
@@ -577,17 +619,17 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
       if (strcasecmp (broken_list[i], "PERFORMANCE") == 0)
b89d89d
         {
b89d89d
           _set_priority (&(*priority_cache)->cipher,
b89d89d
-                         cipher_priority_performance);
b89d89d
+                         gnutls_gcrypt_fips?cipher_priority_performance_fips:cipher_priority_performance);
b89d89d
           _set_priority (&(*priority_cache)->kx, kx_priority_performance);
b89d89d
-          _set_priority (&(*priority_cache)->mac, mac_priority_normal);
b89d89d
+          _set_priority (&(*priority_cache)->mac, gnutls_gcrypt_fips?mac_priority_normal_fips:mac_priority_normal);
b89d89d
           _set_priority (&(*priority_cache)->sign_algo,
b89d89d
                          sign_priority_default);
b89d89d
         }
b89d89d
       else if (strcasecmp (broken_list[i], "NORMAL") == 0)
b89d89d
         {
b89d89d
-          _set_priority (&(*priority_cache)->cipher, cipher_priority_normal);
b89d89d
+          _set_priority (&(*priority_cache)->cipher, gnutls_gcrypt_fips?cipher_priority_normal_fips:cipher_priority_normal);
b89d89d
           _set_priority (&(*priority_cache)->kx, kx_priority_secure);
b89d89d
-          _set_priority (&(*priority_cache)->mac, mac_priority_normal);
b89d89d
+          _set_priority (&(*priority_cache)->mac, gnutls_gcrypt_fips?mac_priority_normal_fips:mac_priority_normal);
b89d89d
           _set_priority (&(*priority_cache)->sign_algo,
b89d89d
                          sign_priority_default);
b89d89d
         }
b89d89d
@@ -595,7 +637,7 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
                || strcasecmp (broken_list[i], "SECURE") == 0)
b89d89d
         {
b89d89d
           _set_priority (&(*priority_cache)->cipher,
b89d89d
-                         cipher_priority_secure256);
b89d89d
+                         gnutls_gcrypt_fips?cipher_priority_secure256_fips:cipher_priority_secure256);
b89d89d
           _set_priority (&(*priority_cache)->kx, kx_priority_secure);
b89d89d
           _set_priority (&(*priority_cache)->mac, mac_priority_secure);
b89d89d
           _set_priority (&(*priority_cache)->sign_algo,
b89d89d
@@ -604,7 +646,7 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
       else if (strcasecmp (broken_list[i], "SECURE128") == 0)
b89d89d
         {
b89d89d
           _set_priority (&(*priority_cache)->cipher,
b89d89d
-                         cipher_priority_secure128);
b89d89d
+                         gnutls_gcrypt_fips?cipher_priority_secure128_fips:cipher_priority_secure128);
b89d89d
           _set_priority (&(*priority_cache)->kx, kx_priority_secure);
b89d89d
           _set_priority (&(*priority_cache)->mac, mac_priority_secure);
b89d89d
           _set_priority (&(*priority_cache)->sign_algo,
b89d89d
@@ -646,7 +688,7 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
               if (strncasecmp (&broken_list[i][1], "VERS-TLS-ALL", 12) == 0)
b89d89d
                 {
b89d89d
                   bulk_fn (&(*priority_cache)->protocol,
b89d89d
-                                 protocol_priority);
b89d89d
+                                 gnutls_gcrypt_fips?protocol_priority_fips:protocol_priority);
b89d89d
                 }
b89d89d
               else
b89d89d
                 {
b89d89d
@@ -718,7 +760,7 @@ gnutls_priority_init (gnutls_priority_t
b89d89d
           else if (strncasecmp (&broken_list[i][1], "CIPHER-ALL", 7) == 0)
b89d89d
             {
b89d89d
                   bulk_fn (&(*priority_cache)->cipher,
b89d89d
-                                cipher_priority_normal);
b89d89d
+                                gnutls_gcrypt_fips?cipher_priority_normal_fips:cipher_priority_normal);
b89d89d
             }
b89d89d
           else
b89d89d
             goto error;