1 module tagion.betterC.wallet.hash; 2 3 import tagion.betterC.utils.Memory; 4 5 /*********************************************************************** 6 * Copyright (c) 2014 Pieter Wuille * 7 * Distributed under the MIT software license, see the accompanying * 8 * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 9 ***********************************************************************/ 10 11 extern (C): 12 13 void secp256k1_sha256_initialize(secp256k1_sha256* hash); 14 void secp256k1_sha256_write(secp256k1_sha256* hash, const(ubyte)* data, size_t size); 15 void secp256k1_sha256_finalize(secp256k1_sha256* hash, ubyte* out32); 16 17 ubyte[] secp256k1_count_hash(const const(ubyte[]) data) { 18 secp256k1_sha256 hash; 19 ubyte[] res; 20 res.create(32); 21 ubyte* ret_arr; 22 23 // secp256k1_sha256_initialize(&hash); 24 // secp256k1_sha256_write(&hash, &data[0], data.length); 25 // secp256k1_sha256_finalize(&hash, ret_arr); 26 27 for (int i = 0; i < 32; i++) { 28 res[i] = *(ret_arr + i); 29 } 30 31 return res; 32 } 33 34 struct secp256k1_sha256 { 35 uint[8] s; 36 uint[16] buf; /* In big endian */ 37 size_t bytes; 38 } 39 40 ubyte[32] secp256k1_count_hmac_hash(const const(ubyte[]) data) { 41 secp256k1_hmac_sha256 hash; 42 ubyte[32] res; 43 ubyte* ret_arr; 44 45 // secp256k1_hmac_sha256_initialize(&hash); 46 // secp256k1_hmac_sha256_write(&hash, &data[0], data.length); 47 // secp256k1_hmac_sha256_finalize(&hash, ret_arr); 48 49 // for (int i = 0; i < 32 ; i++) { 50 // res[i] = *(ret_arr + i); 51 // } 52 53 return res; 54 } 55 56 struct secp256k1_hmac_sha256 { 57 secp256k1_sha256 inner; 58 secp256k1_sha256 outer; 59 } 60 61 void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256* hash, const(ubyte)* key, size_t size); 62 void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256* hash, const(ubyte)* data, size_t size); 63 void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256* hash, ubyte* out32); 64 65 struct secp256k1_rfc6979_hmac_sha256 { 66 ubyte[32] v; 67 ubyte[32] k; 68 int retry; 69 } 70 71 void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256* rng, const(ubyte)* key, size_t keylen); 72 void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256* rng, ubyte* out_, size_t outlen); 73 void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256* rng); 74 75 // struct secp256k1_context { 76 // secp256k1_ecmult_gen_context ecmult_gen_ctx; 77 // secp256k1_callback illegal_callback; 78 // secp256k1_callback error_callback; 79 // int declassify; 80 // }; 81 82 // void randomize32(const (ubyte[]) seed, ubyte[] out32) 83 // in { 84 // assert(seed.length == 32); 85 // assert(out32.length == 32); 86 // } 87 // do { 88 // secp256k1_context ctx; 89 // out32[0.. $] 90 91 // } 92 93 /* SECP256K1_HASH_H */