crypto_kppClass
Lua interface to ECDH key agreement.
An object holds one private key, set at creation and held by the kernel’s transform alone: the binding keeps no copy of it, and the transform is freed zeroed. Keys and secrets are the kernel’s big-endian bytes, each scalar or coordinate of the curve’s size, 32 bytes for P-256: a public key isx || y, the SEC1 uncompressed point without its leading 0x04, and a shared secret is the x
coordinate of the product, the raw ECDH output a KDF such as crypto.hkdf takes. The shared
secret is a Lua string, which Lua does not zero when it collects it, nor the private key a script
passes to the constructor: a key the kernel generates never is one.
Methods
| crypto_kpp:algname () | Returns the driver-independent name of the algorithm the transform was allocated with. |
| crypto_kpp:close () | Releases the transform and the private key it holds. |
| crypto_kpp:publickey () | Returns the public key, twice the curve’s size: 64 bytes for P-256. |
| crypto_kpp:sharedsecret (peer) | Agrees a secret with a peer’s public key. |
Methods in detail
- crypto_kpp:algname ()
-
Returns the driver-independent name of the algorithm the transform was allocated with.
Returns
- crypto_kpp:close ()
-
Releases the transform and the private key it holds.
A to-be-closed variable holding the object releases it the same way. Calling it again does
nothing, and every other method raises “closed object” afterwards.
Returns
-
nil
- crypto_kpp:publickey ()
-
Returns the public key, twice the curve’s size: 64 bytes for P-256.
Returns
-
string
x || yRaises
the errno of a kernel failure, “EIO” for an engine’s status that is not an errno, “not enough memory” when the binding cannot allocate the key -
Agrees a secret with a peer’s public key.
A key the curve refuses is the peer’s, not the script’s mistake, so it is an outcome and not an
error, and no part of a secret is returned for it. The binding checks the key before the transform
sees it, so no driver computes with one the curve refuses, a hardware engine included.
Parameters
Returns
-
string
the shared secret, of the curve’s size, or nil and “EINVAL” for a key of another
length than publickey’s, a point off the curve or the point at infinity
Raises
the errno of a kernel failure, “EIO” for an engine’s status that is not an errno, “not enough memory” when the binding cannot allocate the secret