mingchen/whirlpoolswift
The WHIRLPOOL hash function implemented in Swift. This Swift wrapper encapsulates the WHIRLPOOL reference implementation.
Usage
Import this package through Swift Package Manager. Add the following dependency to your Package.swift file:
// Select a package version:
.package(url: "https://github.com/mingchen/WhirlpoolSwift.git", from: "1.0.0")
// Select a product: WhirlpoolSwift
.product(name: "WhirlpoolSwift", package: "whirlpoolswift")Code Examples
import WhirlpoolSwift
let data1: Data = ...
let data2: Data = ...
var whirlpool = Whirlpool()
whirlpool.update(data: data1)
whirlpool.update(data: data2)
let digest = whirlpool.finalize() // 64 bytes digestAlternatively, for minimal data, in a single line.
import WhirlpoolSwift
let input = "The quick brown fox jumps over the lazy dog"
let digest = Whirlpool.hash(data: input.data(using: .utf8)!) // 64 bytes digestThe function
WHIRLPOOL uses Merkle-Damgård strengthening and the Miyaguchi-Preneel hashing scheme with a dedicated 512-bit block cipher called W. This consists of the following. The bit string to be hashed is padded with a &lquo;'1'-bit, then with a sequence of '0'-bits, and finally with the original length (in the form of a 256-bit integer value), so that the length after padding is a multiple of 512 bits. The resulting message string is divided into a sequence of 512-bit blocks m1, m2, ... mt which is then used to generate a sequence of intermediate hash values H0, H1, H2, ... Ht. By definition, H0 is a string of 512 '0'-bits. To compute Hi, W encrypts mi using Hi-1 as key, and XORs the resulting ciphertext with both Hi-1 and mi. Finally, the WHIRLPOOL message digest is Ht.
[MiyaguchiPreneel Hash]
The Name
The WHIRLPOOL hashing function is named after the Whirlpool galaxy in Canes Venatici (M51, or NGC 5194), the first one recognized to have spiral structure by William Parsons, third Earl of Rosse, in April 1845 (cf. M. Hoskin, "The Cambridge Illustrated History of Astronomy," Cambridge University Press, 1997).
License
Public domain. See LICENSE.
References
- https://web.archive.org/web/20171129084214/http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html
Package Metadata
Repository: mingchen/whirlpoolswift
Default branch: main
README: README.md