Diff
Not logged in

Differences From Artifact [528c74b625]:

To Artifact [10658ddae6]:


13
14
15
16
17
18
19
20

21
22
23
24
25
26

27
28
29
30
31
32
33

34
35

36
37
38

39
40
41

42
43
44

45
46
47

48
49
50

51
52
53

54
55

56
57
58

59
60
61

62
63
64

65
66

67
68
69

70
71
72

73
74
75

76
77
78
79
80
81
82

83
84
85

86
87
88

89
90
91
92
93
94
95
96
97
13
14
15
16
17
18
19

20


21
22
23

24


25
26
27
28

29


30

31

32



33



34



35



36



37


38

39

40



41



42


43

44

45



46



47


48
49
50
51

52



53



54


55
56
57
58
59
60
61







-
+
-
-



-
+
-
-




-
+
-
-
+
-

-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
+
-

-
+
-
-
-
+
-
-
-
+
-
-
+
-

-
+
-
-
-
+
-
-
-
+
-
-




-
+
-
-
-
+
-
-
-
+
-
-








   if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
      return err;
   }

   /* initialize, (u1,u2,u3) = (1,0,a) */
   mp_set(&u1, 1uL);
   if ((err = mp_copy(a, &u3)) != MP_OKAY) {
   if ((err = mp_copy(a, &u3)) != MP_OKAY)                        goto LBL_ERR;
      goto LBL_ERR;
   }

   /* initialize, (v1,v2,v3) = (0,1,b) */
   mp_set(&v2, 1uL);
   if ((err = mp_copy(b, &v3)) != MP_OKAY) {
   if ((err = mp_copy(b, &v3)) != MP_OKAY)                        goto LBL_ERR;
      goto LBL_ERR;
   }

   /* loop while v3 != 0 */
   while (!MP_IS_ZERO(&v3)) {
      /* q = u3/v3 */
      if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) {
      if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)          goto LBL_ERR;
         goto LBL_ERR;
      }


      /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
      if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY) {
      if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)               goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY) {
      if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)              goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY) {
      if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)               goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY) {
      if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)              goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY) {
      if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)               goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY) {
      if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)              goto LBL_ERR;
         goto LBL_ERR;
      }


      /* (u1,u2,u3) = (v1,v2,v3) */
      if ((err = mp_copy(&v1, &u1)) != MP_OKAY) {
      if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_copy(&v2, &u2)) != MP_OKAY) {
      if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_copy(&v3, &u3)) != MP_OKAY) {
      if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }


      /* (v1,v2,v3) = (t1,t2,t3) */
      if ((err = mp_copy(&t1, &v1)) != MP_OKAY) {
      if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_copy(&t2, &v2)) != MP_OKAY) {
      if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_copy(&t3, &v3)) != MP_OKAY) {
      if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                   goto LBL_ERR;
         goto LBL_ERR;
      }
   }

   /* make sure U3 >= 0 */
   if (u3.sign == MP_NEG) {
      if ((err = mp_neg(&u1, &u1)) != MP_OKAY) {
      if ((err = mp_neg(&u1, &u1)) != MP_OKAY)                    goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_neg(&u2, &u2)) != MP_OKAY) {
      if ((err = mp_neg(&u2, &u2)) != MP_OKAY)                    goto LBL_ERR;
         goto LBL_ERR;
      }
      if ((err = mp_neg(&u3, &u3)) != MP_OKAY) {
      if ((err = mp_neg(&u3, &u3)) != MP_OKAY)                    goto LBL_ERR;
         goto LBL_ERR;
      }
   }

   /* copy result out */
   if (U1 != NULL) {
      mp_exch(U1, &u1);
   }
   if (U2 != NULL) {