k12
Computes a KangarooTwelve (K12) hash of arbitrary input bytes, returning a Uint8Array of the requested output length.
Qubic uses KangarooTwelve (K12) as its hash function. K12 is derived from the Keccak sponge construction — the same family as SHA-3 — but uses a reduced round count (12 rounds instead of 24) and adds tree hashing for parallelism. Do not confuse K12 with Ethereum's keccak256: they share a common ancestor but produce completely different outputs.
Signature
K12(input: Uint8Array, outputLength?: number): Uint8ArrayPurpose
Computes a K12 hash of arbitrary input bytes.
import { K12 } from "@qubic.org/crypto"
const input = new TextEncoder().encode("hello qubic")
const hash = K12(input) // Uint8Array, 32 bytes (default)
const longHash = K12(input, 64) // Uint8Array, 64 bytesParameters
| Name | Type | Default | Description |
|---|---|---|---|
input | Uint8Array | — | Bytes to hash |
outputLength | number | 32 | Number of output bytes to produce |
Returns
Uint8Array of length outputLength.
K12 vs SHA-3
Both originate from the Keccak sponge construction but differ in their parameters:
| K12 | SHA-3 | |
|---|---|---|
| Round function | Keccak-p[1600, 12] | Keccak-p[1600, 24] |
| Tree hashing | Yes | No |
| Customization string | Yes | No |
| Standardized by | IETF (RFC 8702) | NIST (FIPS 202) |
Never substitute SHA-3 or keccak256 for K12 in Qubic computations — the outputs differ.
Most SDK consumers never call K12 directly. It runs internally inside publicKeyFromSeed, signTransaction, computeTransactionHash, and verifyTransactionSignature. Call it directly when building a custom transaction type outside the SDK, verifying a message hash against a known value, or computing a checksum over raw Qubic binary data.