pike.git/
src/
post_modules/
Nettle/
hogweed.cmod
Branch:
Tag:
Non-build tags
All tags
No tags
2015-05-27
2015-05-27 16:04:36 by Henrik Grubbström (Grubba) <grubba@grubba.org>
c88bb106caf6c79eb2edb582958f56deeefff940 (
54
lines) (+
39
/-
15
)
[
Show
|
Annotate
]
Branch:
8.1
Nettle.ECC.Curve.ECDSA: Inherit the Point.
838:
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;
853:
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);
866:
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
916:
*/ 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()
933:
*/ 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()
947:
*/ 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)
961:
*/ 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) *!
990:
object(Gmp.mpz)|int r, object(Gmp.mpz)|int s) {
+
struct ecc_point *pub;
struct dsa_signature sig; int ret;
1006:
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;
1044:
*/ 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); } }