If you break SHA-3 away from its fixed length output you get an EXtendable Output Function (XOF). This now has the potential of producing an almost infinite sets of outputs, and where we could thus take a single byte and produce an output of a billion bytes, or even take a billion bytes of input and produce a single byte output. In essence, it is a state generator, and where with given inputs we can reach a well-defined state. We can expose the state to anyone, as they will not know the secrets that allow us to take us to the previous and the next state. This page outlines the SHAKE method [article]. In this case we will use Go to implement SHAKE:
SHAKE n Go |
Test vectors
The following is a test run for eight bytes
Input word: hello123 Length (bytes): 8 -----SHAKE----- Shake 128 bit: 1b85861510bc4d8e Shake 256 bit: ade612ba265f92de
Code
The following is an outline of the code:
package main import( "fmt" "golang.org/x/crypto/sha3" "os" "strconv" ) func main(){ str1:="abc" length:=8 argCount := len(os.Args[1:]) if (argCount>0) {str1 = string(os.Args[1])} if (argCount>1) {length,_ = strconv.Atoi(os.Args[2])} buf := []byte(str1) h := make([]byte, length) sha3.ShakeSum128(h, buf) fmt.Printf("Shake 128: %x\n", h) sha3.ShakeSum256(h, buf) fmt.Printf("Shake 256: %x\n", h) }
Presentation
The following is a presentation on SHA-3, SHAKE and Keccak [slides]: