~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/bn/bn_recp.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051213213742-d0ydaylf80l16bj1
Tags: upstream-0.9.8a
ImportĀ upstreamĀ versionĀ 0.9.8a

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
95
95
        {
96
96
        if (!BN_copy(&(recp->N),d)) return 0;
97
 
        if (!BN_zero(&(recp->Nr))) return 0;
 
97
        BN_zero(&(recp->Nr));
98
98
        recp->num_bits=BN_num_bits(d);
99
99
        recp->shift=0;
100
100
        return(1);
123
123
        ret = BN_div_recp(NULL,r,ca,recp,ctx);
124
124
err:
125
125
        BN_CTX_end(ctx);
 
126
        bn_check_top(r);
126
127
        return(ret);
127
128
        }
128
129
 
147
148
 
148
149
        if (BN_ucmp(m,&(recp->N)) < 0)
149
150
                {
150
 
                if (!BN_zero(d)) return 0;
 
151
                BN_zero(d);
151
152
                if (!BN_copy(r,m)) return 0;
152
153
                BN_CTX_end(ctx);
153
154
                return(1);
190
191
                {
191
192
                if (j++ > 2)
192
193
                        {
193
 
                        BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
 
194
                        BNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL);
194
195
                        goto err;
195
196
                        }
196
197
                if (!BN_usub(r,r,&(recp->N))) goto err;
203
204
        ret=1;
204
205
err:
205
206
        BN_CTX_end(ctx);
 
207
        bn_check_top(dv);
 
208
        bn_check_top(rem);
206
209
        return(ret);
207
210
        } 
208
211
 
214
217
int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)
215
218
        {
216
219
        int ret= -1;
217
 
        BIGNUM t;
218
 
 
219
 
        BN_init(&t);
220
 
 
221
 
        if (!BN_zero(&t)) goto err;
222
 
        if (!BN_set_bit(&t,len)) goto err;
223
 
 
224
 
        if (!BN_div(r,NULL,&t,m,ctx)) goto err;
 
220
        BIGNUM *t;
 
221
 
 
222
        BN_CTX_start(ctx);
 
223
        if((t = BN_CTX_get(ctx)) == NULL) goto err;
 
224
 
 
225
        if (!BN_set_bit(t,len)) goto err;
 
226
 
 
227
        if (!BN_div(r,NULL,t,m,ctx)) goto err;
225
228
 
226
229
        ret=len;
227
230
err:
228
 
        BN_free(&t);
 
231
        bn_check_top(r);
 
232
        BN_CTX_end(ctx);
229
233
        return(ret);
230
234
        }