aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates
diff options
context:
space:
mode:
authorJ08nY2020-02-20 20:41:29 +0100
committerJ08nY2020-02-20 20:41:29 +0100
commit3892d994470b181f950703fabf719a9c963d1c20 (patch)
treefc1c7e68fc6334a7f89fd69eab00a830fb58f275 /pyecsca/codegen/templates
parent92cb16e8103da998aa1bf226d24ef6771a92c5d5 (diff)
downloadpyecsca-codegen-3892d994470b181f950703fabf719a9c963d1c20.tar.gz
pyecsca-codegen-3892d994470b181f950703fabf719a9c963d1c20.tar.zst
pyecsca-codegen-3892d994470b181f950703fabf719a9c963d1c20.zip
Add full implementation tests.
Diffstat (limited to 'pyecsca/codegen/templates')
-rw-r--r--pyecsca/codegen/templates/main.c7
-rw-r--r--pyecsca/codegen/templates/mult_ltr.c4
-rw-r--r--pyecsca/codegen/templates/mult_rtl.c4
3 files changed, 10 insertions, 5 deletions
diff --git a/pyecsca/codegen/templates/main.c b/pyecsca/codegen/templates/main.c
index ae36bfd..b0f81f1 100644
--- a/pyecsca/codegen/templates/main.c
+++ b/pyecsca/codegen/templates/main.c
@@ -325,12 +325,17 @@ static uint8_t cmd_ecdsa_sign(uint8_t *data, uint16_t len) {
bn_t r; bn_init(&r);
point_to_affine(p, curve, &r, NULL);
bn_mod(&r, &curve->n, &r);
+ // r = ([k]G).x mod n
bn_t s; bn_init(&s);
bn_copy(&privkey, &s);
+ // s = x
bn_mod_mul(&s, &r, &curve->n, &s);
+ // s = rx mod n
bn_mod_add(&s, &h, &curve->n, &s);
+ // s = rx + H(m) mod n
bn_mod_div(&s, &k, &curve->n, &s);
+ // s = k^(-1)*(rx + H(m)) mod n
size_t result_len = 0;
uint8_t *result = asn1_der_encode(&r, &s, &result_len);
@@ -444,7 +449,7 @@ int main(void) {
{%- endif %}
{%- if ecdsa %}
simpleserial_addcmd('a', MAX_SS_LEN, cmd_ecdsa_sign);
- simpleserial_addcmd('v', MAX_SS_LEN, cmd_ecdsa_verify);
+ simpleserial_addcmd('r', MAX_SS_LEN, cmd_ecdsa_verify);
{%- endif %}
simpleserial_addcmd('d', MAX_SS_LEN, cmd_debug);
diff --git a/pyecsca/codegen/templates/mult_ltr.c b/pyecsca/codegen/templates/mult_ltr.c
index dbd4704..5b08b80 100644
--- a/pyecsca/codegen/templates/mult_ltr.c
+++ b/pyecsca/codegen/templates/mult_ltr.c
@@ -19,10 +19,10 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) {
for (int i = nbits; i >= 0; i--) {
point_dbl(r, curve, r);
if (bn_get_bit(scalar, i) == 1) {
- point_add(q, r, curve, r);
+ point_add(r, q, curve, r);
} else {
{%- if scalarmult.always %}
- point_add(q, r, curve, dummy);
+ point_add(r, q, curve, dummy);
{%- endif %}
}
}
diff --git a/pyecsca/codegen/templates/mult_rtl.c b/pyecsca/codegen/templates/mult_rtl.c
index 01d42a5..ba40a66 100644
--- a/pyecsca/codegen/templates/mult_rtl.c
+++ b/pyecsca/codegen/templates/mult_rtl.c
@@ -14,10 +14,10 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) {
while (!bn_is_0(&copy)) {
if (bn_get_bit(&copy, 0) == 1) {
- point_add(q, r, curve, r);
+ point_add(r, q, curve, r);
} else {
{%- if scalarmult.always %}
- point_add(q, r, curve, dummy);
+ point_add(r, q, curve, dummy);
{%- endif %}
}
point_dbl(q, curve, q);