ddn.crypto.hash.sha

SHA-1 and SHA-2 hash implementations.

This module provides SHA-1 (legacy) and SHA-2 (SHA-256, SHA-384, SHA-512) hash implementations. SHA-1 is deprecated and should not be used for security-critical purposes; SHA-256 and SHA-512 are recommended for all new code.

Types 9

SHA-1 secure hash algorithm (RFC 3174).

DEPRECATED — Do not use for security-critical purposes.

SHA-1 is no longer considered collision-resistant. NIST deprecated it in 2011, and practical collision attacks have been demonstrated since 2017 (SHAttered). SHA-1 must not be used for digital signatures, certificate generation, or any application that relies on collision resistance.

Acceptable legacy uses include HMAC construction (where collision resistance of the underlying hash is not required), non-security checksums, and compatibility with existing protocols that mandate SHA-1. Even in those cases, consider migrating to SHA-256 at the earliest opportunity.

See Also

SHA256Digest, SHA512Digest
Fields
private uint[5] _state
private ulong _count
private ubyte[64] _buffer
Methods
Hash update(const(ubyte)[] input)
ubyte[] finish()
void reset()
size_t blockSize() @property const
size_t size() @property const
private void transform(const(ubyte)[] block)
private uint rotateLeft(uint x, uint n) pure nothrow @nogc
Constructors

SHA-256 implementation (FIPS 180-4).

Fields
private uint[8] _state
private ulong _count
private ubyte[64] _buffer
private uint[64] K
Methods
void reset()
Hash update(const(ubyte)[] input)
ubyte[] finish()
size_t blockSize() @property const
size_t size() @property const
private void transform(const(ubyte)[] block)
private uint rotateRight(uint x, uint n) pure nothrow @nogc
Constructors

SHA-512 implementation (FIPS 180-4).

Fields
private ulong[8] _state
private ulong[2] _count
private ubyte[128] _buffer
private ulong[80] K
Methods
void reset()
Hash update(const(ubyte)[] input)
ubyte[] finish()
size_t blockSize() @property const
size_t size() @property const
private void transform(const(ubyte)[] block)
private ulong rotateRight(ulong x, uint n)
Constructors

SHA-384 implementation (FIPS 180-4).

SHA-384 uses the same algorithm as SHA-512 but with different initial values and the output is truncated to 48 bytes.

Fields
private ulong[8] _state
private ulong[2] _count
private ubyte[128] _buffer
private ulong[80] K
Methods
void reset()
Hash update(const(ubyte)[] input)
ubyte[] finish()
size_t blockSize() @property const
size_t size() @property const
private void transform(const(ubyte)[] block)
private ulong rotateRight(ulong x, uint n)
Constructors
classSHA3Digest(int bits) : Hash

SHA-3 (Keccak) Digest Implementation.

Fields
private ulong[25] _state
private ubyte[] _buffer
private size_t _rateBytes
private size_t _outputBytes
private size_t _byteIndex
private ulong[24] RC
private int[5][5] RHO_OFFSETS
Methods
void reset()
Hash update(const(ubyte)[] input)
ubyte[] finish()
size_t blockSize() @property const
size_t size() @property const
private void processBlock(const(ubyte)[] block)
private void keccakF1600(ref ulong[25] A) pure nothrow @nogc
private ulong rotl64(ulong x, int n) pure nothrow @nogc
Constructors

SHA3-224

SHA3-256

SHA3-384

SHA3-512