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 extern (C): 29 30 /// See original's library documentation for details. 31 enum gcry_md_algos 32 { 33 GCRY_MD_NONE = 0, 34 GCRY_MD_MD5 = 1, 35 GCRY_MD_SHA1 = 2, 36 GCRY_MD_RMD160 = 3, 37 GCRY_MD_MD2 = 5, 38 GCRY_MD_TIGER = 6, 39 GCRY_MD_HAVAL = 7, 40 GCRY_MD_SHA256 = 8, 41 GCRY_MD_SHA384 = 9, 42 GCRY_MD_SHA512 = 10, 43 GCRY_MD_SHA224 = 11, 44 GCRY_MD_MD4 = 301, 45 GCRY_MD_CRC32 = 302, 46 GCRY_MD_CRC32_RFC1510 = 303, 47 GCRY_MD_CRC24_RFC2440 = 304, 48 GCRY_MD_WHIRLPOOL = 305, 49 GCRY_MD_TIGER1 = 306, 50 GCRY_MD_TIGER2 = 307 51 } 52 53 /// See original's library documentation for details. 54 enum gcry_md_flags 55 { 56 GCRY_MD_FLAG_SECURE = 1, 57 GCRY_MD_FLAG_HMAC = 2 58 } 59 60 /// See original's library documentation for details. 61 struct gcry_md_handle; 62 /// See original's library documentation for details. 63 alias gcry_md_handle* gcry_md_hd_t; 64 65 /// See original's library documentation for details. 66 gcry_error_t gcry_md_open (gcry_md_hd_t* h, gcry_md_algos algo, gcry_md_flags flags); 67 68 /// See original's library documentation for details. 69 void gcry_md_close (gcry_md_hd_t hd); 70 71 /// See original's library documentation for details. 72 gcry_error_t gcry_md_enable (gcry_md_hd_t hd, gcry_md_algos algo); 73 74 /// See original's library documentation for details. 75 gcry_error_t gcry_md_copy (gcry_md_hd_t* bhd, gcry_md_hd_t ahd); 76 77 /// See original's library documentation for details. 78 void gcry_md_reset (gcry_md_hd_t hd); 79 80 /// See original's library documentation for details. 81 gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, 82 void* buffer, size_t buflen); 83 84 /// See original's library documentation for details. 85 void gcry_md_write (gcry_md_hd_t hd, const(void)* buffer, size_t length); 86 87 /// See original's library documentation for details. 88 ubyte* gcry_md_read (gcry_md_hd_t hd, gcry_md_algos algo = gcry_md_algos.init); 89 90 extern (D) ubyte[] gcry_md_read_slice (gcry_md_hd_t hd, gcry_md_algos algo = gcry_md_algos.init) 91 { 92 if (ubyte* data = gcry_md_read(hd, algo)) 93 { 94 return data[0 .. gcry_md_get_algo_dlen(algo? algo : gcry_md_get_algo(hd))]; 95 } 96 else 97 { 98 return null; 99 } 100 } 101 102 /// See original's library documentation for details. 103 void gcry_md_hash_buffer (gcry_md_algos algo, void* digest, 104 const(void)* buffer, size_t length); 105 106 /// See original's library documentation for details. 107 gcry_md_algos gcry_md_get_algo (gcry_md_hd_t hd); 108 109 /// See original's library documentation for details. 110 uint gcry_md_get_algo_dlen (gcry_md_algos algo); 111 112 /// See original's library documentation for details. 113 int gcry_md_is_enabled (gcry_md_hd_t a, gcry_md_algos algo); 114 115 /// See original's library documentation for details. 116 int gcry_md_is_secure (gcry_md_hd_t a); 117 118 /// See original's library documentation for details. 119 gcry_error_t gcry_md_info (gcry_md_hd_t h, gcry_ctl_cmds what, void* buffer, 120 size_t* nbytes); 121 122 /// See original's library documentation for details. 123 gcry_error_t gcry_md_algo_info (gcry_md_algos algo, gcry_ctl_cmds what, void* buffer, 124 size_t* nbytes); 125 126 /// See original's library documentation for details. 127 const(char)* gcry_md_algo_name (gcry_md_algos algo); 128 129 /// See original's library documentation for details. 130 int gcry_md_map_name (const(char)* name); 131 132 /// See original's library documentation for details. 133 gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const(void)* key, size_t keylen); 134 135 /// See original's library documentation for details. 136 void gcry_md_debug (gcry_md_hd_t hd, const(char)* suffix); 137 138 139 /// See original's library documentation for details. 140 extern (D) gcry_error_t gcry_md_test_algo(gcry_md_algos a) 141 { 142 return gcry_md_algo_info(a, gcry_ctl_cmds.GCRYCTL_TEST_ALGO, null, null); 143 } 144 145 /// See original's library documentation for details. 146 extern (D) gcry_error_t gcry_md_get_asnoid(gcry_md_algos a, ref ubyte[] b) 147 { 148 size_t len = b.length; 149 150 if (auto error = gcry_md_algo_info(a, gcry_ctl_cmds.GCRYCTL_GET_ASNOID, b.ptr, &len)) 151 { 152 return error; 153 } 154 else 155 { 156 b = b[0 .. len]; 157 return 0; 158 } 159 } 160 161 /// See original's library documentation for details. 162 gcry_error_t gcry_md_list (int* list, int* list_length);