1 /******************************************************************************* 2 3 D bindings to libgcrypt cryptograhic hash functions. 4 5 Requires linking with libgcrypt: 6 7 -L-lgcrypt 8 9 Copyright: 10 Copyright (c) 2009-2016 dunnhumby Germany GmbH. 11 All rights reserved. 12 13 License: 14 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 15 Alternatively, this file may be distributed under the terms of the Tango 16 3-Clause BSD License (see LICENSE_BSD.txt for details). 17 18 Bear in mind this module provides bindings to an external library that 19 has its own license, which might be more restrictive. Please check the 20 external library license to see which conditions apply for linking. 21 22 *******************************************************************************/ 23 24 module ocean.util.cipher.gcrypt.c.md; 25 26 public import ocean.util.cipher.gcrypt.c.general; 27 28 import ocean.transition; 29 30 extern (C): 31 32 /// See original's library documentation for details. 33 enum gcry_md_algos 34 { 35 GCRY_MD_NONE = 0, 36 GCRY_MD_MD5 = 1, 37 GCRY_MD_SHA1 = 2, 38 GCRY_MD_RMD160 = 3, 39 GCRY_MD_MD2 = 5, 40 GCRY_MD_TIGER = 6, 41 GCRY_MD_HAVAL = 7, 42 GCRY_MD_SHA256 = 8, 43 GCRY_MD_SHA384 = 9, 44 GCRY_MD_SHA512 = 10, 45 GCRY_MD_SHA224 = 11, 46 GCRY_MD_MD4 = 301, 47 GCRY_MD_CRC32 = 302, 48 GCRY_MD_CRC32_RFC1510 = 303, 49 GCRY_MD_CRC24_RFC2440 = 304, 50 GCRY_MD_WHIRLPOOL = 305, 51 GCRY_MD_TIGER1 = 306, 52 GCRY_MD_TIGER2 = 307 53 } 54 55 /// See original's library documentation for details. 56 enum gcry_md_flags 57 { 58 GCRY_MD_FLAG_SECURE = 1, 59 GCRY_MD_FLAG_HMAC = 2 60 } 61 62 /// See original's library documentation for details. 63 struct gcry_md_handle; 64 /// See original's library documentation for details. 65 alias gcry_md_handle* gcry_md_hd_t; 66 67 /// See original's library documentation for details. 68 gcry_error_t gcry_md_open (gcry_md_hd_t* h, gcry_md_algos algo, gcry_md_flags flags); 69 70 /// See original's library documentation for details. 71 void gcry_md_close (gcry_md_hd_t hd); 72 73 /// See original's library documentation for details. 74 gcry_error_t gcry_md_enable (gcry_md_hd_t hd, gcry_md_algos algo); 75 76 /// See original's library documentation for details. 77 gcry_error_t gcry_md_copy (gcry_md_hd_t* bhd, gcry_md_hd_t ahd); 78 79 /// See original's library documentation for details. 80 void gcry_md_reset (gcry_md_hd_t hd); 81 82 /// See original's library documentation for details. 83 gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, 84 void* buffer, size_t buflen); 85 86 /// See original's library documentation for details. 87 void gcry_md_write (gcry_md_hd_t hd, Const!(void)* buffer, size_t length); 88 89 /// See original's library documentation for details. 90 ubyte* gcry_md_read (gcry_md_hd_t hd, gcry_md_algos algo = gcry_md_algos.init); 91 92 extern (D) ubyte[] gcry_md_read_slice (gcry_md_hd_t hd, gcry_md_algos algo = gcry_md_algos.init) 93 { 94 if (ubyte* data = gcry_md_read(hd, algo)) 95 { 96 return data[0 .. gcry_md_get_algo_dlen(algo? algo : gcry_md_get_algo(hd))]; 97 } 98 else 99 { 100 return null; 101 } 102 } 103 104 /// See original's library documentation for details. 105 void gcry_md_hash_buffer (gcry_md_algos algo, void* digest, 106 Const!(void)* buffer, size_t length); 107 108 /// See original's library documentation for details. 109 gcry_md_algos gcry_md_get_algo (gcry_md_hd_t hd); 110 111 /// See original's library documentation for details. 112 uint gcry_md_get_algo_dlen (gcry_md_algos algo); 113 114 /// See original's library documentation for details. 115 int gcry_md_is_enabled (gcry_md_hd_t a, gcry_md_algos algo); 116 117 /// See original's library documentation for details. 118 int gcry_md_is_secure (gcry_md_hd_t a); 119 120 /// See original's library documentation for details. 121 gcry_error_t gcry_md_info (gcry_md_hd_t h, gcry_ctl_cmds what, void* buffer, 122 size_t* nbytes); 123 124 /// See original's library documentation for details. 125 gcry_error_t gcry_md_algo_info (gcry_md_algos algo, gcry_ctl_cmds what, void* buffer, 126 size_t* nbytes); 127 128 /// See original's library documentation for details. 129 Const!(char)* gcry_md_algo_name (gcry_md_algos algo); 130 131 /// See original's library documentation for details. 132 int gcry_md_map_name (Const!(char)* name); 133 134 /// See original's library documentation for details. 135 gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, Const!(void)* key, size_t keylen); 136 137 /// See original's library documentation for details. 138 void gcry_md_debug (gcry_md_hd_t hd, Const!(char)* suffix); 139 140 141 /// See original's library documentation for details. 142 extern (D) gcry_error_t gcry_md_test_algo(gcry_md_algos a) 143 { 144 return gcry_md_algo_info(a, gcry_ctl_cmds.GCRYCTL_TEST_ALGO, null, null); 145 } 146 147 /// See original's library documentation for details. 148 extern (D) gcry_error_t gcry_md_get_asnoid(gcry_md_algos a, ref ubyte[] b) 149 { 150 size_t len = b.length; 151 152 if (auto error = gcry_md_algo_info(a, gcry_ctl_cmds.GCRYCTL_GET_ASNOID, b.ptr, &len)) 153 { 154 return error; 155 } 156 else 157 { 158 b = b[0 .. len]; 159 return 0; 160 } 161 } 162 163 /// See original's library documentation for details. 164 gcry_error_t gcry_md_list (int* list, int* list_length);