aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/mult
diff options
context:
space:
mode:
authorJ08nY2019-11-25 17:45:35 +0100
committerJ08nY2019-11-25 17:45:35 +0100
commit8a56c7a95e662862cfe78b834ccb091e95d5372f (patch)
tree1fd57480b7fc681f00c0bfb6c0e5cfea86762f87 /pyecsca/codegen/mult
parentc8d0bff46001bd5636825c5b0bb4c896cb34a4e6 (diff)
downloadpyecsca-codegen-8a56c7a95e662862cfe78b834ccb091e95d5372f.tar.gz
pyecsca-codegen-8a56c7a95e662862cfe78b834ccb091e95d5372f.tar.zst
pyecsca-codegen-8a56c7a95e662862cfe78b834ccb091e95d5372f.zip
Add libtommath, HOST build, and a simple PRNG.
Diffstat (limited to 'pyecsca/codegen/mult')
-rw-r--r--pyecsca/codegen/mult/double_and_add.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/pyecsca/codegen/mult/double_and_add.c b/pyecsca/codegen/mult/double_and_add.c
index 91ad6e3..1fd3c9e 100644
--- a/pyecsca/codegen/mult/double_and_add.c
+++ b/pyecsca/codegen/mult/double_and_add.c
@@ -1,5 +1,18 @@
#include "mult.h"
void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) {
-
+ point_t *q = point_copy(point);
+ point_t *r = point_copy(curve->neutral);
+
+ int nbits = bn_bit_length(curve->n);
+ 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_scl(r, curve, r);
+ point_set(r, out);
+ point_free(q);
+ point_free(r);
} \ No newline at end of file