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

version» Context lines:

pike.git/src/post_modules/Nettle/hogweed.cmod:831:    /*! @endclass Point    */       /*! @class ECDSA    *!    *! Elliptic Curve Digital Signing Algorithm    */    PIKECLASS ECDSA    program_flags PROGRAM_USES_PARENT|PROGRAM_NEEDS_PARENT|PROGRAM_CLEAR_STORAGE;    { +  /*! @decl inherit Point +  */ +  INHERIT Nettle_ECC_Curve_Point; +     /*! @decl inherit __builtin.Nettle.Sign    */    INHERIT "__builtin.Nettle.Sign";       CVAR struct ecc_scalar key; -  CVAR struct ecc_point pub; +        PIKEVAR function(int(0..):string(0..255)) random    flags ID_PROTECTED;       INIT    {    const struct ecc_curve *curve =    (((const struct Nettle_ECC_Curve_struct *)parent_storage(1, Nettle_ECC_Curve_program))->curve);    if (!curve) Pike_error("No curve selected.\n"); -  ecc_point_init(&THIS->pub, curve); +     ecc_scalar_init(&THIS->key, curve);    push_constant_text("Crypto.Random.random_string");    APPLY_MASTER("resolv",1);    assign_svalue(&THIS->random, Pike_sp-1);    pop_stack();    }       EXIT    {    const struct ecc_curve *curve =    (((const struct Nettle_ECC_Curve_struct *)parent_storage(1, Nettle_ECC_Curve_program))->curve);    if (!curve) return; -  ecc_point_clear(&THIS->pub); +     ecc_scalar_clear(&THIS->key);    }    -  +  static int f_Nettle_ECC_Curve_ECDSA_inherited_Point_set_fun_num = -1; +  EXTRA +  { +  f_Nettle_ECC_Curve_ECDSA_inherited_Point_set_fun_num = +  really_low_reference_inherited_identifier(NULL, 1, +  f_Nettle_ECC_Curve_Point_set_fun_num); +  } +     /*! @decl string(7bit) name()    *!    *! Returns the string @expr{"ECDSA"@} followed by    *! the parenthesized name of the curve.    */    PIKEFUN string(7bit) name()    {    ref_push_string(MK_STRING("ECDSA("));    apply_external(1, f_Nettle_ECC_Curve_name_fun_num, 0);    ref_push_string(MK_STRING(")"));
pike.git/src/post_modules/Nettle/hogweed.cmod:909:       /*! @decl void set_private_key(object(Gmp.mpz)|int k)    *!    *! Set the private key (and corresponding private key).    *!    *! @note    *! Throws errors if the key isn't valid for the curve.    */    PIKEFUN void set_private_key(object(Gmp.mpz)|int k)    { +  struct ecc_point *pub;    convert_svalue_to_bignum(k);    if (!ecc_scalar_set(&THIS->key, (mpz_srcptr)k->u.object->storage)) {    SIMPLE_ARG_ERROR("set_private_key", 1, "Invalid key for curve.");    }    /* Set the corresponding public key, */ -  ecc_point_mul_g(&THIS->pub, &THIS->key); +  pub = &((struct Nettle_ECC_Curve_Point_struct *) +  get_inherited_storage(1, Nettle_ECC_Curve_Point_program))-> +  point; +  ecc_point_mul_g(pub, &THIS->key);    }       /*! @decl object(Gmp.mpz) get_x()    *!    *! Get the x coordinate of the public key.    *!    *! @seealso    *! @[get_y()]    */    PIKEFUN object(Gmp.mpz) get_x()    { -  +  struct ecc_point *pub;    struct object *ret;    push_object(ret = fast_clone_object(bignum_program)); -  ecc_point_get(&THIS->pub, (mpz_ptr)ret->storage, NULL); +  pub = &((struct Nettle_ECC_Curve_Point_struct *) +  get_inherited_storage(1, Nettle_ECC_Curve_Point_program))-> +  point; +  ecc_point_get(pub, (mpz_ptr)ret->storage, NULL);    }       /*! @decl object(Gmp.mpz) get_y()    *!    *! Get the y coordinate of the public key.    *!    *! @seealso    *! @[get_x()]    */    PIKEFUN object(Gmp.mpz) get_y()    { -  +  struct ecc_point *pub;    struct object *ret;    push_object(ret = fast_clone_object(bignum_program)); -  ecc_point_get(&THIS->pub, NULL, (mpz_ptr)ret->storage); +  pub = &((struct Nettle_ECC_Curve_Point_struct *) +  get_inherited_storage(1, Nettle_ECC_Curve_Point_program))-> +  point; +  ecc_point_get(pub, NULL, (mpz_ptr)ret->storage);    }       /*! @decl void set_public_key(object(Gmp.mpz)|int x, object(Gmp.mpz)|int y)    *!    *! Change to the selected point on the curve as public key.    *!    *! @note    *! Throws errors if the point isn't on the curve.    */    PIKEFUN void set_public_key(object(Gmp.mpz)|int x, object(Gmp.mpz)|int y)    { -  convert_svalue_to_bignum(x); -  convert_svalue_to_bignum(y); -  if (!ecc_point_set(&THIS->pub, -  (mpz_srcptr)x->u.object->storage, -  (mpz_srcptr)y->u.object->storage)) { -  SIMPLE_ARG_ERROR("set_point", 1, "Invalid point on curve."); +  apply_current(f_Nettle_ECC_Curve_ECDSA_inherited_Point_set_fun_num, args);    } -  } +        /*! @decl void set_random(function(int(0..):string(8bit)) r)    *!    *! Set the random function, used to generate keys and parameters,    *! to the function @[r].    */    PIKEFUN void set_random(function(int(0..):string(8bit)) r)    {    assign_svalue(&THIS->random, r);    }
pike.git/src/post_modules/Nettle/hogweed.cmod:983:    /*! @decl int(0..1) raw_verify(string(8bit) digest, @    *! object(Gmp.mpz) r, @    *! object(Gmp.mpz) s)    *!    *! Verify the signature @[r], @[s] against the message digest @[digest].    */    PIKEFUN int(0..1) raw_verify(string(0..255) digest,    object(Gmp.mpz)|int r,    object(Gmp.mpz)|int s)    { +  struct ecc_point *pub;    struct dsa_signature sig;    int ret;       NO_WIDE_STRING(digest);       dsa_signature_init(&sig);       if (!mpz_from_svalue((MP_INT *)&sig.r, r)) {    dsa_signature_clear(&sig);    SIMPLE_ARG_TYPE_ERROR("raw_verify", 1, "Gmp.mpz|int");    }    if (!mpz_from_svalue((MP_INT *)&sig.s, s)) {    dsa_signature_clear(&sig);    SIMPLE_ARG_TYPE_ERROR("raw_verify", 2, "Gmp.mpz|int");    }    -  ret = ecdsa_verify(&THIS->pub, digest->len, STR0(digest), &sig); +  pub = &((struct Nettle_ECC_Curve_Point_struct *) +  get_inherited_storage(1, Nettle_ECC_Curve_Point_program))-> +  point; +  ret = ecdsa_verify(pub, digest->len, STR0(digest), &sig);    dsa_signature_clear(&sig);       RETURN ret;    }       /*! @decl array(Gmp.mpz) raw_sign(string(8bit) digest)    *!    *! Sign the message digest @[digest]. Returns the signature    *! as two @[Gmp.mpz] objects.    */
pike.git/src/post_modules/Nettle/hogweed.cmod:1037:    f_aggregate(2);    stack_pop_n_elems_keep_top(args);    }       /*! @decl void generate_key()    *!    *! Generate a new set of private and public keys on the current curve.    */    PIKEFUN void generate_key()    { -  ecdsa_generate_keypair(&THIS->pub, &THIS->key, +  struct ecc_point *pub; +  pub = &((struct Nettle_ECC_Curve_Point_struct *) +  get_inherited_storage(1, Nettle_ECC_Curve_Point_program))-> +  point; +  ecdsa_generate_keypair(pub, &THIS->key,    &THIS->random, random_func_wrapper);    }    }    /*! @endclass ECDSA    */   }      /*! @endclass ECC_Curve    */