This is a revert of my previous commit to "improve" the declaration of
authorGeoff Thorpe <geoff@openssl.org>
Wed, 5 Nov 2003 19:30:29 +0000 (19:30 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Wed, 5 Nov 2003 19:30:29 +0000 (19:30 +0000)
constant BIGNUMs. It turns out that this trips up different but equally
useful compiler warnings to -Wcast-qual, and so wasn't worth the ugliness
it created. (Thanks to Ulf for the forehead-slap.)

crypto/bn/bn.h
crypto/bn/bn_lib.c
crypto/bn/bn_nist.c

index 5c648ea01154e72d051e7163a3ca56e049edef2a..a46fe842cfdfabb59874119a4d0e3f5087aca5e8 100644 (file)
@@ -252,27 +252,6 @@ typedef struct bignum_st
        int flags;
        } BIGNUM;
 
-/* Declaring static BIGNUMs as constant is tricky in C; the 'd' data can't be
- * pre-declared const without having to cast away the const when declaring the
- * BIGNUM. We use this alternative type for declaring const BIGNUMs. See
- * bn_nist.c for examples. */
-typedef struct bignum_c_st
-       {
-       const BN_ULONG *d;
-       int top;
-       int dmax;
-       int neg;
-       int flags;
-       } BIGNUM_C;
-#ifdef BN_DEBUG
-/* Use a function to do this so that we can type-check the pointer we're
- * casting */
-const BIGNUM *BIGNUM_CONST(const BIGNUM_C *bn);
-#else
-/* Use a macro instead */
-#define BIGNUM_CONST(bn)       ((const BIGNUM *)bn)
-#endif
-
 /* Used for temp variables (declaration hidden in bn_lcl.h) */
 typedef struct bignum_ctx BN_CTX;
 
index 85b72e0eebf568951d1cdb7fbeb6d217aa762753..1f45b09d080b6c86593c5fe304a57d42ccccfc0c 100644 (file)
@@ -887,11 +887,3 @@ int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
                }
        return bn_cmp_words(a,b,cl);
        }
-
-/* See the comments surrounding BIGNUM_C in bn.h */
-#ifdef BN_DEBUG
-const BIGNUM *BIGNUM_CONST(const BIGNUM_C *bn)
-       {
-       return (const BIGNUM *)bn;
-       }
-#endif
index 79f7c2ef2867ef12822894b275d27c53d3704008..6aa196f6f86959ede237f1bb07be558daebfacbf 100644 (file)
@@ -127,40 +127,39 @@ const static BN_ULONG _nist_p_521[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
        0xFF,0x01};
 #endif
 
-static const BIGNUM_C bn_nist_p_192 =
-       { _nist_p_192, BN_NIST_192_TOP, BN_NIST_192_TOP, 0, BN_FLG_STATIC_DATA };
-static const BIGNUM_C bn_nist_p_224 =
-       { _nist_p_224, BN_NIST_224_TOP, BN_NIST_224_TOP, 0, BN_FLG_STATIC_DATA };
-static const BIGNUM_C bn_nist_p_256 =
-       { _nist_p_256, BN_NIST_256_TOP, BN_NIST_256_TOP, 0, BN_FLG_STATIC_DATA };
-static const BIGNUM_C bn_nist_p_384 =
-       { _nist_p_384, BN_NIST_384_TOP, BN_NIST_384_TOP, 0, BN_FLG_STATIC_DATA };
-static const BIGNUM_C bn_nist_p_521 =
-       { _nist_p_521, BN_NIST_521_TOP, BN_NIST_521_TOP, 0, BN_FLG_STATIC_DATA };
-
 const BIGNUM *BN_get0_nist_prime_192(void)
        {
-       return BIGNUM_CONST(&bn_nist_p_192);
+       static BIGNUM const_nist_192 = { (BN_ULONG *)_nist_p_192,
+               BN_NIST_192_TOP, BN_NIST_192_TOP, 0, BN_FLG_STATIC_DATA };
+       return &const_nist_192;
        }
 
 const BIGNUM *BN_get0_nist_prime_224(void)
        {
-       return BIGNUM_CONST(&bn_nist_p_224);
+       static BIGNUM const_nist_224 = { (BN_ULONG *)_nist_p_224,
+               BN_NIST_224_TOP, BN_NIST_224_TOP, 0, BN_FLG_STATIC_DATA };
+       return &const_nist_224;
        }
 
 const BIGNUM *BN_get0_nist_prime_256(void)
        {
-       return BIGNUM_CONST(&bn_nist_p_256);
+       static BIGNUM const_nist_256 = { (BN_ULONG *)_nist_p_256,
+               BN_NIST_256_TOP, BN_NIST_256_TOP, 0, BN_FLG_STATIC_DATA };
+       return &const_nist_256;
        }
 
 const BIGNUM *BN_get0_nist_prime_384(void)
        {
-       return BIGNUM_CONST(&bn_nist_p_384);
+       static BIGNUM const_nist_384 = { (BN_ULONG *)_nist_p_384,
+               BN_NIST_384_TOP, BN_NIST_384_TOP, 0, BN_FLG_STATIC_DATA };
+       return &const_nist_384;
        }
 
 const BIGNUM *BN_get0_nist_prime_521(void)
        {
-       return BIGNUM_CONST(&bn_nist_p_521);
+       static BIGNUM const_nist_521 = { (BN_ULONG *)_nist_p_521,
+               BN_NIST_521_TOP, BN_NIST_521_TOP, 0, BN_FLG_STATIC_DATA };
+       return &const_nist_521;
        }
 
 /* some misc internal functions */