class

Beryl::Crypto::V1::EllipticCurveP256::PrivateKey

Inherits Reference < Object

A private key: a secret scalar d in [1, n - 1].

Constructors

generate

Returns a new key drawn from Random::Secure by rejection sampling (FIPS 186-5 Appendix A.2.2).

Source
new(scalar : Bytes)

Keeps a copy of the big-endian scalar scalar. Raises KeySizeMismatch for the wrong length and InvalidPrivateKey for zero or a value not below n.

Source

Instance methods

finalize
Source
public_key
shared_secret(peer : PublicKey) : Bytes

Returns the ECDH shared secret with peer: the x coordinate of [d]Q, Arithmetic::BYTESIZE big-endian bytes (SEC 1 §3.3.1; RFC 9846 §7.4.2). peer was checked to be on the curve when it was decoded, and the group has prime order, so the result is never the point at infinity.

Source
sign(message : Bytes | String, *, format : SignatureFormat = SignatureFormat::DER) : Bytes

Returns the ECDSA signature of message hashed with SHA256, with the RFC 6979 nonce.

Source
sign_digest(digest : Bytes, hash_function : D.class, *, format : SignatureFormat = SignatureFormat::DER) : Bytes forall D

Returns the ECDSA signature of a message whose hash, computed with hash_function, is digest; the RFC 6979 nonce uses HMAC with the same hash.

Source
to_slice

Returns a copy of the big-endian scalar.

Source