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: fuzzy.h 253 2015-03-31 05:50:23Z a4lg $
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 
96 extern /*@only@*/ /*@null@*/ struct fuzzy_state *fuzzy_clone(const struct fuzzy_state *state);
97 
105 extern int fuzzy_set_total_input_length(struct fuzzy_state *state, uint_least64_t total_fixed_length);
106 
116 extern int fuzzy_update(struct fuzzy_state *state,
117  const unsigned char *buffer,
118  size_t buffer_size);
119 
131 extern int fuzzy_digest(const struct fuzzy_state *state,
132  /*@out@*/ char *result,
133  unsigned int flags);
134 
138 extern void fuzzy_free(/*@only@*/ struct fuzzy_state *state);
139 
152 extern int fuzzy_hash_buf(const unsigned char *buf,
153  uint32_t buf_len,
154  /*@out@*/ char *result);
155 
170 extern int fuzzy_hash_file(FILE *handle, /*@out@*/ char *result);
171 
186 extern int fuzzy_hash_stream(FILE *handle, /*@out@*/ char *result);
187 
200 extern int fuzzy_hash_filename(const char *filename, /*@out@*/ char * result);
201 
208 extern int fuzzy_compare(const char *sig1, const char *sig2);
209 
211 #define SPAMSUM_LENGTH 64
212 
215 #define FUZZY_MAX_RESULT (2 * SPAMSUM_LENGTH + 20)
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif
int fuzzy_hash_stream(FILE *handle, char *result)
Compute the fuzzy hash of a stream using an open handle.
Definition: fuzzy.c:507
int fuzzy_digest(const struct fuzzy_state *state, char *result, unsigned int flags)
Obtain the fuzzy hash from the state.
Definition: fuzzy.c:332
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:293
struct fuzzy_state * fuzzy_clone(const struct fuzzy_state *state)
Create a copy of a fuzzy_state object and return it.
Definition: fuzzy.c:154
void fuzzy_free(struct fuzzy_state *state)
Dispose a fuzzy state.
Definition: fuzzy.c:464
int fuzzy_hash_filename(const char *filename, char *result)
Compute the fuzzy hash of a file.
Definition: fuzzy.c:561
int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len, char *result)
Compute the fuzzy hash of a buffer.
Definition: fuzzy.c:469
struct fuzzy_state * fuzzy_new(void)
Construct a fuzzy_state object and return it.
Definition: fuzzy.c:134
Definition: fuzzy.c:116
int fuzzy_hash_file(FILE *handle, char *result)
Compute the fuzzy hash of a file using an open handle.
Definition: fuzzy.c:529
int fuzzy_compare(const char *sig1, const char *sig2)
Definition: fuzzy.c:733
int fuzzy_set_total_input_length(struct fuzzy_state *state, uint_least64_t total_fixed_length)
Set fixed length of input.
Definition: fuzzy.c:164