]> FriiDump Source - friidump.git/blob - libmultihash/multihash.h
FriiDump 0.5.3.16 candidate: add native reports and Linux Xbox support
[friidump.git] / libmultihash / multihash.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by SukkoPera   *
3  *   sukkopera@sukkology.net   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef MULTIHASH_H_INCLUDED
22 #define MULTIHASH_H_INCLUDED
23
24 #ifdef WIN32
25 #include <windows.h>
26
27 /* Definition of the types we use for Windows */
28 #define u_int8_t BYTE
29 #define u_int16_t WORD
30 #define u_int32_t DWORD
31
32 /* Modern MSVC/UCRT provides snprintf; do not macro-alias it. */
33
34 /* Stuff to export library symbols */
35 #ifdef MULTIHASH_BUILD_DLL
36 #ifdef MULTIHASH_EXPORTS
37 #define MULTIHASH_EXPORT __declspec(dllexport)  /* Building the lib */
38 #else
39 #define MULTIHASH_EXPORT __declspec(dllimport)  /* Building user code */
40 #endif
41 #else
42 #define MULTIHASH_EXPORT
43 #endif
44
45 #else   /* !WIN32 */
46
47 #define MULTIHASH_EXPORT
48
49 #endif
50
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 #define USE_CRC32
57 #define USE_MD4
58 #define USE_MD5
59 #define USE_ED2K
60 #define USE_SHA1
61 #define USE_SHA2
62
63 #ifdef USE_CRC32
64 #include <sys/types.h>
65 #include "crc32.h"
66 #define LEN_CRC32 8
67 #endif
68
69 #ifdef USE_MD4
70 #include "md4.h"
71 #define LEN_MD4 32
72 #define MD4_DIGESTSIZE 16
73 #endif
74
75 #ifdef USE_MD5
76 #include "md5.h"
77 #define LEN_MD5 32
78 #endif
79
80 #ifdef USE_ED2K
81 #include "edonkey.h"
82 #define LEN_ED2K 32
83 #endif
84
85 #ifdef USE_SHA1
86 #include "sha1.h"
87 #define LEN_SHA1 40
88 #endif
89
90 #ifdef USE_SHA2
91 #include "sha2.h"
92 #define LEN_SHA2 64
93 #endif
94
95 /* This must be as long as the longest hash (in bytes) */
96 #define MAX_DIGESTSIZE 32
97
98 typedef struct {
99 #ifdef USE_CRC32
100         u_int32_t crc32;
101         char crc32_s[LEN_CRC32 + 1];
102 #endif
103 #ifdef USE_MD4
104         md4_context md4;
105         char md4_s[LEN_MD4 + 1];
106 #endif
107 #ifdef USE_MD5
108         Md5Context md5;
109         char md5_s[LEN_MD5 + 1];
110 #endif
111 #ifdef USE_ED2K
112         ed2khash_context ed2k;
113         char ed2k_s[LEN_ED2K + 1];
114 #endif
115 #ifdef USE_SHA1
116         Sha1Context sha1;
117         char sha1_s[LEN_SHA1 + 1];
118 #endif
119 #ifdef USE_SHA2
120         Sha256Context sha2;
121         char sha2_s[LEN_SHA2 + 1];
122 #endif
123 } multihash;
124
125
126 /* Prototypes */
127 MULTIHASH_EXPORT void multihash_init (multihash *mh);
128 MULTIHASH_EXPORT void multihash_update (multihash *mh, unsigned char *data, int bytes);
129 MULTIHASH_EXPORT void multihash_finish (multihash *mh);
130 MULTIHASH_EXPORT int multihash_file (multihash *mh, char *filename);
131
132 #ifdef __cplusplus
133 }
134 #endif
135
136 #endif