aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/bn.c
diff options
context:
space:
mode:
authorJ08nY2019-11-26 20:37:19 +0100
committerJ08nY2019-11-26 20:37:19 +0100
commitbb00fee9702155586e674b9d6a3b838bd54baac2 (patch)
treecc35efecb92ae20dbab88694737a6b7d53a62782 /pyecsca/codegen/bn.c
parent6784477dfc8f34f8d1a262517fe83ae70a59b325 (diff)
downloadpyecsca-codegen-bb00fee9702155586e674b9d6a3b838bd54baac2.tar.gz
pyecsca-codegen-bb00fee9702155586e674b9d6a3b838bd54baac2.tar.zst
pyecsca-codegen-bb00fee9702155586e674b9d6a3b838bd54baac2.zip
Add ASN.1 parsing and more utility functions, + commands sketch.
Diffstat (limited to 'pyecsca/codegen/bn.c')
-rw-r--r--pyecsca/codegen/bn.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/pyecsca/codegen/bn.c b/pyecsca/codegen/bn.c
index 26149ba..aa33124 100644
--- a/pyecsca/codegen/bn.c
+++ b/pyecsca/codegen/bn.c
@@ -12,6 +12,10 @@ void bn_clear(bn_t *bn) {
mp_clear(bn);
}
+int bn_from_bin(const uint8_t *data, size_t size, bn_t *out) {
+ return mp_from_ubin(out, data, size);
+}
+
int bn_from_hex(const char *data, bn_t *out) {
return mp_read_radix(out, data, 16);
}
@@ -21,6 +25,20 @@ int bn_from_int(uint64_t value, bn_t *out) {
return MP_OKAY;
}
+void bn_to_binpad(const bn_t *one, uint8_t *data, size_t size) {
+ size_t ubin_size = mp_ubin_size(one);
+ size_t offset = size - ubin_size;
+ mp_to_ubin(one, data + offset, ubin_size, NULL);
+}
+
+void bn_to_bin(const bn_t *one, uint8_t *data) {
+ mp_to_ubin(one, data, mp_ubin_size(one), NULL);
+}
+
+size_t bn_to_bin_size(const bn_t *one) {
+ return mp_ubin_size(one);
+}
+
void bn_mod_add(bn_t *one, bn_t *other, bn_t *mod, bn_t *out) {
mp_addmod(one, other, mod, out);
}