#include <limits.h>
#include "internal/cryptlib.h"
#include "bn_lcl.h"
+#include <openssl/opensslconf.h>
/* This stuff appears to be completely unused, so is deprecated */
-#ifndef OPENSSL_NO_DEPRECATED
+#if OPENSSL_API_COMPAT < 0x00908000L
/*-
* For a 32 bit machine
* 2 - 4 == 128
if (a->flags & BN_FLG_MALLOCED)
OPENSSL_free(a);
else {
-#ifndef OPENSSL_NO_DEPRECATED
+#if OPENSSL_API_COMPAT < 0x00908000L
a->flags |= BN_FLG_FREE;
#endif
a->d = NULL;
}
}
-void BN_init(BIGNUM *a)
+void bn_init(BIGNUM *a)
{
- memset(a, 0, sizeof(*a));
+ static BIGNUM nilbn;
+
+ *a = nilbn;
bn_check_top(a);
}
{
BIGNUM *ret;
- if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
+ if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
ret->flags = BN_FLG_MALLOCED;
- ret->top = 0;
- ret->neg = 0;
- ret->dmax = 0;
- ret->d = NULL;
bn_check_top(ret);
return (ret);
}
BIGNUM *BN_secure_new(void)
{
BIGNUM *ret = BN_new();
- if (ret)
+ if (ret != NULL)
ret->flags |= BN_FLG_SECURE;
return (ret);
}
-/* This is used both by bn_expand2() and bn_dup_expand() */
+/* This is used by bn_expand2() */
/* The caller MUST check that words > b->dmax before calling this */
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
return (NULL);
bn_check_top(ret);
/* Skip leading zero's. */
- for ( ; *s == 0 && len > 0; s++, len--)
+ for ( ; len > 0 && *s == 0; s++, len--)
continue;
n = len;
if (n == 0) {
return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);
}
-void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int n)
+void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)
{
dest->d = b->d;
dest->top = b->top;
dest->neg = b->neg;
dest->flags = ((dest->flags & BN_FLG_MALLOCED)
| (b->flags & ~BN_FLG_MALLOCED)
- | BN_FLG_STATIC_DATA | n);
+ | BN_FLG_STATIC_DATA | flags);
}
BN_GENCB *BN_GENCB_new(void)