ztcl::crypto
Gives SHA-256, SHA-384, and SHA-512 hashes and HMACs of bytes, checks Ed25519 and ECDSA P-256 signatures, and signs bytes with an Ed25519 seed.
ztcl::crypto SUBCOMMAND ?ARG ...?
Description
The hash and signature commands of std.crypto for a script: hash gives a SHA-2 digest, hmac gives an HMAC, verify checks an Ed25519 signature or an ECDSA signature on P-256 with SHA-256, sign makes an Ed25519 signature with a given seed, and pubkey gives the public key of a seed.
Load the module with package require ztcl::crypto. It needs no capability: each command is a pure function of its arguments and reads no entropy. Each argument and each result is a byte string, as binary gives it. Each subcommand is also the command ztcl::crypto::NAME.
Subcommands
| Subcommand | Description |
|---|---|
ztcl::crypto verify | Checks the signature of a message. |
ztcl::crypto sign | Signs a message with an Ed25519 seed. |
ztcl::crypto pubkey | Gives the public key of an Ed25519 seed. |
ztcl::crypto hash | Gives the SHA-256, SHA-384, or SHA-512 digest of bytes. |
ztcl::crypto hmac | Gives the HMAC of bytes with a key. |
Returns
The result of the subcommand.
Examples
Each example of this page runs after package require ztcl::crypto.
% set seed [binary decode hex 9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60]
> set sig [ztcl::crypto sign ed25519 $seed hello]
> ztcl::crypto verify ed25519 [ztcl::crypto pubkey ed25519 $seed] hello $sig
1
Errors
% ztcl::crypto bogus
unknown or ambiguous subcommand "bogus": must be hash, hmac, pubkey, sign, or verify
-errorcode TCL LOOKUP SUBCOMMAND bogus
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.10
- Compute cost
- One compute unit for each 4,096 bytes of the message, the data, and the key, and 64 more units for a signature command.
The full page: ztcl::crypto.