3d: SHA Hash Family
+shad
+shadDouble SHA-256.
Produces an $atom that is twice-hashed with +shax, the SHA-256 cryptographic hash algorithm.
Accepts
.ruz is an $atom.
Produces
An $atom.
Source
++ shad |=(ruz=@ (shax (shax ruz)))Examples
> `@uw`(shad 11)
0w2Rt.J1gzO.JjsQc.0Komy.DYUUO.27koh.QxwE0.Qgwt7.EPGCi+shaf
+shafHalf SHA-256.
Produces a 128-bit $atom by performing the bitwise XOR on the first and last halves of the 256-bit salted hash +shas.
Accepts
.sal is an $atom.
.ruz is an $atom.
Source
Examples
+sham
+sham128-bit $noun hash.
Produces a 128-bit $atom by hashing a $noun .yux with the +shaf function. If that $noun is a cell, then it is passed to the +jam function to produce an $atom to be hashed.
Accepts
.yux is a $noun.
Produces
A @uvH.
Source
Examples
+shas
+shasSalted hash.
Produces an $atom by using SHA-256 plus a salt input. The bitwise XOR is performed on salt +sal and the product of $atom .ruz hashed with SHA-256. The product of that logical operation is then itself hashed with SHA-256.
Accepts
.sal is an $atom.
.ruz is an $atom.
Source
Examples
+shax
+shaxSHA-256.
Produces an $atom by hashing an $atom .ruz with SHA-256.
Sources
Examples
+shay
+shaySHA-256 with length.
Produces an $atom by hashing an $atom .ruz with SHA-256. Another $atom, .len, is the byte-length of the theoretical buffer represented by the $atom.
Accepts
.len is an $atom.
.ruz is an $atom.
Source
Examples
Discussion
Because byte-strings can have leading zeros, but $atoms cannot, we use .len as a way of saying that the $atom .ruz is shorter than its representative byte-string.
+shaw
+shawHash to nbits.
Produces an $atom of .len random bits by hashing .ruz with the salted SHA-256 hash algorithm, where .sal is the cryptographic salt.
Accepts
.sal is an $atom.
.len is an $atom.
.ruz is an $atom.
Produces
An $atom.
Source
Examples
+shaz
+shazSHA-512.
Produces an $atom by hashing an $atom .ruz with SHA-512.
Accepts
.ruz is an $atom.
Produces
An $atom.
Source
Examples
+shal
+shalSHA-512 with length.
Produces an $atom by hashing an $atom .ruz with SHA-512. Another $atom, .len, is the byte-length of the theoretical buffer represented by the $atom.
Accepts
.len is an $atom.
.ruz is an $atom.
Produces
An $atom.
Source
Examples
Discussion
Because byte-strings can have leading zeros, but $atoms cannot, we use .len as a way of saying that the $atom .ruz is shorter than its representative byte-string.
+shan
+shanSHA-1.
Produces an $atom by hashing an $atom .ruz with SHA-1.
Accepts
.ruz is an $atom.
Produces
An $atom.
Source
Examples
Discussion
SHA-1 is a deprecated function; it is not considered secure.
+og
+ogContainer arm for SHA-256-powered random-number generation. Its sample .a is an $atom that is used as a seed for the hash.
Accepts
.a is an $atom.
Produces
A core.
Source
Examples
Discussion
Note that the product is deterministic; the seed will produce the same result every time it is run. Use .eny, 256 bits of entropy, for a non-deterministic product.
+rad:og
+rad:ogRandom in range.
Produces a random number that is within the range of first .b whole numbers, starting at 0.
Accepts
.b is an $atom.
Produces
An $atom.
Source
Examples
+rads:og
+rads:ogRandom continuation.
Produces a cell. The head of the cell is a random number that is within the range of first .b whole numbers, starting at 0. The tail is a new core produced from hashing the parent core with (rad b).
Accepts
.b is an $atom.
Produces
A cell.
Source
Examples
Discussion
Since everything in Hoon is a pure function, we need to use tricks like this to generate separate random values from the same seed. Notice how we jump from one +rads:rng function call to another in the above example.
+raw:og
+raw:ogRandom bits.
Produces an $atom with a bitwidth .b that is composed of random bits.
Accepts
.b is an $atom.
Produces
An $atom.
Source
Examples
+raws:og
+raws:ogRandom bits continuation.
Produces a cell. The head of the cell is an $atom with a bitwidth .b that is composed of random bits. The tail is a new core produced from hashing the parent core with (raw b).
Source
Examples
Discussion
Since everything in Hoon is a pure function, we need to use tricks like this to generate separate random values from the same seed. Notice how we jump from one +raws function call to another in the above example.
Last updated