* n2 must be a power of 2.
* We multiply and return the result.
* t must be 2*n2 words in size
- * We calulate
+ * We calculate
* a[0]*b[0]
* a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
* a[1]*b[1]
}
top=al+bl;
+ BN_CTX_start(ctx);
if ((r == a) || (r == b))
- rr= &(ctx->bn[ctx->tos+1]);
+ {
+ if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
+ }
else
- rr=r;
+ rr = r;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
if (al == bl)
# ifdef BN_MUL_COMBA
/* if (al == 4)
{
- if (bn_wexpand(rr,8) == NULL) return(0);
+ if (bn_wexpand(rr,8) == NULL) goto err;
rr->top=8;
bn_mul_comba4(rr->d,a->d,b->d);
goto end;
}
else */ if (al == 8)
{
- if (bn_wexpand(rr,16) == NULL) return(0);
+ if (bn_wexpand(rr,16) == NULL) goto err;
rr->top=16;
bn_mul_comba8(rr->d,a->d,b->d);
goto end;
if (al < BN_MULL_SIZE_NORMAL)
#endif
{
- if (bn_wexpand(rr,top) == NULL) return(0);
+ if (bn_wexpand(rr,top) == NULL) goto err;
rr->top=top;
bn_mul_normal(rr->d,a->d,al,b->d,bl);
goto end;
}
# ifdef BN_RECURSION
- goto symetric;
+ goto symmetric;
# endif
}
#endif
#ifdef BN_RECURSION
else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))
{
- if (bn_wexpand(rr,top) == NULL) return(0);
+ if (bn_wexpand(rr,top) == NULL) goto err;
rr->top=top;
bn_mul_normal(rr->d,a->d,al,b->d,bl);
goto end;
bn_wexpand(b,al);
b->d[bl]=0;
bl++;
- goto symetric;
+ goto symmetric;
}
else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
{
bn_wexpand(a,bl);
a->d[al]=0;
al++;
- goto symetric;
+ goto symmetric;
}
}
#endif
- /* asymetric and >= 4 */
- if (bn_wexpand(rr,top) == NULL) return(0);
+ /* asymmetric and >= 4 */
+ if (bn_wexpand(rr,top) == NULL) goto err;
rr->top=top;
bn_mul_normal(rr->d,a->d,al,b->d,bl);
#ifdef BN_RECURSION
if (0)
{
-symetric:
- /* symetric and > 4 */
+symmetric:
+ /* symmetric and > 4 */
/* 16 or larger */
j=BN_num_bits_word((BN_ULONG)al);
j=1<<(j-1);
k=j+j;
- t= &(ctx->bn[ctx->tos]);
+ t = BN_CTX_get(ctx);
if (al == j) /* exact multiple */
{
bn_wexpand(t,k*2);
#endif
bn_fix_top(rr);
if (r != rr) BN_copy(r,rr);
+ BN_CTX_end(ctx);
return(1);
+err:
+ BN_CTX_end(ctx);
+ return(0);
}
void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)