pike.git / src / post_modules / Nettle / hogweed.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hogweed.cmod:353:    *! Elliptic Curve Definition    */   PIKECLASS ECC_Curve   {    /*! @decl inherit __builtin.Nettle.ECC_Curve    */    INHERIT "__builtin.Nettle.ECC_Curve";       CVAR const struct ecc_curve *curve;    +  /* Initialized to the scalar constant 1. */ +  CVAR struct ecc_scalar scalar_one; +     DECLARE_STORAGE;    -  +  EXIT +  { +  ecc_scalar_clear(&THIS->scalar_one); +  } +     /*! @decl void create(int(0..) curve)    *!    *! Initialize the curve.    *!    *! @param curve    *! The curve type the object should be initialized as.    *! @int    *! @value Nettle.SECP192R1    *! @value Nettle.SECP224R1    *! @value Nettle.SECP256R1    *! @value Nettle.SECP384R1    *! @value Nettle.SECP521R1    *! @endint    */    PIKEFUN void create(int(0..) curve)    flags ID_STATIC    { -  +  mpz_t mpz_one; +     if (THIS->curve) {    Pike_error("The curve has already been initialized!\n");    }       switch(curve) {   #ifdef HAVE_CURVE_NETTLE_SECP_192R1    case SECP192R1: THIS->curve = &nettle_secp_192r1; break;   #endif /* HAVE_CURVE_NETTLE_SECP_192R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_224R1    case SECP224R1: THIS->curve = &nettle_secp_224r1; break;
pike.git/src/post_modules/Nettle/hogweed.cmod:396:   #ifdef HAVE_CURVE_NETTLE_SECP_384R1    case SECP384R1: THIS->curve = &nettle_secp_384r1; break;   #endif /* HAVE_CURVE_NETTLE_SECP_384R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_521R1    case SECP521R1: THIS->curve = &nettle_secp_521r1; break;   #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */    default:    Pike_error("Invalid curve\n");    break;    } +  +  ecc_scalar_init(&THIS->scalar_one, THIS->curve); +  mpz_init_set_si(mpz_one, 1); +  ecc_scalar_set(&THIS->scalar_one, mpz_one); +  mpz_clear(mpz_one);    }       /*! @decl protected local int(0..1) `==(mixed x)    *!    *! @returns    *! Returns @expr{1@} if @[x] is the same @[Curve],    *! and @expr{0@} (zero) otherwise.    */    PIKEFUN int(0..1) `==(mixed x)    flags ID_PROTECTED|ID_LOCAL;
pike.git/src/post_modules/Nettle/hogweed.cmod:714:    0, parent_Point_fun_num);    low_inherit(parent_Point_prog, 0,    parent_Point_fun_num,    1 + 42, 0, NULL);    }    }    }       INIT    { -  const struct ecc_curve *curve = -  (((const struct Nettle_ECC_Curve_struct *)parent_storage(1, Nettle_ECC_Curve_program))->curve); +  const struct Nettle_ECC_Curve_struct *parent = +  parent_storage(1, Nettle_ECC_Curve_program); +  const struct ecc_curve *curve = parent->curve; +     if (!curve) Pike_error("No curve selected.\n");    ecc_point_init(&THIS->point, curve); -  +  +  /* Make sure that the point is on the curve by initializing it to 'g'. */ +  ecc_point_mul_g(&THIS->point, &parent->scalar_one);    }       EXIT    { -  const struct ecc_curve *curve = -  (((const struct Nettle_ECC_Curve_struct *)parent_storage(1, Nettle_ECC_Curve_program))->curve); +  const struct Nettle_ECC_Curve_struct *parent = +  parent_storage(1, Nettle_ECC_Curve_program); +  const struct ecc_curve *curve = parent->curve; +     if (!curve) return;    ecc_point_clear(&THIS->point);    }       /*! @decl protected local int(0..1) _equal(mixed x)    *!    *! @returns    *! Returns @expr{1@} if @[x] is a @[Point] on the same    *! @[Curve] and has the same coordinates, and otherwise    *! returns @expr{0@} (zero).