#endif
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include "cryptlib.h"
#include "bn_lcl.h"
else return(0);
}
-BIGNUM *BN_value_one(void)
+const BIGNUM *BN_value_one(void)
{
static BN_ULONG data_one=1L;
static BIGNUM const_one={&data_one,1,1,0};
const BN_ULONG *B;
int i;
+ if (words > (INT_MAX/(4*BN_BITS2)))
+ {
+ BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_BIGNUM_TOO_LONG);
+ return NULL;
+ }
+
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
}
}
- /* Now need to zero any data between b->top and b->max */
- /* XXX Why? */
-
- A= &(a[b->top]);
- for (i=(words - b->top)>>3; i>0; i--,A+=8)
- {
- A[0]=0; A[1]=0; A[2]=0; A[3]=0;
- A[4]=0; A[5]=0; A[6]=0; A[7]=0;
- }
- for (i=(words - b->top)&7; i>0; i--,A++)
- A[0]=0;
#else
memset(A,0,sizeof(BN_ULONG)*(words+1));
memcpy(A,b->d,sizeof(b->d[0])*b->top);
{
BIGNUM *r = NULL;
+ /* This function does not work if
+ * words <= b->dmax && top < words
+ * because BN_dup() does not preserve 'dmax'!
+ * (But bn_dup_expand() is not used anywhere yet.)
+ */
+
if (words > b->dmax)
{
BN_ULONG *a = bn_expand_internal(b, words);
}
/* This is an internal function that should not be used in applications.
- * It ensures that 'b' has enough room for a 'words' word number number.
+ * It ensures that 'b' has enough room for a 'words' word number
+ * and initialises the unused part of b->d with leading zeros.
* It is mostly used by the various BIGNUM routines. If there is an error,
* NULL is returned. If not, 'b' is returned. */
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
+ BN_ULONG *A;
+ int i;
+
if (words > b->dmax)
{
BN_ULONG *a = bn_expand_internal(b, words);
else
b = NULL;
}
+
+ /* NB: bn_wexpand() calls this only if the BIGNUM really has to grow */
+ A = &(b->d[b->top]);
+ for (i=(words - b->top)>>3; i>0; i--,A+=8)
+ {
+ A[0]=0; A[1]=0; A[2]=0; A[3]=0;
+ A[4]=0; A[5]=0; A[6]=0; A[7]=0;
+ }
+ for (i=(words - b->top)&7; i>0; i--,A++)
+ A[0]=0;
+
return b;
}