dauth.sha

This has been temporarily added to DAuth since it doesn't exist in Phobos before DMD 2.066: https://github.com/D-Programming-Language/phobos/pull/2129

On DMD 2.066 and up, DAuth uses std.digest.sha *instead* of this module.

Main module: dauth

Computes SHA1 and SHA2 hashes of arbitrary data. SHA hashes are 20 to 64 byte quantities (depending on the SHA algorithm) that are like a checksum or CRC, but are more robust.

SHA2 comes in several different versions, all supported by this module: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.

This module conforms to the APIs defined in std.digest.digest. To understand the differences between the template and the OOP API, see std.digest.digest.

This module publicly imports std.digest.digest and can be used as a stand-alone module.

Public Imports

std.digest.digest
public import std.digest.digest;
Undocumented in source.

Members

Aliases

SHA1
alias SHA1 = SHA!(512, 160)
Undocumented in source.
SHA1Digest
alias SHA1Digest = WrapperDigest!SHA1

OOP API SHA1 and SHA2 implementations. See std.digest.digest for differences between template and OOP API.

SHA224
alias SHA224 = SHA!(512, 224)
Undocumented in source.
SHA224Digest
alias SHA224Digest = WrapperDigest!SHA224
Undocumented in source.
SHA256
alias SHA256 = SHA!(512, 256)
Undocumented in source.
SHA256Digest
alias SHA256Digest = WrapperDigest!SHA256
Undocumented in source.
SHA384
alias SHA384 = SHA!(1024, 384)
Undocumented in source.
SHA384Digest
alias SHA384Digest = WrapperDigest!SHA384
Undocumented in source.
SHA512
alias SHA512 = SHA!(1024, 512)
Undocumented in source.
SHA512Digest
alias SHA512Digest = WrapperDigest!SHA512
Undocumented in source.
SHA512_224
alias SHA512_224 = SHA!(1024, 224)
Undocumented in source.
SHA512_224Digest
alias SHA512_224Digest = WrapperDigest!SHA512_224
Undocumented in source.
SHA512_256
alias SHA512_256 = SHA!(1024, 256)
Undocumented in source.
SHA512_256Digest
alias SHA512_256Digest = WrapperDigest!SHA512_256
Undocumented in source.

Functions

sha1Of
auto sha1Of(T data)
sha224Of
auto sha224Of(T data)
sha256Of
auto sha256Of(T data)
sha384Of
auto sha384Of(T data)
sha512Of
auto sha512Of(T data)
sha512_224Of
auto sha512_224Of(T data)
sha512_256Of
auto sha512_256Of(T data)

These are convenience aliases for std.digest.digest.digest using the SHA implementation.

Structs

SHA
struct SHA(int blockSize, int digestSize)

Template API SHA1/SHA2 implementation. Supports: SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.

Examples

t
{
    //Template API
    ubyte[20] hash1 = sha1Of("abc");
    assert(toHexString(hash1) == "A9993E364706816ABA3E25717850C26C9CD0D89D");

    ubyte[28] hash224 = sha224Of("abc");
    assert(toHexString(hash224) == "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7");

    //Feeding data
    ubyte[1024] data;
    SHA1 sha1;
    sha1.start();
    sha1.put(data[]);
    sha1.start(); //Start again
    sha1.put(data[]);
    hash1 = sha1.finish(
t
{
    //OOP API
    auto sha1 = new SHA1Digest();
    ubyte[] hash1 = sha1.digest("abc");
    assert(toHexString(hash1) == "A9993E364706816ABA3E25717850C26C9CD0D89D");

    auto sha224 = new SHA224Digest();
    ubyte[] hash224 = sha224.digest("abc");
    assert(toHexString(hash224) == "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7");

    //Feeding data
    ubyte[1024] data;
    sha1.put(data[]);
    sha1.reset(); //Start again
    sha1.put(data[]);
    hash1 = sha1.finish(

Meta

License

<a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>

CTFE: Digests do not work in CTFE

Authors

The routines and algorithms are derived from the Secure Hash Signature Standard (SHS) (FIPS PUB 180-2).
Kai Nacke, Johannes Pfau, Nick Sabalausky

References: