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);
26 if ((al < 4) || (bl < 4))
28 if (bn_wexpand(r,top) == NULL) return(0);
30 bn_mul_normal(r->d,a->d,al,b->d,bl);
33 else if (al == bl) /* A good start, they are the same size */
38 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
45 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
54 /* asymetric and >= 4 */
55 if (bn_wexpand(r,top) == NULL) return(0);
57 bn_mul_normal(r->d,a->d,al,b->d,bl);
61 /* symetric and > 4 */
65 if (bn_wexpand(r,al*2) == NULL) return(0);
67 bn_mul_comba4(r->d,a->d,b->d);
72 if (bn_wexpand(r,al*2) == NULL) return(0);
74 bn_mul_comba8(r->d,a->d,b->d);
77 if (al <= BN_MULL_NORMAL_SIZE)
79 if (bn_wexpand(r,al*2) == NULL) return(0);
81 bn_mul_normal(r->d,a->d,al,b->d,bl);
85 j=BN_num_bits_word((BN_ULONG)al);
88 t= &(ctx->bn[ctx->tos]);
89 if (al == j) /* exact multiple */
93 bn_mul_recursive(r->d,a->d,b->d,al,t->d);
101 for (i=a->top; i<k; i++)
103 for (i=b->top; i<k; i++)
105 bn_mul_part_recursive(r->d,a->d,b->d,al-j,j,t->d);
115 void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
120 printf(" bn_mul_normal %d * %d\n",na,nb);
128 itmp=na; na=nb; nb=itmp;
133 rr[0]=bn_mul_words(r,a,na,b[0]);
137 if (--nb <= 0) return;
138 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
139 if (--nb <= 0) return;
140 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
141 if (--nb <= 0) return;
142 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
143 if (--nb <= 0) return;
144 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
152 void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
155 printf(" bn_mul_low_normal %d * %d\n",n,n);
157 bn_mul_words(r,a,n,b[0]);
161 if (--n <= 0) return;
162 bn_mul_add_words(&(r[1]),a,n,b[1]);
163 if (--n <= 0) return;
164 bn_mul_add_words(&(r[2]),a,n,b[2]);
165 if (--n <= 0) return;
166 bn_mul_add_words(&(r[3]),a,n,b[3]);
167 if (--n <= 0) return;
168 bn_mul_add_words(&(r[4]),a,n,b[4]);