1 // Written in the D programming language. 2 3 module wrapper.sodium.crypto_hash_sha512; 4 5 import wrapper.sodium.core; // assure sodium got initialized 6 7 public 8 import deimos.sodium.crypto_hash_sha512 : crypto_hash_sha512_state, 9 crypto_hash_sha512_statebytes, 10 crypto_hash_sha512_BYTES, 11 crypto_hash_sha512_bytes; 12 /* crypto_hash_sha512, 13 crypto_hash_sha512_init, 14 crypto_hash_sha512_update, 15 crypto_hash_sha512_final; */ 16 17 alias crypto_hash_sha512 = deimos.sodium.crypto_hash_sha512.crypto_hash_sha512; 18 19 pragma(inline, true) 20 bool crypto_hash_sha512(out ubyte[crypto_hash_sha512_BYTES] out_, scope const ubyte[] in_) @nogc pure @trusted 21 { 22 return crypto_hash_sha512(out_.ptr, in_.ptr, in_.length) == 0; 23 } 24 25 26 alias crypto_hash_sha512_init = deimos.sodium.crypto_hash_sha512.crypto_hash_sha512_init; 27 28 pragma(inline, true) 29 bool crypto_hash_sha512_init(out crypto_hash_sha512_state state) @nogc pure @trusted 30 { 31 return crypto_hash_sha512_init(&state) == 0; 32 } 33 34 alias crypto_hash_sha512_update = deimos.sodium.crypto_hash_sha512.crypto_hash_sha512_update; 35 36 pragma(inline, true) 37 bool crypto_hash_sha512_update(ref crypto_hash_sha512_state state, scope const ubyte[] in_) @nogc pure @trusted 38 { 39 return crypto_hash_sha512_update(&state, in_.ptr, in_.length) == 0; 40 } 41 42 alias crypto_hash_sha512_final = deimos.sodium.crypto_hash_sha512.crypto_hash_sha512_final; 43 44 pragma(inline, true) 45 bool crypto_hash_sha512_final(ref crypto_hash_sha512_state state, out ubyte[crypto_hash_sha512_BYTES] out_) @nogc pure @trusted 46 { 47 return crypto_hash_sha512_final(&state, out_.ptr) == 0; 48 } 49 50 51 @safe 52 unittest 53 { 54 import std.stdio : writeln, writefln; 55 import std..string : representation; 56 debug writeln("unittest block 1 from sodium.crypto_hash_sha512.d"); 57 58 assert(crypto_hash_sha512_statebytes == crypto_hash_sha512_state.sizeof); 59 // writeln(crypto_hash_sha512_statebytes()); // 208 60 // writeln(crypto_hash_sha512_state.sizeof); // 208 61 assert(crypto_hash_sha512_bytes() == crypto_hash_sha512_BYTES); 62 63 auto message = representation("test some more text!"); 64 65 ubyte[crypto_hash_sha512_BYTES] hash; 66 ubyte[crypto_hash_sha512_BYTES] hash_saved; 67 assert(crypto_hash_sha512(hash, message)); 68 hash_saved = hash; 69 // writefln("0x%(%02X%)", hash); // 0x751D946284C252417D596C384A710A02D25788A109BBAC3DC83F98A4EF4F0D235DAC3691E57B0013ABC24F174E71671152BFA9C41033683737328D34F57B528D 70 hash = hash.init; 71 auto message1 = representation("test some"); 72 auto message2 = representation(" more text!"); 73 crypto_hash_sha512_state state; 74 75 assert(crypto_hash_sha512_init (state)); 76 assert(crypto_hash_sha512_update(state, message1)); 77 assert(crypto_hash_sha512_update(state, message2)); 78 assert(crypto_hash_sha512_final (state, hash)); 79 assert(hash == hash_saved); 80 }