Fuzzy Hashing API
fuzzy.h
Go to the documentation of this file.
1 #ifndef FUZZY_H
2 #define FUZZY_H
3 
4 /*
5  * Copyright (C) ManTech International Corporation 2010
6  * Copyright (C) Kyrus 2012
7  * Copyright (C) 2013 Helmut Grohne <helmut@subdivi.de>
8  *
9  * $Id$
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24  *
25  * Earlier versions of this code can be found at:
26  * http://ssdeep.sf.net/
27  */
28 
43 
57 
58 
59 #include <stdint.h>
60 #include <stdio.h>
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
70 #define FUZZY_FLAG_ELIMSEQ 0x1u
71 
75 #define FUZZY_FLAG_NOTRUNC 0x2u
76 
77 struct fuzzy_state;
78 
86 extern /*@only@*/ /*@null@*/ struct fuzzy_state *fuzzy_new(void);
87 
97 extern /*@only@*/ /*@null@*/ struct fuzzy_state *fuzzy_clone(const struct fuzzy_state *state);
98 
108 extern int fuzzy_set_total_input_length(struct fuzzy_state *state, uint_least64_t total_fixed_length);
109 
120 extern int fuzzy_update(struct fuzzy_state *state,
121  const unsigned char *buffer,
122  size_t buffer_size);
123 
136 extern int fuzzy_digest(const struct fuzzy_state *state,
137  /*@out@*/ char *result,
138  unsigned int flags);
139 
144 extern void fuzzy_free(/*@only@*/ struct fuzzy_state *state);
145 
158 extern int fuzzy_hash_buf(const unsigned char *buf,
159  uint32_t buf_len,
160  /*@out@*/ char *result);
161 
176 extern int fuzzy_hash_file(FILE *handle, /*@out@*/ char *result);
177 
192 extern int fuzzy_hash_stream(FILE *handle, /*@out@*/ char *result);
193 
206 extern int fuzzy_hash_filename(const char *filename, /*@out@*/ char * result);
207 
214 extern int fuzzy_compare(const char *sig1, const char *sig2);
215 
217 #define SPAMSUM_LENGTH 64
218 
221 #define FUZZY_MAX_RESULT (2 * SPAMSUM_LENGTH + 20)
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif
int fuzzy_hash_stream(FILE *handle, char *result)
Compute the fuzzy hash of a stream using an open handle.
Definition: fuzzy.c:538
int fuzzy_digest(const struct fuzzy_state *state, char *result, unsigned int flags)
Obtain the fuzzy hash from the state.
Definition: fuzzy.c:360
int fuzzy_update(struct fuzzy_state *state, const unsigned char *buffer, size_t buffer_size)
Feed the data contained in the given buffer to the state.
Definition: fuzzy.c:323
struct fuzzy_state * fuzzy_clone(const struct fuzzy_state *state)
Create a copy of a fuzzy_state object and return it.
Definition: fuzzy.c:169
void fuzzy_free(struct fuzzy_state *state)
Dispose a fuzzy state.
Definition: fuzzy.c:495
int fuzzy_hash_filename(const char *filename, char *result)
Compute the fuzzy hash of a file.
Definition: fuzzy.c:592
int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len, char *result)
Compute the fuzzy hash of a buffer.
Definition: fuzzy.c:500
struct fuzzy_state * fuzzy_new(void)
Construct a fuzzy_state object and return it.
Definition: fuzzy.c:147
Definition: fuzzy.c:127
int fuzzy_hash_file(FILE *handle, char *result)
Compute the fuzzy hash of a file using an open handle.
Definition: fuzzy.c:560
int fuzzy_compare(const char *sig1, const char *sig2)
Definition: fuzzy.c:852
int fuzzy_set_total_input_length(struct fuzzy_state *state, uint_least64_t total_fixed_length)
Set fixed length of input.
Definition: fuzzy.c:183