ztcl::crypto hash
Gives the SHA-256, SHA-384, or SHA-512 digest of bytes.
ztcl::crypto hash ALGORITHM DATA
Description
Gives the SHA-256, SHA-384, or SHA-512 digest (FIPS 180-4) of the bytes of DATA: 32, 48, or 64 bytes. Each character of DATA below 256 is one byte, as binary gives it.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ALGORITHM | string | required | sha256, sha384, or sha512. |
| DATA | bytes | required | The bytes to hash. |
Returns
The digest, as bytes.
Examples
Each example of this page runs after package require ztcl::crypto.
% binary encode hex [ztcl::crypto hash sha256 abc]
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
% string length [ztcl::crypto hash sha512 {}]
64
Errors
% ztcl::crypto hash md5 x
bad algorithm "md5": must be sha256, sha384, or sha512
-errorcode ZTCL CRYPTO ALG
% ztcl::crypto hash sha256
wrong # args: should be "ztcl::crypto hash algorithm data"
-errorcode TCL WRONGARGS
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.