remove OPENSSL_FIPSAPI
[openssl.git] / crypto / bn / bn_lib.c
index 72da0735fd83ada70265c1dac87fba13fd931321..0305a19e3dcad6ea006902e0bc7536139ebdee13 100644 (file)
 # define NDEBUG
 #endif
 
-#define OPENSSL_FIPSAPI
+
 
 #include <assert.h>
 #include <limits.h>
-#include <stdio.h>
 #include "cryptlib.h"
 #include "bn_lcl.h"
 
-__fips_constseg
 const char BN_version[]="Big Number" OPENSSL_VERSION_PTEXT;
 
 /* This stuff appears to be completely unused, so is deprecated */
@@ -144,7 +142,6 @@ const BIGNUM *BN_value_one(void)
 
 int BN_num_bits_word(BN_ULONG l)
        {
-       __fips_constseg
        static const unsigned char bits[256]={
                0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
                5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
@@ -324,6 +321,15 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
                BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
+#ifdef PURIFY
+       /* Valgrind complains in BN_consttime_swap because we process the whole
+        * array even if it's not initialised yet. This doesn't matter in that
+        * function - what's important is constant time operation (we're not
+        * actually going to use the data)
+       */
+       memset(a, 0, sizeof(BN_ULONG)*words);
+#endif
+
 #if 1
        B=b->d;
        /* Check if the previous number needs to be copied */
@@ -880,3 +886,28 @@ void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
        }
 #undef BN_CONSTTIME_SWAP
 }
+
+/* Bits of security, see SP800-57 */
+
+int BN_security_bits(int L, int N)
+       {
+       int secbits, bits;
+       if (L >= 15360)
+               secbits = 256;
+       else if (L >= 7690)
+               secbits = 192;
+       else if (L >= 3072)
+               secbits = 128;
+       else if (L >= 2048)
+               secbits = 112;
+       else if (L >= 1024)
+               secbits = 80;
+       else
+               return 0;
+       if (N == -1)
+               return secbits;
+       bits = N / 2;
+       if (bits < 80)
+               return 0;
+       return bits >= secbits ? secbits : bits;
+       }