Add new hash API

* adds the new API used for hashes/digests
* adds new crc & md modules using this API
* deprecate std.md5 & crc32
* update std.stream to use new hash API
This commit is contained in:
Johannes Pfau 2012-07-01 15:24:11 +02:00
parent 94738ad5c9
commit 6ff6adc5bf
10 changed files with 2510 additions and 13 deletions

View file

@ -14,6 +14,8 @@
// CRC-32 calculation
module crc32;
pragma(msg, "The 'crc32' module has been scheduled for deprecation. Please use 'std.digest.crc' instead.");
private immutable uint[256] crc32_table =
[
0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,

View file

@ -54,7 +54,7 @@ DOCSRC = ../d-programming-language.org
WEBSITE_DIR = ../web
DOC_OUTPUT_DIR = $(WEBSITE_DIR)/phobos-prerelease
BIGDOC_OUTPUT_DIR = /tmp
SRC_DOCUMENTABLES = index.d $(addsuffix .d,$(STD_MODULES) $(STD_NET_MODULES) $(EXTRA_DOCUMENTABLES))
SRC_DOCUMENTABLES = index.d $(addsuffix .d,$(STD_MODULES) $(STD_NET_MODULES) $(STD_DIGEST_MODULES) $(EXTRA_DOCUMENTABLES))
STDDOC = $(DOCSRC)/std.ddoc
BIGSTDDOC = $(DOCSRC)/std_consolidated.ddoc
DDOCFLAGS=-m$(MODEL) -d -c -o- -version=StdDdoc -I$(DRUNTIME_PATH)/import $(DMDEXTRAFLAGS)
@ -162,6 +162,8 @@ STD_MODULES = $(addprefix std/, algorithm array ascii base64 bigint \
STD_NET_MODULES = $(addprefix std/net/, isemail curl)
STD_DIGEST_MODULES = $(addprefix std/digest/, digest crc md sha)
# OS-specific D modules
EXTRA_MODULES_LINUX := $(addprefix std/c/linux/, linux socket)
EXTRA_MODULES_OSX := $(addprefix std/c/osx/, socket)
@ -184,7 +186,7 @@ EXTRA_MODULES += $(EXTRA_DOCUMENTABLES) $(addprefix \
processinit uni uni_tab)
# Aggregate all D modules relevant to this build
D_MODULES = crc32 $(STD_MODULES) $(EXTRA_MODULES) $(STD_NET_MODULES)
D_MODULES = crc32 $(STD_MODULES) $(EXTRA_MODULES) $(STD_NET_MODULES) $(STD_DIGEST_MODULES)
# Add the .d suffix to the module names
D_FILES = $(addsuffix .d,$(D_MODULES))
# Aggregate all D modules over all OSs (this is for the zip file)
@ -310,6 +312,9 @@ $(DOC_OUTPUT_DIR)/std_c_windows_%.html : std/c/windows/%.d $(STDDOC)
$(DOC_OUTPUT_DIR)/std_net_%.html : std/net/%.d $(STDDOC)
$(DDOC) $(DDOCFLAGS) $(STDDOC) -Df$@ $<
$(DOC_OUTPUT_DIR)/std_digest_%.html : std/digest/%.d $(STDDOC)
$(DDOC) $(DDOCFLAGS) $(STDDOC) -Df$@ $<
$(DOC_OUTPUT_DIR)/etc_c_%.html : etc/c/%.d $(STDDOC)
$(DDOC) $(DDOCFLAGS) $(STDDOC) -Df$@ $<

533
std/digest/crc.d Normal file
View file

@ -0,0 +1,533 @@
/**
<script type="text/javascript">inhibitQuickIndex = 1</script>
$(BOOKTABLE ,
$(TR $(TH Category) $(TH Functions)
)
$(TR $(TDNW Template API) $(TD $(MYREF CRC32)
)
)
$(TR $(TDNW OOP API) $(TD $(MYREF CRC32Digest))
)
$(TR $(TDNW Helpers) $(TD $(MYREF crcHexString) $(MYREF crc32Of))
)
)
* Cyclic Redundancy Check (32-bit) implementation.
*
* This module conforms to the APIs defined in $(D std.digest.digest). To understand the
* differences between the template and the OOP API, see $(D std.digest.digest).
*
* This module publicly imports $(D std.digest.digest) and can be used as a stand-alone
* module.
*
* Note:
* CRCs are usually printed with the MSB first. When using $(XREF digest.digest, toHexString) the result
* will be in an unexpected order. Use $(XREF digest.digest, toHexString)s optional order parameter
* to specify decreasing order for the correct result. The $(LREF crcHexString) alias can also
* be used for this purpose.
*
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>
*
* Authors: Pavel "EvilOne" Minayev, Alex Rønne Petersen, Johannes Pfau
*
* References:
* $(LINK2 http://en.wikipedia.org/wiki/Cyclic_redundancy_check, Wikipedia on CRC)
*
* Source: $(PHOBOSSRC std/digest/_crc.d)
*
* Macros:
* WIKI = Phobos/StdUtilDigestCRC32
* MYREF = <font face='Consolas, "Bitstream Vera Sans Mono", "Andale Mono", Monaco, "DejaVu Sans Mono", "Lucida Console", monospace'><a href="#$1">$1</a>&nbsp;</font>
*
* Standards:
* Implements the 'common' IEEE CRC32 variant
* (LSB-first order, Initial value uint.max, complement result)
*
* CTFE:
* Digests do not work in CTFE
*
* Examples:
* ---------
* //Template API
* import std.digest.crc;
*
* ubyte[4] hash = crc32Of("The quick brown fox jumps over the lazy dog");
* assert(crcHexString(hash) == "414FA339");
*
* //Feeding data
* ubyte[1024] data;
* CRC32 crc;
* crc.put(data[]);
* crc.start(); //Start again
* crc.put(data[]);
* hash = crc.finish();
* ---------
*
* ---------
* //OOP API
* import std.digest.crc;
*
* auto crc = new CRC32Digest();
* ubyte[] hash = crc.digest("The quick brown fox jumps over the lazy dog");
* assert(crcHexString(hash) == "414FA339");
*
* //Feeding data
* ubyte[1024] data;
* crc.put(data[]);
* crc.reset(); //Start again
* crc.put(data[]);
* hash = crc.finish();
* ---------
*/
/*
* Copyright (c) 2001 - 2002
* Pavel "EvilOne" Minayev
* Copyright (c) 2012
* Alex Rønne Petersen
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module std.digest.crc;
public import std.digest.digest;
version(unittest)
import std.exception;
import std.bitmanip;
//verify example
unittest
{
//Template API
import std.digest.crc;
ubyte[4] hash = crc32Of("The quick brown fox jumps over the lazy dog");
assert(crcHexString(hash) == "414FA339");
//Feeding data
ubyte[1024] data;
CRC32 crc;
crc.put(data[]);
crc.start(); //Start again
crc.put(data[]);
hash = crc.finish();
}
//verify example
unittest
{
//OOP API
import std.digest.crc;
auto crc = new CRC32Digest();
ubyte[] hash = crc.digest("The quick brown fox jumps over the lazy dog");
assert(crcHexString(hash) == "414FA339"); //352441c2
//Feeding data
ubyte[1024] data;
crc.put(data[]);
crc.reset(); //Start again
crc.put(data[]);
hash = crc.finish();
}
private immutable uint[256] crc32_table =
[
0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,
0x9e6495a3,0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,
0xe7b82d07,0x90bf1d91,0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,
0x6ddde4eb,0xf4d4b551,0x83d385c7,0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,
0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,0x3b6e20c8,0x4c69105e,0xd56041e4,
0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,0x35b5a8fa,0x42b2986c,
0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,0x26d930ac,
0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,
0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,
0xb6662d3d,0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,
0x9fbfe4a5,0xe8b8d433,0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,
0x086d3d2d,0x91646c97,0xe6635c01,0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,
0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,0x65b0d9c6,0x12b7e950,0x8bbeb8ea,
0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,0x4db26158,0x3ab551ce,
0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,0x4369e96a,
0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,
0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,
0xce61e49f,0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,
0xb7bd5c3b,0xc0ba6cad,0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,
0x9dd277af,0x04db2615,0x73dc1683,0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,
0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1,0xf00f9344,0x8708a3d2,0x1e01f268,
0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,0xfed41b76,0x89d32be0,
0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,0xd6d6a3e8,
0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,
0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,
0x4669be79,0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,
0x220216b9,0x5505262f,0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,
0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,
0x9c0906a9,0xeb0e363f,0x72076785,0x05005713,0x95bf4a82,0xe2b87a14,0x7bb12bae,
0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21,0x86d3d2d4,0xf1d4e242,
0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,0x88085ae6,
0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,
0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,
0x3e6e77db,0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,
0x47b2cf7f,0x30b5ffe9,0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,
0xcdd70693,0x54de5729,0x23d967bf,0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,
0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d
];
/**
* Template API CRC32 implementation.
* See $(D std.digest.digest) for differences between template and OOP API.
*
* Examples:
* --------
* //Simple example, hashing a string using crc32Of helper function
* ubyte[4] hash = crc32Of("abc");
* //Let's get a hash string
* assert(crcHexString(hash) == "352441C2");
* --------
*
* --------
* //Using the basic API
* CRC32 hash;
* ubyte[1024] data;
* //Initialize data here...
* hash.put(data);
* ubyte[4] result = hash.finish();
* --------
*
* --------
* //Let's use the template features:
* //Note: When passing a CRC32 to a function, it must be passed by reference!
* void doSomething(T)(ref T hash) if(isDigest!T)
* {
* hash.put(cast(ubyte)0);
* }
* CRC32 crc;
* crc.start();
* doSomething(crc);
* assert(crcHexString(crc.finish()) == "D202EF8D");
* --------
*/
struct CRC32
{
private:
// magic initialization constants
uint _state = uint.max;
public:
/**
* Use this to feed the digest with data.
* Also implements the $(XREF range, OutputRange) interface for $(D ubyte) and
* $(D const(ubyte)[]).
*
* Examples:
* ----
* CRC32 dig;
* dig.put(cast(ubyte)0); //single ubyte
* dig.put(cast(ubyte)0, cast(ubyte)0); //variadic
* ubyte[10] buf;
* dig.put(buf); //buffer
* ----
*/
@trusted pure nothrow void put(scope const(ubyte)[] data...)
{
foreach (val; data)
_state = (_state >> 8) ^ crc32_table[cast(ubyte)_state ^ val];
}
/**
* Used to initialize the CRC32 digest.
*
* Note:
* For this CRC32 Digest implementation calling start after default construction
* is not necessary. Calling start is only necessary to reset the Digest.
*
* Generic code which deals with different Digest types should always call start though.
*
* Examples:
* --------
* CRC32 digest;
* //digest.start(); //Not necessary
* digest.put(0);
* --------
*/
@trusted pure nothrow void start()
{
this = CRC32.init;
}
/**
* Returns the finished CRC32 hash. This also calls $(LREF start) to
* reset the internal state.
*
* Examples:
* --------
* //Simple example
* CRC32 hash;
* hash.put(cast(ubyte)0);
* ubyte[4] result = hash.finish();
* --------
*/
@trusted pure nothrow ubyte[4] finish()
{
auto tmp = peek();
start();
return tmp;
}
/**
* Works like $(D finish) but does not reset the internal state, so it's possible
* to continue putting data into this CRC32 after a call to peek.
*/
@trusted pure nothrow ubyte[4] peek() const
{
//Complement, LSB first / Little Endian, see http://rosettacode.org/wiki/CRC-32
return nativeToLittleEndian(~_state);
}
}
//verify example
unittest
{
//Simple example, hashing a string using crc32Of helper function
ubyte[4] hash = crc32Of("abc");
//Let's get a hash string
assert(crcHexString(hash) == "352441C2");
}
//verify example
unittest
{
//Using the basic API
CRC32 hash;
ubyte[1024] data;
//Initialize data here...
hash.put(data);
ubyte[4] result = hash.finish();
}
//verify example
unittest
{
//Let's use the template features:
//Note: When passing a CRC32 to a function, it must be passed by referece!
void doSomething(T)(ref T hash) if(isDigest!T)
{
hash.put(cast(ubyte)0);
}
CRC32 crc;
crc.start();
doSomething(crc);
assert(crcHexString(crc.finish()) == "D202EF8D");
}
unittest
{
assert(isDigest!CRC32);
}
unittest
{
ubyte[4] digest;
CRC32 crc;
crc.put(cast(ubyte[])"abcdefghijklmnopqrstuvwxyz");
assert(crc.peek() == cast(ubyte[])x"bd50274c");
crc.start();
crc.put(cast(ubyte[])"");
assert(crc.finish() == cast(ubyte[])x"00000000");
digest = crc32Of("");
assert(digest == cast(ubyte[])x"00000000");
//Test vector from http://rosettacode.org/wiki/CRC-32
assert(crcHexString(crc32Of("The quick brown fox jumps over the lazy dog")) == "414FA339");
digest = crc32Of("a");
assert(digest == cast(ubyte[])x"43beb7e8");
digest = crc32Of("abc");
assert(digest == cast(ubyte[])x"c2412435");
digest = crc32Of("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
assert(digest == cast(ubyte[])x"5f3f1a17");
digest = crc32Of("message digest");
assert(digest == cast(ubyte[])x"7f9d1520");
digest = crc32Of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
assert(digest == cast(ubyte[])x"d2e6c21f");
digest = crc32Of("1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890");
assert(digest == cast(ubyte[])x"724aa97c");
assert(crcHexString(cast(ubyte[4])x"c3fcd3d7") == "D7D3FCC3");
}
/**
* This is a convenience alias for $(XREF digest.digest, digest) using the
* CRC32 implementation.
*
* Examples:
* ---------
* ubyte[4] hash = crc32Of("abc");
* assert(hash == digest!CRC32("abc")); //This is the same as above
* ---------
*/
//simple alias doesn't work here, hope this gets inlined...
auto crc32Of(T...)(T data)
{
return digest!(CRC32, T)(data);
}
/**
* This is a convenience alias for $(XREF digest.digest, toHexString) producing the usual
* CRC32 string output.
*/
public alias toHexString!(Order.decreasing) crcHexString;
///ditto
public alias toHexString!(Order.decreasing, 16) crcHexString;
//verify example
unittest
{
ubyte[4] hash = crc32Of("abc");
assert(hash == digest!CRC32("abc")); //This is the same as above
}
/**
* OOP API CRC32 implementation.
* See $(D std.digest.digest) for differences between template and OOP API.
*
* This is an alias for $(XREF digest.digest, WrapperDigest)!CRC32, see
* $(XREF digest.digest, WrapperDigest) for more information.
*
* Examples:
* --------
* //Simple example, hashing a string using Digest.digest helper function
* auto crc = new CRC32Digest();
* ubyte[] hash = crc.digest("abc");
* //Let's get a hash string
* assert(crcHexString(hash) == "352441C2");
* --------
*
* --------
* //Let's use the OOP features:
* void test(Digest dig)
* {
* dig.put(cast(ubyte)0);
* }
* auto crc = new CRC32Digest();
* test(crc);
*
* //Let's use a custom buffer:
* ubyte[4] buf;
* ubyte[] result = crc.finish(buf[]);
* assert(crcHexString(result) == "D202EF8D");
* --------
*/
alias WrapperDigest!CRC32 CRC32Digest;
//verify example
unittest
{
//Simple example, hashing a string using Digest.digest helper function
auto crc = new CRC32Digest();
ubyte[] hash = crc.digest("abc");
//Let's get a hash string
assert(crcHexString(hash) == "352441C2");
}
//verify example
unittest
{
//Let's use the OOP features:
void test(Digest dig)
{
dig.put(cast(ubyte)0);
}
auto crc = new CRC32Digest();
test(crc);
//Let's use a custom buffer:
ubyte[4] buf;
ubyte[] result = crc.finish(buf[]);
assert(crcHexString(result) == "D202EF8D");
}
//verify example
unittest
{
//Simple example
auto hash = new CRC32Digest();
hash.put(cast(ubyte)0);
ubyte[] result = hash.finish();
}
//verify example
unittest
{
//using a supplied buffer
ubyte[4] buf;
auto hash = new CRC32Digest();
hash.put(cast(ubyte)0);
ubyte[] result = hash.finish(buf[]);
//The result is now in result (and in buf. If you pass a buffer which is bigger than
//necessary, result will have the correct length, but buf will still have it's original
//length)
}
unittest
{
import std.range;
auto crc = new CRC32Digest();
crc.put(cast(ubyte[])"abcdefghijklmnopqrstuvwxyz");
assert(crc.peek() == cast(ubyte[])x"bd50274c");
crc.reset();
crc.put(cast(ubyte[])"");
assert(crc.finish() == cast(ubyte[])x"00000000");
crc.put(cast(ubyte[])"abcdefghijklmnopqrstuvwxyz");
ubyte[20] result;
auto result2 = crc.finish(result[]);
assert(result[0 .. 4] == result2 && result2 == cast(ubyte[])x"bd50274c");
debug
assertThrown!Error(crc.finish(result[0 .. 3]));
assert(crc.length == 4);
assert(crc.digest("") == cast(ubyte[])x"00000000");
assert(crc.digest("a") == cast(ubyte[])x"43beb7e8");
assert(crc.digest("abc") == cast(ubyte[])x"c2412435");
assert(crc.digest("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
== cast(ubyte[])x"5f3f1a17");
assert(crc.digest("message digest") == cast(ubyte[])x"7f9d1520");
assert(crc.digest("abcdefghijklmnopqrstuvwxyz")
== cast(ubyte[])x"bd50274c");
assert(crc.digest("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
== cast(ubyte[])x"d2e6c21f");
assert(crc.digest("1234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890")
== cast(ubyte[])x"724aa97c");
ubyte[] onemilliona = new ubyte[1000000];
onemilliona[] = 'a';
auto digest = crc32Of(onemilliona);
assert(digest == cast(ubyte[])x"BCBF25DC");
auto oneMillionRange = repeat!ubyte(cast(ubyte)'a', 1000000);
digest = crc32Of(oneMillionRange);
assert(digest == cast(ubyte[])x"BCBF25DC");
}

1207
std/digest/digest.d Normal file

File diff suppressed because it is too large Load diff

688
std/digest/md.d Normal file
View file

@ -0,0 +1,688 @@
/**
<script type="text/javascript">inhibitQuickIndex = 1</script>
$(BOOKTABLE ,
$(TR $(TH Category) $(TH Functions)
)
$(TR $(TDNW Template API) $(TD $(MYREF MD5)
)
)
$(TR $(TDNW OOP API) $(TD $(MYREF MD5Digest))
)
$(TR $(TDNW Helpers) $(TD $(MYREF md5Of))
)
)
* Computes MD5 hashes of arbitrary data. MD5 hashes are 16 byte quantities that are like a
* checksum or CRC, but are more robust.
*
* This module conforms to the APIs defined in $(D std.digest.digest). To understand the
* differences between the template and the OOP API, see $(D std.digest.digest).
*
* This module publicly imports $(D std.digest.digest) and can be used as a stand-alone
* module.
*
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>
*
* CTFE:
* Digests do not work in CTFE
*
* Authors:
* Piotr Szturmaj, Kai Nacke, Johannes Pfau $(BR)
* The routines and algorithms are derived from the $(I RSA Data Security, Inc. MD5 Message-Digest Algorithm).
*
* References:
* $(LINK2 http://en.wikipedia.org/wiki/Md5, Wikipedia on MD5)
*
* Source: $(PHOBOSSRC std/digest/_md.d)
*
* Macros:
* WIKI = Phobos/StdMd5
* MYREF = <font face='Consolas, "Bitstream Vera Sans Mono", "Andale Mono", Monaco, "DejaVu Sans Mono", "Lucida Console", monospace'><a href="#$1">$1</a>&nbsp;</font>
*
* Examples:
* ---------
* //Template API
* import std.digest.md;
*
* ubyte[16] hash = md5Of("abc");
* assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
*
* //Feeding data
* ubyte[1024] data;
* MD5 md5;
* md5.start();
* md5.put(data[]);
* md5.start(); //Start again
* md5.put(data[]);
* hash = md5.finish();
* ---------
*
* ---------
* //OOP API
* import std.digest.md;
*
* auto md5 = new MD5Digest();
* ubyte[] hash = md5.digest("abc");
* assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
*
* //Feeding data
* ubyte[1024] data;
* md5.put(data[]);
* md5.reset(); //Start again
* md5.put(data[]);
* hash = md5.finish();
* ---------
*/
/* md5.d - RSA Data Security, Inc., MD5 message-digest algorithm
* Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm.
*/
module std.digest.md;
import std.bitmanip, std.exception, std.string;
public import std.digest.digest;
//verify example
unittest
{
//Template API
import std.digest.md;
ubyte[16] hash = md5Of("abc");
assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
//Feeding data
ubyte[1024] data;
MD5 md5;
md5.start();
md5.put(data[]);
md5.start(); //Start again
md5.put(data[]);
hash = md5.finish();
}
//verify example
unittest
{
//OOP API
import std.digest.md;
auto md5 = new MD5Digest();
ubyte[] hash = md5.digest("abc");
assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
//Feeding data
ubyte[1024] data;
md5.put(data[]);
md5.reset(); //Start again
md5.put(data[]);
hash = md5.finish();
}
//rotateLeft rotates x left n bits
private nothrow pure uint rotateLeft(uint x, uint n)
{
// With recently added optimization to DMD (commit 32ea0206 at 07/28/11), this is translated to rol.
// No assembler required.
return (x << n) | (x >> (32-n));
}
/**
* Template API MD5 implementation.
* See $(D std.digest.digest) for differences between template and OOP API.
*
* Examples:
* --------
* //Simple example, hashing a string using md5Of helper function
* ubyte[16] hash = md5Of("abc");
* //Let's get a hash string
* assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
* --------
*
* --------
* //Using the basic API
* MD5 hash;
* hash.start();
* ubyte[1024] data;
* //Initialize data here...
* hash.put(data);
* ubyte[16] result = hash.finish();
* --------
*
* --------
* //Let's use the template features:
* //Note: When passing a MD5 to a function, it must be passed by referece!
* void doSomething(T)(ref T hash) if(isDigest!T)
* {
* hash.put(cast(ubyte)0);
* }
* MD5 md5;
* md5.start();
* doSomething(md5);
* assert(toHexString(md5.finish()) == "93B885ADFE0DA089CDF634904FD59F71");
* --------
*/
struct MD5
{
private:
// magic initialization constants
uint _state[4] = [0x67452301,0xefcdab89,0x98badcfe,0x10325476]; // state (ABCD)
ulong _count; //number of bits, modulo 2^64
ubyte[64] _buffer; // input buffer
enum ubyte[64] _padding =
[
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
// F, G, H and I are basic MD5 functions
static nothrow pure
{
uint F(uint x, uint y, uint z) { return (x & y) | (~x & z); }
uint G(uint x, uint y, uint z) { return (x & z) | (y & ~z); }
uint H(uint x, uint y, uint z) { return x ^ y ^ z; }
uint I(uint x, uint y, uint z) { return y ^ (x | ~z); }
}
/*
* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* Rotation is separate from addition to prevent recomputation.
*/
static nothrow pure void FF(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
{
a += F (b, c, d) + x + cast(uint)(ac);
a = rotateLeft(a, s);
a += b;
}
static nothrow pure void GG(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
{
a += G (b, c, d) + x + cast(uint)(ac);
a = rotateLeft(a, s);
a += b;
}
static nothrow pure void HH(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
{
a += H (b, c, d) + x + cast(uint)(ac);
a = rotateLeft(a, s);
a += b;
}
static nothrow pure void II(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
{
a += I (b, c, d) + x + cast(uint)(ac);
a = rotateLeft(a, s);
a += b;
}
/*
* MD5 basic transformation. Transforms state based on block.
*/
//Constants for MD5Transform routine.
enum
{
S11 = 7,
S12 = 12,
S13 = 17,
S14 = 22,
S21 = 5,
S22 = 9,
S23 = 14,
S24 = 20,
S31 = 4,
S32 = 11,
S33 = 16,
S34 = 23,
S41 = 6,
S42 = 10,
S43 = 15,
S44 = 21,
}
private nothrow pure void transform(const(ubyte[64])* block)
{
uint a = _state[0],
b = _state[1],
c = _state[2],
d = _state[3];
uint[16] x = void;
version(BigEndian)
{
for(size_t i = 0; i < 16; i++)
{
x[i] = littleEndianToNative!uint(cast(ubyte[4])block[i*4..i+4]);
}
}
else
{
(cast(ubyte*)x.ptr)[0 .. 64] = (cast(ubyte*)block)[0 .. 64];
}
//Round 1
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
//Round 2
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
//Round 3
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
//Round 4
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
_state[0] += a;
_state[1] += b;
_state[2] += c;
_state[3] += d;
//Zeroize sensitive information.
x[] = 0;
}
public:
/**
* Use this to feed the digest with data.
* Also implements the $(XREF range, OutputRange) interface for $(D ubyte) and
* $(D const(ubyte)[]).
*
* Examples:
* ----
* MD5 dig;
* dig.put(cast(ubyte)0); //single ubyte
* dig.put(cast(ubyte)0, cast(ubyte)0); //variadic
* ubyte[10] buf;
* dig.put(buf); //buffer
* ----
*/
@trusted nothrow pure void put(scope const(ubyte)[] data...)
{
uint i, index, partLen;
auto inputLen = data.length;
//Compute number of bytes mod 64
index = (cast(uint)_count >> 3) & (64 - 1);
//Update number of bits
_count += inputLen * 8;
partLen = 64 - index;
//Transform as many times as possible
if (inputLen >= partLen)
{
(&_buffer[index])[0 .. partLen] = data.ptr[0 .. partLen];
transform(&_buffer);
for(i = partLen; i + 63 < inputLen; i += 64)
{
transform(cast(const(ubyte[64])*)(data[i .. i + 64].ptr));
}
index = 0;
}
else
{
i = 0;
}
/* Buffer remaining input */
if (inputLen - i)
(&_buffer[index])[0 .. inputLen-i] = (&data[i])[0 .. inputLen-i];
}
/**
* Used to (re)initialize the MD5 digest.
*
* Note:
* For this MD5 Digest implementation calling start after default construction
* is not necessary. Calling start is only necessary to reset the Digest.
*
* Generic code which deals with different Digest types should always call start though.
*
* Examples:
* --------
* MD5 digest;
* //digest.start(); //Not necessary
* digest.put(0);
* --------
*/
@trusted nothrow pure void start()
{
this = MD5.init;
}
/**
* Returns the finished MD5 hash. This also calls $(LREF start) to
* reset the internal state.
*
* Examples:
* --------
* //Simple example
* MD5 hash;
* hash.start();
* hash.put(cast(ubyte)0);
* ubyte[16] result = hash.finish();
* --------
*/
@trusted nothrow pure ubyte[16] finish()
{
ubyte[16] data;
ubyte[8] bits = void;
uint index, padLen;
//Save number of bits
bits[0 .. 4] = nativeToLittleEndian((cast(uint*)&_count)[0]);
bits[4 .. 8] = nativeToLittleEndian((cast(uint*)&_count)[1]);
//Pad out to 56 mod 64
index = (cast(uint)_count >> 3) & (64 - 1);
padLen = (index < 56) ? (56 - index) : (120 - index);
put(_padding[0 .. padLen]);
//Append length (before padding)
put(bits);
//Store state in digest
data[0 .. 4] = nativeToLittleEndian(_state[0]);
data[4 .. 8] = nativeToLittleEndian(_state[1]);
data[8 .. 12] = nativeToLittleEndian(_state[2]);
data[12 .. 16] = nativeToLittleEndian(_state[3]);
/* Zeroize sensitive information. */
start();
return data;
}
}
//verify example
unittest
{
//Simple example, hashing a string using md5Of helper function
ubyte[16] hash = md5Of("abc");
//Let's get a hash string
assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
}
//verify example
unittest
{
//Using the basic API
MD5 hash;
hash.start();
ubyte[1024] data;
//Initialize data here...
hash.put(data);
ubyte[16] result = hash.finish();
}
//verify example
unittest
{
//Let's use the template features:
void doSomething(T)(ref T hash) if(isDigest!T)
{
hash.put(cast(ubyte)0);
}
MD5 md5;
md5.start();
doSomething(md5);
assert(toHexString(md5.finish()) == "93B885ADFE0DA089CDF634904FD59F71");
}
//verify example
unittest
{
//Simple example
MD5 hash;
hash.start();
hash.put(cast(ubyte)0);
ubyte[16] result = hash.finish();
}
unittest
{
assert(isDigest!MD5);
}
unittest
{
import std.range;
ubyte[16] digest;
MD5 md5;
md5.put(cast(ubyte[])"abcdef");
md5.start();
md5.put(cast(ubyte[])"");
assert(md5.finish() == cast(ubyte[])x"d41d8cd98f00b204e9800998ecf8427e");
digest = md5Of("");
assert(digest == cast(ubyte[])x"d41d8cd98f00b204e9800998ecf8427e");
digest = md5Of("a");
assert(digest == cast(ubyte[])x"0cc175b9c0f1b6a831c399e269772661");
digest = md5Of("abc");
assert(digest == cast(ubyte[])x"900150983cd24fb0d6963f7d28e17f72");
digest = md5Of("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
assert(digest == cast(ubyte[])x"8215ef0796a20bcaaae116d3876c664a");
digest = md5Of("message digest");
assert(digest == cast(ubyte[])x"f96b697d7cb7938d525a2f31aaf161d0");
digest = md5Of("abcdefghijklmnopqrstuvwxyz");
assert(digest == cast(ubyte[])x"c3fcd3d76192e4007dfb496cca67e13b");
digest = md5Of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
assert(digest == cast(ubyte[])x"d174ab98d277d9f5a5611c2c9f419d9f");
digest = md5Of("1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890");
assert(digest == cast(ubyte[])x"57edf4a22be3c955ac49da2e2107b67a");
assert(toHexString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b")
== "C3FCD3D76192E4007DFB496CCA67E13B");
ubyte[] onemilliona = new ubyte[1000000];
onemilliona[] = 'a';
digest = md5Of(onemilliona);
assert(digest == cast(ubyte[])x"7707D6AE4E027C70EEA2A935C2296F21");
auto oneMillionRange = repeat!ubyte(cast(ubyte)'a', 1000000);
digest = md5Of(oneMillionRange);
assert(digest == cast(ubyte[])x"7707D6AE4E027C70EEA2A935C2296F21");
}
/**
* This is a convenience alias for $(XREF digest.digest, digest) using the
* MD5 implementation.
*
* Examples:
* ---------
* ubyte[16] hash = md5Of("abc");
* assert(hash == digest!MD5("abc")); //This is the same as above
* ---------
*/
//simple alias doesn't work here, hope this gets inlined...
auto md5Of(T...)(T data)
{
return digest!(MD5, T)(data);
}
//verify example
unittest
{
ubyte[16] hash = md5Of("abc");
assert(hash == digest!MD5("abc"));
}
/**
* OOP API MD5 implementation.
* See $(D std.digest.digest) for differences between template and OOP API.
*
* This is an alias for $(XREF digest.digest, WrapperDigest)!MD5, see
* $(XREF digest.digest, WrapperDigest) for more information.
*
* Examples:
* --------
* //Simple example, hashing a string using Digest.digest helper function
* auto md5 = new MD5Digest();
* ubyte[] hash = md5.digest("abc");
* //Let's get a hash string
* assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
* --------
*
* --------
* //Let's use the OOP features:
* void test(Digest dig)
* {
* dig.put(cast(ubyte)0);
* }
* auto md5 = new MD5Digest();
* test(md5);
*
* //Let's use a custom buffer:
* ubyte[16] buf;
* ubyte[] result = md5.finish(buf[]);
* assert(toHexString(result) == "93B885ADFE0DA089CDF634904FD59F71");
* --------
*/
alias WrapperDigest!MD5 MD5Digest;
//verify example
unittest
{
//Simple example, hashing a string using Digest.digest helper function
auto md5 = new MD5Digest();
ubyte[] hash = md5.digest("abc");
//Let's get a hash string
assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
}
//verify example
unittest
{
//Let's use the OOP features:
void test(Digest dig)
{
dig.put(cast(ubyte)0);
}
auto md5 = new MD5Digest();
test(md5);
//Let's use a custom buffer:
ubyte[16] buf;
ubyte[] result = md5.finish(buf[]);
assert(toHexString(result) == "93B885ADFE0DA089CDF634904FD59F71");
}
unittest
{
auto md5 = new MD5Digest();
md5.put(cast(ubyte[])"abcdef");
md5.reset();
md5.put(cast(ubyte[])"");
assert(md5.finish() == cast(ubyte[])x"d41d8cd98f00b204e9800998ecf8427e");
md5.put(cast(ubyte[])"abcdefghijklmnopqrstuvwxyz");
ubyte[20] result;
auto result2 = md5.finish(result[]);
assert(result[0 .. 16] == result2 && result2 == cast(ubyte[])x"c3fcd3d76192e4007dfb496cca67e13b");
debug
assertThrown!Error(md5.finish(result[0 .. 15]));
assert(md5.length == 16);
assert(md5.digest("") == cast(ubyte[])x"d41d8cd98f00b204e9800998ecf8427e");
assert(md5.digest("a") == cast(ubyte[])x"0cc175b9c0f1b6a831c399e269772661");
assert(md5.digest("abc") == cast(ubyte[])x"900150983cd24fb0d6963f7d28e17f72");
assert(md5.digest("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
== cast(ubyte[])x"8215ef0796a20bcaaae116d3876c664a");
assert(md5.digest("message digest") == cast(ubyte[])x"f96b697d7cb7938d525a2f31aaf161d0");
assert(md5.digest("abcdefghijklmnopqrstuvwxyz")
== cast(ubyte[])x"c3fcd3d76192e4007dfb496cca67e13b");
assert(md5.digest("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
== cast(ubyte[])x"d174ab98d277d9f5a5611c2c9f419d9f");
assert(md5.digest("1234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890")
== cast(ubyte[])x"57edf4a22be3c955ac49da2e2107b67a");
}

View file

@ -5,6 +5,8 @@
*/
/**
* $(RED Scheduled for deprecation. Please use std.digest.md instead.)
*
* Computes MD5 digests of arbitrary data. MD5 digests are 16 byte quantities that are like a checksum or crc, but are more robust.
*
* There are two ways to do this. The first does it all in one function call to
@ -80,6 +82,9 @@ documentation and/or software.
module std.md5;
pragma(msg, "std.md5 is scheduled for deprecation. Please use "
"std.digest.md instead");
//debug=md5; // uncomment to turn on debugging printf's
import std.ascii;
@ -490,4 +495,3 @@ unittest
assert(digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b")
== "C3FCD3D76192E4007DFB496CCA67E13B");
}

View file

@ -389,7 +389,7 @@ interface OutputStream {
// not really abstract, but its instances will do nothing useful
class Stream : InputStream, OutputStream {
private import std.string, crc32, std.c.stdlib, std.c.stdio;
private import std.string, std.digest.crc, std.c.stdlib, std.c.stdio;
// stream abilities
bool readable = false; /// Indicates whether this stream can be read from.
@ -1364,16 +1364,25 @@ class Stream : InputStream, OutputStream {
{
ulong pos = position;
scope(exit) position(pos);
uint crc = init_crc32();
CRC32 crc;
crc.start();
position(0);
ulong len = size;
for (ulong i = 0; i < len; i++)
{
ubyte c;
read(c);
crc = update_crc32(c, crc);
crc.put(c);
}
return crc;
union resUnion
{
size_t hash;
ubyte[4] crcVal;
}
resUnion res;
res.crcVal = crc.finish();
return res.hash;
}
catch (Throwable)
{

View file

@ -58,6 +58,10 @@ public import std.zip;
public import std.zlib;
public import std.net.isemail;
public import std.net.curl;
public import std.digest.digest;
public import std.digest.crc;
public import std.digest.sha;
public import std.digest.md;
int main(char[][] args)
{
@ -126,6 +130,11 @@ version (all)
bool isEmail = std.net.isemail.isEmail("abc");
auto http = std.net.curl.HTTP("dlang.org");
auto uuid = randomUUID();
auto md5 = md5Of("hello");
auto sha1 = sha1Of("hello");
auto crc = crc32Of("hello");
auto string = toHexString(crc);
}
puts("Success!");
return 0;

View file

@ -122,7 +122,9 @@ SRC_STD_3= std\csv.d std\math.d std\complex.d std\numeric.d std\bigint.d \
std\compiler.d std\cpuid.d \
std\system.d std\concurrency.d
SRC_STD_4= std\uuid.d
#can't place SRC_STD_DIGEST in SRC_STD_REST because of out-of-memory issues
SRC_STD_DIGEST= std\digest\crc.d std\digest\sha.d std\digest\md.d std\digest\digest.d
SRC_STD_4= std\uuid.d $(SRC_STD_DIGEST)
SRC_STD_5_HEAVY= std\algorithm.d
@ -187,7 +189,7 @@ SRC_STD_INTERNAL= std\internal\processinit.d std\internal\uni.d std\internal\uni
SRC_STD_INTERNAL_MATH= std\internal\math\biguintcore.d \
std\internal\math\biguintnoasm.d std\internal\math\biguintx86.d \
std\internal\math\gammafunction.d std\internal\math\errorfunction.d
std\internal\math\gammafunction.d std\internal\math\errorfunction.d
SRC_STD_INTERNAL_WINDOWS= std\internal\windows\advapi32.d
@ -278,6 +280,10 @@ DOCS= $(DOC)\object.html \
$(DOC)\std_container.html \
$(DOC)\std_conv.html \
$(DOC)\std_cpuid.html \
$(DOC)\std_digest_crc.html \
$(DOC)\std_digest_sha.html \
$(DOC)\std_digest_md.html \
$(DOC)\std_digest_digest.html \
$(DOC)\std_cstream.html \
$(DOC)\std_ctype.html \
$(DOC)\std_csv.html \
@ -635,6 +641,18 @@ $(DOC)\std_net_isemail.html : $(STDDOC) std\net\isemail.d
$(DOC)\std_net_curl.html : $(STDDOC) std\net\curl.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_net_curl.html $(STDDOC) std\net\curl.d
$(DOC)\std_digest_crc.html : $(STDDOC) std\digest\crc.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_crc.html $(STDDOC) std\digest\crc.d
$(DOC)\std_digest_sha.html : $(STDDOC) std\digest\sha.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_sha.html $(STDDOC) std\digest\sha.d
$(DOC)\std_digest_md.html : $(STDDOC) std\digest\md.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_md.html $(STDDOC) std\digest\md.d
$(DOC)\std_digest_digest.html : $(STDDOC) std\digest\digest.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_digest.html $(STDDOC) std\digest\digest.d
$(DOC)\std_windows_charset.html : $(STDDOC) std\windows\charset.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_windows_charset.html $(STDDOC) std\windows\charset.d
@ -689,7 +707,7 @@ $(DOC)\etc_c_zlib.html : $(STDDOC) etc\c\zlib.d
zip : win32.mak win64.mak posix.mak $(STDDOC) $(SRC) \
$(SRC_STD) $(SRC_STD_C) $(SRC_STD_WIN) \
$(SRC_STD_C_WIN) $(SRC_STD_C_LINUX) $(SRC_STD_C_OSX) $(SRC_STD_C_FREEBSD) \
$(SRC_ETC) $(SRC_ETC_C) $(SRC_ZLIB) $(SRC_STD_NET) \
$(SRC_ETC) $(SRC_ETC_C) $(SRC_ZLIB) $(SRC_STD_NET) $(SRC_STD_DIGEST) \
$(SRC_STD_INTERNAL) $(SRC_STD_INTERNAL_MATH) $(SRC_STD_INTERNAL_WINDOWS)
del phobos.zip
zip32 -u phobos win32.mak win64.mak posix.mak $(STDDOC)
@ -707,6 +725,7 @@ zip : win32.mak win64.mak posix.mak $(STDDOC) $(SRC) \
zip32 -u phobos $(SRC_ETC) $(SRC_ETC_C)
zip32 -u phobos $(SRC_ZLIB)
zip32 -u phobos $(SRC_STD_NET)
zip32 -u phobos $(SRC_STD_DIGEST)
clean:
cd etc\c\zlib
@ -744,6 +763,7 @@ install:
$(CP) $(SRC) $(DIR)\src\phobos\
$(CP) $(SRC_STD) $(DIR)\src\phobos\std\
$(CP) $(SRC_STD_NET) $(DIR)\src\phobos\std\net\
$(CP) $(SRC_STD_DIGEST) $(DIR)\src\phobos\std\digest\
$(CP) $(SRC_STD_C) $(DIR)\src\phobos\std\c\
$(CP) $(SRC_STD_WIN) $(DIR)\src\phobos\std\windows\
$(CP) $(SRC_STD_C_WIN) $(DIR)\src\phobos\std\c\windows\
@ -751,7 +771,7 @@ install:
$(CP) $(SRC_STD_C_OSX) $(DIR)\src\phobos\std\c\osx\
$(CP) $(SRC_STD_C_FREEBSD) $(DIR)\src\phobos\std\c\freebsd\
$(CP) $(SRC_STD_INTERNAL) $(DIR)\src\phobos\std\internal\
$(CP) $(SRC_STD_INTERNAL_MATH) $(DIR)\src\phobos\std\internal\math\
$(CP) $(SRC_STD_INTERNAL_MATH) $(DIR)\src\phobos\std\internal\math\
$(CP) $(SRC_STD_INTERNAL_WINDOWS) $(DIR)\src\phobos\std\internal\windows\
#$(CP) $(SRC_ETC) $(DIR)\src\phobos\etc\
$(CP) $(SRC_ETC_C) $(DIR)\src\phobos\etc\c\

View file

@ -123,7 +123,9 @@ SRC_STD_3= std\csv.d std\math.d std\complex.d std\numeric.d std\bigint.d \
std\compiler.d std\cpuid.d \
std\system.d std\concurrency.d
SRC_STD_4= std\uuid.d
#can't place SRC_STD_DIGEST in SRC_STD_REST because of out-of-memory issues
SRC_STD_DIGEST= std\digest\crc.d std\digest\sha.d std\digest\md.d std\digest\digest.d
SRC_STD_4= std\uuid.d $(SRC_STD_DIGEST)
SRC_STD_5_HEAVY= std\algorithm.d
@ -279,6 +281,10 @@ DOCS= $(DOC)\object.html \
$(DOC)\std_container.html \
$(DOC)\std_conv.html \
$(DOC)\std_cpuid.html \
$(DOC)\std_digest_crc.html \
$(DOC)\std_digest_sha.html \
$(DOC)\std_digest_md.html \
$(DOC)\std_digest_digest.html \
$(DOC)\std_cstream.html \
$(DOC)\std_ctype.html \
$(DOC)\std_csv.html \
@ -636,6 +642,18 @@ $(DOC)\std_net_isemail.html : $(STDDOC) std\net\isemail.d
$(DOC)\std_net_curl.html : $(STDDOC) std\net\curl.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_net_curl.html $(STDDOC) std\net\curl.d
$(DOC)\std_digest_crc.html : $(STDDOC) std\digest\crc.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_crc.html $(STDDOC) std\digest\crc.d
$(DOC)\std_digest_sha.html : $(STDDOC) std\digest\sha.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_sha.html $(STDDOC) std\digest\sha.d
$(DOC)\std_digest_md.html : $(STDDOC) std\digest\md.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_md.html $(STDDOC) std\digest\md.d
$(DOC)\std_digest_digest.html : $(STDDOC) std\digest\digest.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_digest_digest.html $(STDDOC) std\digest\digest.d
$(DOC)\std_windows_charset.html : $(STDDOC) std\windows\charset.d
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_windows_charset.html $(STDDOC) std\windows\charset.d
@ -690,7 +708,7 @@ $(DOC)\etc_c_zlib.html : $(STDDOC) etc\c\zlib.d
zip : win32.mak win64.mak posix.mak $(STDDOC) $(SRC) \
$(SRC_STD) $(SRC_STD_C) $(SRC_STD_WIN) \
$(SRC_STD_C_WIN) $(SRC_STD_C_LINUX) $(SRC_STD_C_OSX) $(SRC_STD_C_FREEBSD) \
$(SRC_ETC) $(SRC_ETC_C) $(SRC_ZLIB) $(SRC_STD_NET) \
$(SRC_ETC) $(SRC_ETC_C) $(SRC_ZLIB) $(SRC_STD_NET) $(SRC_STD_DIGEST)\
$(SRC_STD_INTERNAL) $(SRC_STD_INTERNAL_MATH) $(SRC_STD_INTERNAL_WINDOWS)
del phobos.zip
zip32 -u phobos win32.mak win64.mak posix.mak $(STDDOC)
@ -708,6 +726,7 @@ zip : win32.mak win64.mak posix.mak $(STDDOC) $(SRC) \
zip32 -u phobos $(SRC_ETC) $(SRC_ETC_C)
zip32 -u phobos $(SRC_ZLIB)
zip32 -u phobos $(SRC_STD_NET)
zip32 -u phobos $(SRC_STD_DIGEST)
clean:
cd etc\c\zlib
@ -745,6 +764,7 @@ install:
$(CP) $(SRC) $(DIR)\src\phobos\
$(CP) $(SRC_STD) $(DIR)\src\phobos\std\
$(CP) $(SRC_STD_NET) $(DIR)\src\phobos\std\net\
$(CP) $(SRC_STD_DIGEST) $(DIR)\src\phobos\std\digest\
$(CP) $(SRC_STD_C) $(DIR)\src\phobos\std\c\
$(CP) $(SRC_STD_WIN) $(DIR)\src\phobos\std\windows\
$(CP) $(SRC_STD_C_WIN) $(DIR)\src\phobos\std\c\windows\