Usage example

This library consists of two sub libraries: KeccakC and KeccakSwift

While the first one is just CocoaPod / SPM wrapper for C library, the other one wraps the first to provide Swift interface.

There is only one single static function where you can pass your data to hash, algorithm with its rate and desired output size:

let data: Data

// Keccak has only one rate: .rate256
// Common Keccak output size bits in crypto: 
//  - 224
//  - 256
//  - 288
//  - 384
//  - 512
// While other sizes potentially should work, 
// they're not used in crypto and not recommended unless you know what you do
let result = Keccak.hash(data: data, rate: .keccak(.rate256), outputSize: .bits(224)) 

While we do not use other algorithms like SHAKE and SHA3 directly from this library, they were added for consistency to proxy all available functions from KeccakC:

let data: Data

let result = Keccak.hash(data: data, rate: .shake(.rate128), outputSize: .bytes(64)) 
let result = Keccak.hash(data: data, rate: .shake(.rate256), outputSize: .bytes(64))

let result = Keccak.hash(data: data, rate: .sha3(.rate224), outputSize: .bytes(64)) 
let result = Keccak.hash(data: data, rate: .sha3(.rate256), outputSize: .bytes(64))
let result = Keccak.hash(data: data, rate: .sha3(.rate384), outputSize: .bytes(64)) 
let result = Keccak.hash(data: data, rate: .sha3(.rate512), outputSize: .bytes(64))

Output size of 64 bytes is just provided for example, you're free to provide any desired output size either in bits or bytes.

Last updated