~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtommath/etc/pprime.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
189
189
  }
190
190
 
191
191
  if ((res = mp_init (&v)) != MP_OKAY) {
192
 
    goto __C;
 
192
    goto LBL_C;
193
193
  }
194
194
 
195
195
  /* product of first 50 primes */
197
197
       mp_read_radix (&v,
198
198
                      "19078266889580195013601891820992757757219839668357012055907516904309700014933909014729740190",
199
199
                      10)) != MP_OKAY) {
200
 
    goto __V;
 
200
    goto LBL_V;
201
201
  }
202
202
 
203
203
  if ((res = mp_init (&a)) != MP_OKAY) {
204
 
    goto __V;
 
204
    goto LBL_V;
205
205
  }
206
206
 
207
207
  /* set the prime */
208
208
  mp_set (&a, prime_digit ());
209
209
 
210
210
  if ((res = mp_init (&b)) != MP_OKAY) {
211
 
    goto __A;
 
211
    goto LBL_A;
212
212
  }
213
213
 
214
214
  if ((res = mp_init (&n)) != MP_OKAY) {
215
 
    goto __B;
 
215
    goto LBL_B;
216
216
  }
217
217
 
218
218
  if ((res = mp_init (&x)) != MP_OKAY) {
219
 
    goto __N;
 
219
    goto LBL_N;
220
220
  }
221
221
 
222
222
  if ((res = mp_init (&y)) != MP_OKAY) {
223
 
    goto __X;
 
223
    goto LBL_X;
224
224
  }
225
225
 
226
226
  if ((res = mp_init (&z)) != MP_OKAY) {
227
 
    goto __Y;
 
227
    goto LBL_Y;
228
228
  }
229
229
 
230
230
  /* now loop making the single digit */
236
236
 
237
237
    /* now compute z = a * b * 2 */
238
238
    if ((res = mp_mul (&a, &b, &z)) != MP_OKAY) {       /* z = a * b */
239
 
      goto __Z;
 
239
      goto LBL_Z;
240
240
    }
241
241
 
242
242
    if ((res = mp_copy (&z, &c)) != MP_OKAY) {  /* c = a * b */
243
 
      goto __Z;
 
243
      goto LBL_Z;
244
244
    }
245
245
 
246
246
    if ((res = mp_mul_2 (&z, &z)) != MP_OKAY) { /* z = 2 * a * b */
247
 
      goto __Z;
 
247
      goto LBL_Z;
248
248
    }
249
249
 
250
250
    /* n = z + 1 */
251
251
    if ((res = mp_add_d (&z, 1, &n)) != MP_OKAY) {      /* n = z + 1 */
252
 
      goto __Z;
 
252
      goto LBL_Z;
253
253
    }
254
254
 
255
255
    /* check (n, v) == 1 */
256
256
    if ((res = mp_gcd (&n, &v, &y)) != MP_OKAY) {       /* y = (n, v) */
257
 
      goto __Z;
 
257
      goto LBL_Z;
258
258
    }
259
259
 
260
260
    if (mp_cmp_d (&y, 1) != MP_EQ)
266
266
 
267
267
      /* compute x^a mod n */
268
268
      if ((res = mp_exptmod (&x, &a, &n, &y)) != MP_OKAY) {     /* y = x^a mod n */
269
 
        goto __Z;
 
269
        goto LBL_Z;
270
270
      }
271
271
 
272
272
      /* if y == 1 loop */
275
275
 
276
276
      /* now x^2a mod n */
277
277
      if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) {  /* y = x^2a mod n */
278
 
        goto __Z;
 
278
        goto LBL_Z;
279
279
      }
280
280
 
281
281
      if (mp_cmp_d (&y, 1) == MP_EQ)
283
283
 
284
284
      /* compute x^b mod n */
285
285
      if ((res = mp_exptmod (&x, &b, &n, &y)) != MP_OKAY) {     /* y = x^b mod n */
286
 
        goto __Z;
 
286
        goto LBL_Z;
287
287
      }
288
288
 
289
289
      /* if y == 1 loop */
292
292
 
293
293
      /* now x^2b mod n */
294
294
      if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) {  /* y = x^2b mod n */
295
 
        goto __Z;
 
295
        goto LBL_Z;
296
296
      }
297
297
 
298
298
      if (mp_cmp_d (&y, 1) == MP_EQ)
300
300
 
301
301
      /* compute x^c mod n == x^ab mod n */
302
302
      if ((res = mp_exptmod (&x, &c, &n, &y)) != MP_OKAY) {     /* y = x^ab mod n */
303
 
        goto __Z;
 
303
        goto LBL_Z;
304
304
      }
305
305
 
306
306
      /* if y == 1 loop */
309
309
 
310
310
      /* now compute (x^c mod n)^2 */
311
311
      if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) {  /* y = x^2ab mod n */
312
 
        goto __Z;
 
312
        goto LBL_Z;
313
313
      }
314
314
 
315
315
      /* y should be 1 */
346
346
  mp_exch (&n, p);
347
347
 
348
348
  res = MP_OKAY;
349
 
__Z:mp_clear (&z);
350
 
__Y:mp_clear (&y);
351
 
__X:mp_clear (&x);
352
 
__N:mp_clear (&n);
353
 
__B:mp_clear (&b);
354
 
__A:mp_clear (&a);
355
 
__V:mp_clear (&v);
356
 
__C:mp_clear (&c);
 
349
LBL_Z:mp_clear (&z);
 
350
LBL_Y:mp_clear (&y);
 
351
LBL_X:mp_clear (&x);
 
352
LBL_N:mp_clear (&n);
 
353
LBL_B:mp_clear (&b);
 
354
LBL_A:mp_clear (&a);
 
355
LBL_V:mp_clear (&v);
 
356
LBL_C:mp_clear (&c);
357
357
  return res;
358
358
}
359
359