6 int bn_mull(BIGNUM *r,BIGNUM *a,BIGNUM *b, BN_CTX *ctx);
8 int bn_mull(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
14 printf("bn_mull %d * %d\n",a->top,b->top);
27 if ((al < 4) || (bl < 4))
29 if (bn_wexpand(r,top) == NULL) return(0);
31 bn_mul_normal(r->d,a->d,al,b->d,bl);
34 else if (al == bl) /* A good start, they are the same size */
39 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
46 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
55 /* asymetric and >= 4 */
56 if (bn_wexpand(r,top) == NULL) return(0);
58 bn_mul_normal(r->d,a->d,al,b->d,bl);
62 /* symetric and > 4 */
66 if (bn_wexpand(r,al*2) == NULL) return(0);
68 bn_mul_comba4(r->d,a->d,b->d);
73 if (bn_wexpand(r,al*2) == NULL) return(0);
75 bn_mul_comba8(r->d,a->d,b->d);
78 if (al <= BN_MULL_NORMAL_SIZE)
80 if (bn_wexpand(r,al*2) == NULL) return(0);
82 bn_mul_normal(r->d,a->d,al,b->d,bl);
86 j=BN_num_bits_word((BN_ULONG)al);
90 if (al == j) /* exact multiple */
94 bn_mul_recursive(r->d,a->d,b->d,al,t->d);
102 for (i=a->top; i<k; i++)
104 for (i=b->top; i<k; i++)
106 bn_mul_part_recursive(r->d,a->d,b->d,al-j,j,t->d);
117 void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
122 printf(" bn_mul_normal %d * %d\n",na,nb);
130 itmp=na; na=nb; nb=itmp;
135 rr[0]=bn_mul_words(r,a,na,b[0]);
139 if (--nb <= 0) return;
140 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
141 if (--nb <= 0) return;
142 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
143 if (--nb <= 0) return;
144 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
145 if (--nb <= 0) return;
146 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
154 void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
157 printf(" bn_mul_low_normal %d * %d\n",n,n);
159 bn_mul_words(r,a,n,b[0]);
163 if (--n <= 0) return;
164 bn_mul_add_words(&(r[1]),a,n,b[1]);
165 if (--n <= 0) return;
166 bn_mul_add_words(&(r[2]),a,n,b[2]);
167 if (--n <= 0) return;
168 bn_mul_add_words(&(r[3]),a,n,b[3]);
169 if (--n <= 0) return;
170 bn_mul_add_words(&(r[4]),a,n,b[4]);