Optimal implementation of cryptographic function of exponentiation by modulus in Rust

Viewed 93

I try to use the num-bigint crate to implement such a formula ( ( a ^ b ) % c ), where a, b and c are integers of an arbitrary length and ^ the operation of exponentiation, and % the operation of finding the reminder. But I faced two problems.

  1. seems num-bigint does not have single function implementing ( ( a ^ b ) % c ) optimally
  2. num-bigint is not zero-copy. To make an instance of BigUint you need to make a copy of the original data Vec <u8>, and then copy the result again from BigUint to Vec <u8>.

Is it possible to solve these problems within this module? If not, please advise another module?

1 Answers

You may use function modpow as suggested. It seems num does not support zero-copy. Function new copy data from a vector. Same is relevant to from_slice, from_bytes_le, from_bytes_be. Moreover current implementation of from_bytes_le is sub-optimal.

Related