Back to index

lightning-sunbird  0.9+nobinonly
Typedefs | Functions
ecl.h File Reference
#include "ecl-exp.h"
#include "mpi.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct ECGroupStr

Functions

ECGroup * ECGroup_fromHex (const ECCurveParams *params)
ECGroup * ECGroup_fromName (const ECCurveName name)
void ECGroup_free (ECGroup *group)
ECCurveParams * EC_GetNamedCurveParams (const ECCurveName name)
ECCurveParams * ECCurveParams_dup (const ECCurveParams *params)
void EC_FreeCurveParams (ECCurveParams *params)
mp_err ECPoint_mul (const ECGroup *group, const mp_int *k, const mp_int *px, const mp_int *py, mp_int *qx, mp_int *qy)
mp_err ECPoints_mul (const ECGroup *group, const mp_int *k1, const mp_int *k2, const mp_int *px, const mp_int *py, mp_int *qx, mp_int *qy)
mp_err ECPoint_validate (const ECGroup *group, const mp_int *px, const mp_int *py)

Typedef Documentation

typedef struct ECGroupStr

Definition at line 49 of file ecl.h.


Function Documentation

void EC_FreeCurveParams ( ECCurveParams *  params)

Definition at line 104 of file ecl_curve.c.

{
       if (params == NULL)
              return;
       if (params->text != NULL)
              free(params->text);
       if (params->irr != NULL)
              free(params->irr);
       if (params->curvea != NULL)
              free(params->curvea);
       if (params->curveb != NULL)
              free(params->curveb);
       if (params->genx != NULL)
              free(params->genx);
       if (params->geny != NULL)
              free(params->geny);
       if (params->order != NULL)
              free(params->order);
       free(params);
}

Here is the caller graph for this function:

ECCurveParams* EC_GetNamedCurveParams ( const ECCurveName  name)

Definition at line 92 of file ecl_curve.c.

{
       if ((name <= ECCurve_noName) || (ECCurve_pastLastCurve <= name) ||
                                   (ecCurve_map[name] == NULL)) {
              return NULL;
       } else {
              return ECCurveParams_dup(ecCurve_map[name]);
       }
}

Here is the caller graph for this function:

ECCurveParams* ECCurveParams_dup ( const ECCurveParams *  params)

Definition at line 49 of file ecl_curve.c.

{
       int res = 1;
       ECCurveParams *ret = NULL;

       CHECK(ret = (ECCurveParams *) calloc(1, sizeof(ECCurveParams)));
       if (params->text != NULL) {
              CHECK(ret->text = strdup(params->text));
       }
       ret->field = params->field;
       ret->size = params->size;
       if (params->irr != NULL) {
              CHECK(ret->irr = strdup(params->irr));
       }
       if (params->curvea != NULL) {
              CHECK(ret->curvea = strdup(params->curvea));
       }
       if (params->curveb != NULL) {
              CHECK(ret->curveb = strdup(params->curveb));
       }
       if (params->genx != NULL) {
              CHECK(ret->genx = strdup(params->genx));
       }
       if (params->geny != NULL) {
              CHECK(ret->geny = strdup(params->geny));
       }
       if (params->order != NULL) {
              CHECK(ret->order = strdup(params->order));
       }
       ret->cofactor = params->cofactor;

  CLEANUP:
       if (res != 1) {
              EC_FreeCurveParams(ret);
              return NULL;
       }
       return ret;
}

Here is the caller graph for this function:

void ECGroup_free ( ECGroup *  group)

Definition at line 409 of file ecl.c.

{
       if (group == NULL)
              return;
       GFMethod_free(group->meth);
       if (group->constructed == MP_NO)
              return;
       mp_clear(&group->curvea);
       mp_clear(&group->curveb);
       mp_clear(&group->genx);
       mp_clear(&group->geny);
       mp_clear(&group->order);
       if (group->text != NULL)
              free(group->text);
       if (group->extra_free != NULL)
              group->extra_free(group);
       free(group);
}
ECGroup* ECGroup_fromHex ( const ECCurveParams *  params)

Definition at line 357 of file ecl.c.

ECGroup* ECGroup_fromName ( const ECCurveName  name)

Definition at line 364 of file ecl.c.

