< prev index next >

src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c

Print this page
rev 16167 : 8170525: Fix minor issues in awt coding


  55         mp_int kt;
  56 
  57         ARGCHK((k != NULL) && (group != NULL), MP_BADARG);
  58         MP_DIGITS(&kt) = 0;
  59 
  60         /* want scalar to be less than or equal to group order */
  61         if (mp_cmp(k, &group->order) > 0) {
  62                 MP_CHECKOK(mp_init(&kt, FLAG(k)));
  63                 MP_CHECKOK(mp_mod(k, &group->order, &kt));
  64         } else {
  65                 MP_SIGN(&kt) = MP_ZPOS;
  66                 MP_USED(&kt) = MP_USED(k);
  67                 MP_ALLOC(&kt) = MP_ALLOC(k);
  68                 MP_DIGITS(&kt) = MP_DIGITS(k);
  69         }
  70 
  71         if ((px == NULL) || (py == NULL)) {
  72                 if (group->base_point_mul) {
  73                         MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
  74                 } else {

  75                         MP_CHECKOK(group->
  76                                            point_mul(&kt, &group->genx, &group->geny, rx, ry,
  77                                                                  group));
  78                 }
  79         } else {
  80                 if (group->meth->field_enc) {
  81                         MP_CHECKOK(group->meth->field_enc(px, rx, group->meth));
  82                         MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
  83                         MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
  84                 } else {

  85                         MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
  86                 }
  87         }
  88         if (group->meth->field_dec) {
  89                 MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
  90                 MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
  91         }
  92 
  93   CLEANUP:
  94         if (MP_DIGITS(&kt) != MP_DIGITS(k)) {
  95                 mp_clear(&kt);
  96         }
  97         return res;
  98 }
  99 
 100 /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
 101  * k2 * P(x, y), where G is the generator (base point) of the group of
 102  * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
 103  * Input and output values are assumed to be NOT field-encoded. */
 104 mp_err




  55         mp_int kt;
  56 
  57         ARGCHK((k != NULL) && (group != NULL), MP_BADARG);
  58         MP_DIGITS(&kt) = 0;
  59 
  60         /* want scalar to be less than or equal to group order */
  61         if (mp_cmp(k, &group->order) > 0) {
  62                 MP_CHECKOK(mp_init(&kt, FLAG(k)));
  63                 MP_CHECKOK(mp_mod(k, &group->order, &kt));
  64         } else {
  65                 MP_SIGN(&kt) = MP_ZPOS;
  66                 MP_USED(&kt) = MP_USED(k);
  67                 MP_ALLOC(&kt) = MP_ALLOC(k);
  68                 MP_DIGITS(&kt) = MP_DIGITS(k);
  69         }
  70 
  71         if ((px == NULL) || (py == NULL)) {
  72                 if (group->base_point_mul) {
  73                         MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
  74                 } else {
  75                         kt.flag = (mp_sign)0;
  76                         MP_CHECKOK(group->
  77                                            point_mul(&kt, &group->genx, &group->geny, rx, ry,
  78                                                                  group));
  79                 }
  80         } else {
  81                 if (group->meth->field_enc) {
  82                         MP_CHECKOK(group->meth->field_enc(px, rx, group->meth));
  83                         MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
  84                         MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
  85                 } else {
  86                         kt.flag = (mp_sign)0;
  87                         MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
  88                 }
  89         }
  90         if (group->meth->field_dec) {
  91                 MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
  92                 MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
  93         }
  94 
  95   CLEANUP:
  96         if (MP_DIGITS(&kt) != MP_DIGITS(k)) {
  97                 mp_clear(&kt);
  98         }
  99         return res;
 100 }
 101 
 102 /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
 103  * k2 * P(x, y), where G is the generator (base point) of the group of
 104  * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
 105  * Input and output values are assumed to be NOT field-encoded. */
 106 mp_err


< prev index next >