This is the least unacceptable way I've found for declaring the bignum data
[openssl.git] / crypto / bn / bn.h
index 686b3b3079fcb5231397d096bebf5f2ad24cc1ff..44ba175247b0bd2ea181ce0e22001de1e6aa7d47 100644 (file)
@@ -252,6 +252,27 @@ 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;