Skip to content

Commit

Permalink
Merge pull request #807 from redstar/sha1_ssse3
Browse files Browse the repository at this point in the history
Add SSSE3 implementation to SHA1 digest.
  • Loading branch information
Alex Rønne Petersen committed Dec 10, 2012
2 parents 2a07625 + 4592361 commit dd463ad
Show file tree
Hide file tree
Showing 6 changed files with 752 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelog.dd
Expand Up @@ -2,7 +2,7 @@ $(VERSION 061, ddd mm, 2012, =================================================,
$(WHATSNEW
$(LI std.digest: Added new package for digests. This replaces std.md5 and the internal crc32
implementation.)
$(LI std.digest.sha: Added SHA1 digest implementation.)
$(LI std.digest.sha: Added SHA1 digest implementation, including a fast SSSE3 version.)
$(LI std.digest.ripemd: Added RIPEMD-160 digest implementation.)
$(LI std.uuid: Support SHA1 UUIDs.)
$(LI std.uuid: md5UUID and sha1UUID can now be used in pure code.)
Expand Down
1 change: 1 addition & 0 deletions posix.mak
Expand Up @@ -192,6 +192,7 @@ EXTRA_DOCUMENTABLES += $(addprefix etc/c/,curl sqlite3 zlib) $(addprefix \
std/c/, fenv locale math process stdarg stddef stdio stdlib string \
time wcharh)
EXTRA_MODULES += $(EXTRA_DOCUMENTABLES) $(addprefix \
std/internal/digest/, sha_SSSE3 ) $(addprefix \
std/internal/math/, biguintcore biguintnoasm biguintx86 \
gammafunction errorfunction) $(addprefix std/internal/, \
processinit uni uni_tab)
Expand Down
30 changes: 29 additions & 1 deletion std/digest/sha.d
Expand Up @@ -125,9 +125,25 @@ unittest
hash = sha.finish();
}

version(OSX)
{
// Do not use.
}
else version(D_InlineAsm_X86)
{
private version = USE_SSSE3;
}
else version(D_InlineAsm_X86_64)
{
private version = USE_SSSE3;
}

import std.ascii : hexDigits;
import std.exception : assumeUnique;
import core.bitop : bswap;
version(USE_SSSE3) import core.cpuid : hasSSSE3Support = ssse3;
version(USE_SSSE3) import std.internal.digest.sha_SSSE3 : transformSSSE3;


version(unittest)
{
Expand Down Expand Up @@ -212,7 +228,19 @@ private nothrow pure uint rotateLeft(uint x, uint n)
*/
struct SHA1
{
alias transformX86 transform;
version(USE_SSSE3)
{
private __gshared immutable nothrow pure void function(uint[5]* state, const(ubyte[64])* block) transform;

shared static this()
{
transform = hasSSSE3Support() ? &transformSSSE3 : &transformX86;
}
}
else
{
alias transformX86 transform;
}

private:
uint state[5] = /* state (ABCDE) */
Expand Down

0 comments on commit dd463ad

Please sign in to comment.