From bb00fee9702155586e674b9d6a3b838bd54baac2 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 26 Nov 2019 20:37:19 +0100 Subject: Add ASN.1 parsing and more utility functions, + commands sketch. --- pyecsca/codegen/bn.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'pyecsca/codegen/bn.c') 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); } -- cgit v1.3.1