SHA3FINAL224, SHA3FINAL256, SHA3FINAL384, and SHA3FINAL512

Use a token initialized by the corresponding SHA3INIT function to complete a SHA-3 hash of a series of texts and return a CHAR string with that hash value.

Read syntax diagramSkip visual syntax diagramSHA3FINALx( t, p, n)
t
A token returned by a previous invocation of SHA3INITx or SHA3UPDATEx.
p
A pointer that specifies the address of a buffer to be added to the hash.
n
An expression that specifies the length (in bytes) of that buffer. It must have a computational type and will be converted to type size_t.

The length returned is one eighth of the bit length in the function name, so, for example, SHA3FINAL256 returns a CHAR(32) value.

These functions generate code that executes the KIMD and KLMD assembler instructions.

Examples

The following example performs a 512-bit SHA-3 hash of a file that is read one line at a time into a CHARACTER variable c.

        dcl token     pointer;
        dcl encoded   char(64);
        token = sha3init512();
        on endfile(input);
        do loop;
          read file(input) into(c);
          if endfile(input) then leave;
          token = sha3update512(token, addrdata(c), length(c));
        end;
        encoded = sha3final512(token, sysnull(), 0);

In above example, all the SHA function calls are in the same block of code. This is not necessary: the calls can occur in a set of routines as long as they all use the same token created by the SHA3INIT call.