const-crypto
A #[no_std] library for const sha2/sha3 hashing, ed25519 off-curve point evaluation, and bs58 decoding/encoding with minimal dependencies.
Features
- We write a
constimplementation of Edwards point decompression and use it to provide aconstimplementation of on/off curve evaluation. This is then used to build aconstimplementation of Solana'sPubkey::find_program_address. NOTE: this point decompression implementation is not cryptographically safe; it does not use constant time implementations for the internal math operations, as it is not intended to be used with secrets. Do not reuse. - Base58 encoding of 32 byte arrays into strings (and vice versa, i.e. decoding). The encoding is taken from
fd_bs58, and adapted forconst/`#[no_std] with some bug fixes. - Full sha2/sha3 hash suites. Re-exports of
sha2-const-stable(authored by yours truly) andkeccak-const(authored by OffChainLabs)
Usage
The file examples/pda.rs concisely demonstrates all functionality:
use ;
/// Uses const bs58 to roundtrip (decode + encode) system_program ID
pub const PROGRAM_KEY: = decode_pubkey;
pub const PROGRAM_KEY_STR: &'static str = encode_pubkey.str;
const _: = assert!;
/// Uses const ed25519 (and thus const sha2 internally)
pub const PROGRAM_DERIVED_ADDRESS: =
derive_program_address.0;
// the address is off curve
const _: = assert!;
/// A utility function used to show round trip is correct
pub const