WhirlpoolSwift

1.0.0

The WHIRLPOOL hash function implemented in Swift.
mingchen/WhirlpoolSwift

What's New

1.0.0

2023-12-03T19:41:33Z

Initial release.

WhirlpoolSwift

CI

The WHIRLPOOL hash function implemented in Swift. This Swift wrapper encapsulates the WHIRLPOOL reference implementation.

WHIRLPOOL is a hash function designed by Vincent Rijmen and Paulo S. L. M. Barreto that operates on messages less than 2256 bits in length, and produces a message digest of 512 bits.

WHIRLPOOL was adopted by the International Organization for Standardization (ISO) in the ISO/IEC 10118-3:2004 standard.

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 digest

Alternatively, 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 digest

The 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

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Apr 11 2024 22:48:47 GMT-0900 (Hawaii-Aleutian Daylight Time)