sha512() - > Bytes- Module
- std.
bytes - Receiver
- Bytes
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.bytes in language mode 5.21.
The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 52 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 519 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 229
Receiver
Bytes
Parameter constraints
Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.
CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.
Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.
Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.
HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.
Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.
These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.
The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.
Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.
Related rule: Compute interoperable checksums and digestsResult
The declared result type is Bytes.
Effects
Failures
Result and effects
LinkReturn the 64-byte SHA-512 digest of the exact receiver bytes.
Resolved contracts
LinkRelated entries
LinkCompute interoperable checksums and digests
LinkCompute interoperable checksums and digests
Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.
CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.
Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.
Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.
HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.
Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.
These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.
The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.
Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.
Why
Named standard algorithms must agree with independent implementations. Keeping digest bytes separate from their text representation makes the same digest usable in binary and text formats.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 22 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 947 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1042 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1158 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2963 -
topaz.stdlib.contract.bytes-digestsatworking-tree
Match established checksum and hash vectors
Linkimport std.bytes { Bytes }import std.ioio.writeLine("{Bytes.empty().crc32()}")let checksum = "123456789".encodeUtf8().crc32()io.writeLine("{checksum}")io.writeLine("abc".encodeUtf8().sha256().toHex())io.writeLine("abc".encodeUtf8().sha512().toHex())io.writeLine("key".encodeUtf8().hmacSha256("The quick brown fox jumps over the lazy dog".encodeUtf8()).toHex())
0 3421780262 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
Expected result
Expected result
Execution completes. Exit code 0.
03421780262ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49ff7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 22 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 947 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1042 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 1158 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2963 -
topaz.stdlib.contract.bytes-digestsatworking-tree