{
       ECGroup *group = NULL;
       ECCurveParams *params = NULL;
       mp_err res = MP_OKAY;

       params = EC_GetNamedCurveParams(name);
       if (params == NULL) {
              res = MP_UNDEF;
              goto CLEANUP;
       }

       /* construct actual group */
       group = ecgroup_fromNameAndHex(name, params);
       if (group == NULL) {
              res = MP_UNDEF;
              goto CLEANUP;
       }

  CLEANUP:
       EC_FreeCurveParams(params);
       if (res != MP_OKAY) {
              ECGroup_free(group);
              return NULL;
       }
       return group;
}
mp_err ECPoint_mul ( const ECGroup *  group,
const mp_int k,
const mp_int px,
const mp_int py,
mp_int qx,
mp_int qy 
)

Definition at line 50 of file ecl_mult.c.

{
       mp_err res = MP_OKAY;
       mp_int kt;

       ARGCHK((k != NULL) && (group != NULL), MP_BADARG);
       MP_DIGITS(&kt) = 0;

       /* want scalar to be less than or equal to group order */
       if (mp_cmp(k, &group->order) > 0) {
              MP_CHECKOK(mp_init(&kt));
              MP_CHECKOK(mp_mod(k, &group->order, &kt));
       } else {
              MP_SIGN(&kt) = MP_ZPOS;
              MP_USED(&kt) = MP_USED(k);
              MP_ALLOC(&kt) = MP_ALLOC(k);
              MP_DIGITS(&kt) = MP_DIGITS(k);
       }

       if ((px == NULL) || (py == NULL)) {
              if (group->base_point_mul) {
                     MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
              } else {
                     MP_CHECKOK(group->
                                      point_mul(&kt, &group->genx, &group->geny, rx, ry,
                                                         group));
              }
       } else {
              if (group->meth->field_enc) {
                     MP_CHECKOK(group->meth->field_enc(px, rx, group->meth));
                     MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
                     MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
              } else {
                     MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
              }
       }
       if (group->meth->field_dec) {
              MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
              MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
       }

  CLEANUP:
       if (MP_DIGITS(&kt) != MP_DIGITS(k)) {
              mp_clear(&kt);
       }
       return res;
}

Here is the caller graph for this function:

mp_err ECPoint_validate ( const ECGroup *  group,
const mp_int px,
const mp_int py 
)

Definition at line 393 of file ecl.c.

{
    /* 1: Verify that publicValue is not the point at infinity */
    /* 2: Verify that the coordinates of publicValue are elements 
     *    of the field.
     */
    /* 3: Verify that publicValue is on the curve. */
    /* 4: Verify that the order of the curve times the publicValue
     *    is the point at infinity.
     */
       return group->validate_point(px, py, group);
}
mp_err ECPoints_mul ( const ECGroup *  group,
const mp_int k1,
const mp_int k2,
const mp_int px,
const mp_int py,
mp_int qx,
mp_int qy 
)

Definition at line 309 of file ecl_mult.c.

{
       mp_err res = MP_OKAY;
       mp_int k1t, k2t;
       const mp_int *k1p, *k2p;

       MP_DIGITS(&k1t) = 0;
       MP_DIGITS(&k2t) = 0;

       ARGCHK(group != NULL, MP_BADARG);

       /* want scalar to be less than or equal to group order */
       if (k1 != NULL) {
              if (mp_cmp(k1, &group->order) >= 0) {
                     MP_CHECKOK(mp_init(&k1t));
                     MP_CHECKOK(mp_mod(k1, &group->order, &k1t));
                     k1p = &k1t;
              } else {
                     k1p = k1;
              }
       } else {
              k1p = k1;
       }
       if (k2 != NULL) {
              if (mp_cmp(k2, &group->order) >= 0) {
                     MP_CHECKOK(mp_init(&k2t));
                     MP_CHECKOK(mp_mod(k2, &group->order, &k2t));
                     k2p = &k2t;
              } else {
                     k2p = k2;
              }
       } else {
              k2p = k2;
       }

       /* if points_mul is defined, then use it */
       if (group->points_mul) {
              res = group->points_mul(k1p, k2p, px, py, rx, ry, group);
       } else {
              res = ec_pts_mul_simul_w2(k1p, k2p, px, py, rx, ry, group);
       }

  CLEANUP:
       mp_clear(&k1t);
       mp_clear(&k2t);
       return res;
}

Here is the caller graph for this function: