crypto_sigClass
Lua interface to public key signature verification.
A verifier takes a public key with setpubkey, then answers whether a signature over a digest verifies. It does not sign.Methods
| crypto_sig:algname () | Returns the driver-independent name of the algorithm the transform was allocated with. |
| crypto_sig:close () | Releases the transform. |
| crypto_sig:maxsize () | Returns the size in bytes the kernel gives for a signature under the key: the key’s for RSA,
the DER bound for x962(...) and twice the key’s for p1363(...). |
| crypto_sig:setpubkey (key) | Sets the public key, in the algorithm’s own encoding: ECDSA takes the uncompressed point,
0x04 || x || y, 65 bytes for P-256; RSA takes the DER RSAPublicKey,
SEQUENCE { n INTEGER, e INTEGER }. |
| crypto_sig:verify (signature, digest) | Verifies a signature over a digest. |
Methods in detail
- crypto_sig:algname ()
-
Returns the driver-independent name of the algorithm the transform was allocated with.
Returns
- crypto_sig:close ()
-
Releases the transform.
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_sig:maxsize ()
-
Returns the size in bytes the kernel gives for a signature under the key: the key’s for RSA,
the DER bound for
x962(...)and twice the key’s forp1363(...). On 6.12 and earlier ECDSA answers the key’s size, 32 for P-256, which a DER signature exceeds.Returns
-
integer
Raises
“ENOKEY” before a setpubkey succeeds - crypto_sig:setpubkey (key)
-
Sets the public key, in the algorithm’s own encoding: ECDSA takes the uncompressed point,
0x04 || x || y, 65 bytes for P-256; RSA takes the DERRSAPublicKey,SEQUENCE { n INTEGER, e INTEGER }. A key that fails leaves the verifier without one.Parameters
- key string
Raises
“EINVAL” for a key the algorithm refuses, such as a compressed or off-curve point, a point of another length or a modulus of a size RSA does not take, “EBADMSG” for a DER key that does not parse - crypto_sig:verify (signature, digest)
-
Verifies a signature over a digest.
The answer is the kernel’s verdict on the two strings, so a signature a peer sent raises only
for a length out of bounds. ECDSA pads or truncates a digest of another size than the curve’s.
Parameters
- signature string the signature in the algorithm’s encoding, of at most 65535 bytes
- digest string the digest the signature was made over, of 1 to 65535 bytes
Returns
-
boolean
true when the signature verifies, or false and the errno’s name:
“EKEYREJECTED” for a signature that does not verify the digest, “EBADMSG” for one that does
not parse, “EINVAL” for a length the algorithm cannot take or a DER integer longer than the
curve
Raises
“ENOKEY” before a setpubkey succeeds, “ENOSYS” for an algorithm that does not verify, such asrsaon 6.12 and earlier, “ENOMEM”, and “out of bounds” for a string of a length out of bounds