RustCrypto / crypto-bigint

Cryptography-oriented big integer library with constant-time, stack-allocated (no_std-friendly) implementations of modern formulas
Apache License 2.0
180 stars 48 forks source link

Any chance of supporting 8-bit platforms? #182

Open xphoniex opened 1 year ago

xphoniex commented 1 year ago

I'm trying to compile k256 for ATmega328, a popular 8-bit chip on arduino boards, but I'm getting:

error: this crate builds on 32-bit and 64-bit platforms only
  --> /.cargo/registry/src/github.com-1ecc6299db9ec823/crypto-bigint-0.4.9/src/limb.rs:31:1
   |
31 | compile_error!("this crate builds on 32-bit and 64-bit platforms only");

The other alternatives to k256, secp256k1 and libsecp256k1 both need alloc, which I have not been able to get working yet on that platform. Any thoughts?

tarcieri commented 1 year ago

With the forthcoming cpubits crate we may be able to select the 32-bit backend for 8-bit platforms, if that works: https://github.com/RustCrypto/utils/issues/824

xphoniex commented 1 year ago

sidenote: I tried compiling for 32-bit ARM and it still failed because of getrandom crate:

error[E0463]: can't find crate for `std`
 --> /home/usr/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.8/src/error_impls.rs:9:1
  |
9 | extern crate std;
  | ^^^^^^^^^^^^^^^^^ can't find crate
  |
  = note: the `thumbv6m-none-eabi` target may not support the standard library

error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv6m-none-eabi` target may not support the standard library
  = note: `std` is required by `once_cell` because it does not declare `#![no_std]`

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> /home/usr/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.8/src/lib.rs:268:9
    |
268 | /         compile_error!("target is not supported, for more information see: \
269 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /home/usr/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.8/src/lib.rs:290:5
    |
290 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

so with the upcoming cpubits crate, k256 wouldn't still compile for an 8-bit platform like AVR, unless dependencies are changed.

tarcieri commented 1 year ago

getrandom is only under dev-dependencies. Did you add default-features = false to disable the std feature?

We ensure all of the crates in this repo build on no_std targets that are unsupported by getrandom:

https://github.com/RustCrypto/elliptic-curves/blob/master/.github/workflows/k256.yml#L30

xphoniex commented 1 year ago

getrandom is only under dev-dependencies. Did you add default-features = false to disable the std feature?

We ensure all of the crates in this repo build on no_std targets that are unsupported by getrandom:

https://github.com/RustCrypto/elliptic-curves/blob/master/.github/workflows/k256.yml#L30

Oops, my bad, it works! I'd deleted default-features = false before while I was trying different combinations for AVR.

Btw, regarding cpubits: I checked and the crate (https://github.com/RustCrypto/utils/commit/916240a7da4e9c96e67ace0112d501b90c66fb8c) is simply empty for now. What are you blocked on atm? Might be able to help.

tarcieri commented 1 year ago

I just need to finish and merge https://github.com/RustCrypto/utils/pull/826, which I plan to do soon