Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
5
Task/SHA-256/D/sha-256-1.d
Normal file
5
Task/SHA-256/D/sha-256-1.d
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
void main() {
|
||||
import std.stdio, std.digest.sha;
|
||||
|
||||
writefln("%-(%02x%)", "Rosetta code".sha256Of);
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ struct SHA256 {
|
|||
alias TResult = ubyte[256 / 8];
|
||||
|
||||
version(WORDS_BIGENDIAN) {
|
||||
static uint bswap(in uint n) pure nothrow { return n; }
|
||||
static uint bswap(in uint n) pure nothrow @safe @nogc { return n; }
|
||||
}
|
||||
|
||||
// Bytes used to pad the buffer to the next 64-byte boundary.
|
||||
|
|
@ -30,7 +30,7 @@ struct SHA256 {
|
|||
Takes a pointer to a 256 bit block of data (eight 32 bit ints) and
|
||||
intializes it to the start constants of the SHA256 algorithm. This
|
||||
must be called before using hash in the call to sha256_hash. */
|
||||
void init() pure nothrow {
|
||||
void init() pure nothrow @safe @nogc {
|
||||
state = [0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU,
|
||||
0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U];
|
||||
total[] = 0;
|
||||
|
|
@ -42,7 +42,7 @@ struct SHA256 {
|
|||
the initialization function) update the context for the next LEN
|
||||
bytes starting at BUFFER.
|
||||
It is not required that LEN is a multiple of 64. */
|
||||
void processBytes(in ubyte[] inBuffer) pure nothrow {
|
||||
void processBytes(in ubyte[] inBuffer) pure nothrow @nogc {
|
||||
// When we already have some bits in our internal
|
||||
// buffer concatenate both inputs first.
|
||||
const(ubyte)* inBufferPtr = inBuffer.ptr;
|
||||
|
|
@ -61,10 +61,8 @@ struct SHA256 {
|
|||
processBlock(bufferB[0 .. bufLen & ~63]);
|
||||
|
||||
bufLen &= 63;
|
||||
// The regions in the following copy operation
|
||||
// cannot overlap.
|
||||
memcpy(bufferB.ptr,
|
||||
&bufferB[(left_over + add) & ~63], bufLen);
|
||||
// The regions in the following copy operation cannot overlap.
|
||||
memcpy(bufferB.ptr, &bufferB[(left_over + add) & ~63], bufLen);
|
||||
}
|
||||
|
||||
inBufferPtr += add;
|
||||
|
|
@ -99,15 +97,15 @@ struct SHA256 {
|
|||
the next len bytes starting at buffer.
|
||||
It is necessary that len is a multiple of 64. */
|
||||
void processBlock(in ubyte[] inBuffer)
|
||||
pure nothrow in {
|
||||
pure nothrow @nogc in {
|
||||
assert(inBuffer.length % 64 == 0);
|
||||
} body {
|
||||
// Round functions.
|
||||
static uint F1(in uint e, in uint f, in uint g) pure nothrow {
|
||||
static uint F1(in uint e, in uint f, in uint g) pure nothrow @safe @nogc {
|
||||
return g ^ (e & (f ^ g));
|
||||
}
|
||||
|
||||
static uint F2(in uint a, in uint b, in uint c) pure nothrow {
|
||||
static uint F2(in uint a, in uint b, in uint c) pure nothrow @safe @nogc {
|
||||
return (a & b) | (c & (a | b));
|
||||
}
|
||||
|
||||
|
|
@ -132,18 +130,18 @@ struct SHA256 {
|
|||
if (total[0] < len)
|
||||
total[1]++;
|
||||
|
||||
static uint rol(in uint x, in uint n) pure nothrow {
|
||||
static uint rol(in uint x, in uint n) pure nothrow @safe @nogc {
|
||||
return (x << n) | (x >> (32 - n)); }
|
||||
static uint S0(in uint x) pure nothrow {
|
||||
static uint S0(in uint x) pure nothrow @safe @nogc {
|
||||
return rol(x, 25) ^ rol(x, 14) ^ (x >> 3); }
|
||||
static uint S1(in uint x) pure nothrow {
|
||||
static uint S1(in uint x) pure nothrow @safe @nogc {
|
||||
return rol(x, 15) ^ rol(x, 13) ^ (x >> 10); }
|
||||
static uint SS0(in uint x) pure nothrow {
|
||||
static uint SS0(in uint x) pure nothrow @safe @nogc {
|
||||
return rol(x, 30) ^ rol(x,19) ^ rol(x, 10); }
|
||||
static uint SS1(in uint x) pure nothrow {
|
||||
static uint SS1(in uint x) pure nothrow @safe @nogc {
|
||||
return rol(x, 26) ^ rol(x, 21) ^ rol(x, 7); }
|
||||
|
||||
uint M(in uint I) nothrow {
|
||||
uint M(in uint I) pure nothrow @safe @nogc {
|
||||
immutable uint tm = S1(x[(I - 2) & 0x0f]) +
|
||||
x[(I - 7) & 0x0f] +
|
||||
S0(x[(I - 15) & 0x0f]) +
|
||||
|
|
@ -154,7 +152,7 @@ struct SHA256 {
|
|||
|
||||
static void R(in uint a, in uint b, in uint c, ref uint d,
|
||||
in uint e, in uint f, in uint g, ref uint h,
|
||||
in uint k, in uint m) pure nothrow {
|
||||
in uint k, in uint m) pure nothrow @safe @nogc {
|
||||
immutable t0 = SS0(a) + F2(a, b, c);
|
||||
immutable t1 = h + SS1(e) + F1(e, f, g) + k + m;
|
||||
d += t1;
|
||||
|
|
@ -268,7 +266,7 @@ struct SHA256 {
|
|||
resBuf.
|
||||
Important: On some systems it is required that resBuf is correctly
|
||||
aligned for a 32-bit value. */
|
||||
void conclude() pure nothrow {
|
||||
void conclude() pure nothrow @nogc {
|
||||
// Take yet unprocessed bytes into account.
|
||||
immutable bytes = bufLen;
|
||||
immutable size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
|
||||
|
|
@ -294,7 +292,7 @@ struct SHA256 {
|
|||
result must be in little endian byte order.
|
||||
Important: On some systems it is required that resBuf is correctly
|
||||
aligned for a 32-bit value. */
|
||||
ref TResult read(ref TResult resBuf) const pure nothrow {
|
||||
ref TResult read(return ref TResult resBuf) pure nothrow @nogc {
|
||||
foreach (immutable i, immutable s; state)
|
||||
(cast(uint*)resBuf.ptr)[i] = bswap(s);
|
||||
return resBuf;
|
||||
|
|
@ -307,7 +305,7 @@ struct SHA256 {
|
|||
the wanted ASCII representation of the message digest.
|
||||
Important: On some systems it is required that resBuf be correctly
|
||||
aligned for a 32 bits value. */
|
||||
ref TResult finish(ref TResult resBuf) pure nothrow {
|
||||
ref TResult finish(return ref TResult resBuf) pure nothrow @nogc {
|
||||
conclude;
|
||||
return read(resBuf);
|
||||
}
|
||||
|
|
@ -317,8 +315,8 @@ struct SHA256 {
|
|||
buffer. The result is always in little endian byte order, so that
|
||||
a byte-wise output yields to the wanted ASCII representation of
|
||||
the message digest. */
|
||||
static ref TResult digest(in ubyte[] inBuffer, ref TResult resBuf)
|
||||
pure nothrow {
|
||||
static ref TResult digest(in ubyte[] inBuffer, return ref TResult resBuf)
|
||||
pure nothrow @nogc {
|
||||
SHA256 sha = void;
|
||||
|
||||
// Initialize the computation context.
|
||||
|
|
@ -333,7 +331,7 @@ struct SHA256 {
|
|||
|
||||
|
||||
/// ditto
|
||||
static TResult digest(in ubyte[] inBuffer) pure nothrow {
|
||||
static TResult digest(in ubyte[] inBuffer) pure nothrow @nogc {
|
||||
align(4) TResult resBuf = void;
|
||||
return digest(inBuffer, resBuf);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue