diff options
| author | J08nY | 2019-11-27 20:34:58 +0100 |
|---|---|---|
| committer | J08nY | 2019-11-27 20:34:58 +0100 |
| commit | 32a4874abfbaff8cb4ee2d31fe71bcc3499e52dc (patch) | |
| tree | 1203a322d7488ef51b4de2d34c6e0c2871ea68a5 /pyecsca/codegen/bn/bn.h | |
| parent | bb00fee9702155586e674b9d6a3b838bd54baac2 (diff) | |
| download | pyecsca-codegen-32a4874abfbaff8cb4ee2d31fe71bcc3499e52dc.tar.gz pyecsca-codegen-32a4874abfbaff8cb4ee2d31fe71bcc3499e52dc.tar.zst pyecsca-codegen-32a4874abfbaff8cb4ee2d31fe71bcc3499e52dc.zip | |
Reorganize files, implement proper main.
Diffstat (limited to 'pyecsca/codegen/bn/bn.h')
| -rw-r--r-- | pyecsca/codegen/bn/bn.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/pyecsca/codegen/bn/bn.h b/pyecsca/codegen/bn/bn.h new file mode 100644 index 0000000..2ff723f --- /dev/null +++ b/pyecsca/codegen/bn/bn.h @@ -0,0 +1,51 @@ +#ifndef BN_H_ +#define BN_H_ + +#include <tommath.h> + +#define bn_t mp_int +#define bn_err mp_err + +typedef struct { + char name; + bn_t value; +} named_bn_t; + +bn_err bn_init(bn_t *bn); +void bn_copy(const bn_t *from, bn_t *to); +void bn_clear(bn_t *bn); + +int bn_from_bin(const uint8_t *data, size_t size, bn_t *out); +int bn_from_hex(const char *data, bn_t *out); +int bn_from_int(uint64_t value, bn_t *out); + +void bn_to_binpad(const bn_t *one, uint8_t *data, size_t size); +void bn_to_bin(const bn_t *one, uint8_t *data); +size_t bn_to_bin_size(const bn_t *one); + +void bn_rand_mod_sample(bn_t *out, const bn_t *mod); +void bn_rand_mod_reduce(bn_t *out, const bn_t *mod); + +#if MOD_RAND == MOD_RAND_SAMPLE +#define bn_rand_mod bn_rand_mod_sample +#elif MOD_RAND == MOD_RAND_REDUCE +#define bn_rand_mod bn_rand_mod_reduce +#endif + +void bn_mod_add(const bn_t *one, const bn_t *other, const bn_t *mod, bn_t *out); +void bn_mod_sub(const bn_t *one, const bn_t *other, const bn_t *mod, bn_t *out); +void bn_mod_mul(const bn_t *one, const bn_t *other, const bn_t *mod, bn_t *out); +void bn_mod_sqr(const bn_t *one, const bn_t *mod, bn_t *out); +void bn_mod_div(const bn_t *one, const bn_t *other, const bn_t *mod, bn_t *out); +void bn_mod_inv(const bn_t *one, const bn_t *mod, bn_t *out); +void bn_mod(const bn_t *one, const bn_t *mod, bn_t *out); + +void bn_lsh(const bn_t *one, int amount, bn_t *out); +void bn_rsh(const bn_t *one, int amount, bn_t *out); + +bool bn_eq(const bn_t *one, const bn_t *other); + +int bn_get_bit(const bn_t *bn, int which); +int bn_bit_length(const bn_t *bn); + +#endif //BN_H_
\ No newline at end of file |
