mb-p256

NIST P-256 elliptic curve (secp256r1) for MoonBit: ECDSA and ECDH

crypto
p256
ecdsa
ecdh
secp256r1
elliptic-curve
moon add Tigls/mb-p256@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
3 months ago
Downloads
20

Dependencies

README

#
AffinePoint

pub struct AffinePoint {
x : FixedArray[UInt]
y : FixedArray[UInt]
infinity : Bool
}
Affine point: (x, y) or identity

#
ECDSAKeyPair

pub struct ECDSAKeyPair {
private_key : Array[UInt]
public_key : Array[UInt]
}
ECDSA key pair.

#
ECDSASignature

pub(all) struct ECDSASignature {
r : Array[UInt]
s : Array[UInt]
}
ECDSA signature (r, s) each 32 bytes big-endian.

#
ProjectivePoint

pub struct ProjectivePoint {
x : FixedArray[UInt]
y : FixedArray[UInt]
z : FixedArray[UInt]
}
Projective point: (X : Y : Z) where affine (x, y) = (X/Z, Y/Z) Identity point: (0 : 1 : 0)

#
derive_public_key

fn derive_public_key(private_key : Array[UInt]) -> Result[Array[UInt], String]
Derive public key from private key (32 bytes -> 65 bytes uncompressed).

#
ecdh

fn ecdh(private_key : Array[UInt], peer_public_key : Array[UInt]) -> Result[Array[UInt], String]
Compute ECDH shared secret (32 bytes, x-coordinate of the shared point).

#
ecdh_bytes

fn ecdh_bytes(private_key : Bytes, peer_public_key : Bytes) -> Result[Bytes, String]
Compute ECDH shared secret (Bytes API).

#
ecdsa_keygen

fn ecdsa_keygen(private_key_bytes : Array[UInt]) -> Result[ECDSAKeyPair, String]
Generate key pair from a 32-byte private key.

#
ecdsa_keygen_bytes

fn ecdsa_keygen_bytes(private_key : Bytes) -> Result[ECDSAKeyPair, String]
Bytes API wrappers

#
ecdsa_sign

fn ecdsa_sign(private_key : Array[UInt], message_hash : FixedArray[UInt]) -> Result[ECDSASignature, String]
Sign a message hash using ECDSA with RFC 6979 deterministic nonce.

#
ecdsa_sign_bytes

fn ecdsa_sign_bytes(private_key : Bytes, message : Bytes) -> Result[ECDSASignature, String]

#
ecdsa_sign_message

fn ecdsa_sign_message(private_key : Array[UInt], message : Array[UInt]) -> Result[ECDSASignature, String]
Sign a message (not pre-hashed) using ECDSA. Hashes with SHA-256 first.

#
ecdsa_verify

fn ecdsa_verify(public_key : Array[UInt], message_hash : FixedArray[UInt], signature : ECDSASignature) -> Result[Bool, String]
Verify an ECDSA signature against a message hash and public key.

#
ecdsa_verify_bytes

fn ecdsa_verify_bytes(public_key : Bytes, message : Bytes, signature : ECDSASignature) -> Result[Bool, String]

#
ecdsa_verify_message

fn ecdsa_verify_message(public_key : Array[UInt], message : Array[UInt], signature : ECDSASignature) -> Result[Bool, String]
Verify an ECDSA signature against a message (not pre-hashed).

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io