Skip to main content

Module crypto

Module crypto 

Source
Expand description

COSE key parsing and signature verification (ES256 / RS256) via ring, plus base64url helpers and CSPRNG challenge generation.

§Security

  • All cryptographic primitives come from ring (constant-time ECDSA/RSA verification). This crate contains no hand-rolled cryptography; the only custom encoding is RFC 5280 DER wrapping of already-validated RSA modulus/exponent byte strings, which never touches secret material.
  • Signature verification is constant-result: on failure the payload and signature are discarded and only an error variant is returned.

Enums§

CosePublicKey
Parsed COSE public key (EC2 or RSA).

Constants§

COSE_ALG_ES256
COSE algorithm: ECDSA w/ SHA-256 on P-256.
COSE_ALG_RS256
COSE algorithm: RSASSA-PKCS1-v1_5 w/ SHA-256.
COSE_KTY_EC2
COSE key type: Elliptic-Curve key pair with x/y coordinates.
COSE_KTY_OKP
COSE key type: Octet Key Pair (Ed25519 et al.). Not supported.
COSE_KTY_RSA
COSE key type: RSA key.

Functions§

alg_to_name
Convert a COSE algorithm ID to a human-readable name.
base64_decode_urlsafe
Base64url decode (RFC 4648 §5, no padding required; standard alphabet with padding is also accepted by the engine’s forgiving handling).
base64_encode_urlsafe
Base64url encode (RFC 4648 §5, no padding), as required by the WebAuthn JSON serialization conventions.
cbor_bytes
Extract a CBOR byte string from a value.
cbor_map_entries
Parse a CBOR map into ordered (i64, Value) entries.
generate_challenge_bytes
Generate 32 random bytes (256 bits of entropy) for a WebAuthn challenge.
parse_cose_key
Parse a COSE key from its CBOR encoding (RFC 9052).
verify_cose_signature
Verify a COSE signature using the parsed public key.