diff options
author | Helmut Grohne <helmut@subdivi.de> | 2013-03-24 14:25:57 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2013-03-24 14:25:57 +0100 |
commit | 95f03d03491f0673d4c527f5a23697be44ad0a28 (patch) | |
tree | 9c28dc0506ce1608d35bdbc60cae283ed5067fe9 | |
parent | 2c21b4f1203ba69727c64f1a3bf2fe84cc1565db (diff) | |
download | ssdeep-95f03d03491f0673d4c527f5a23697be44ad0a28.tar.gz |
ship a fuzzy.h compatible with ssdeep's fuzzy.h
-rw-r--r-- | fuzzy.c | 3 | ||||
-rw-r--r-- | fuzzy.h | 104 |
2 files changed, 105 insertions, 2 deletions
@@ -27,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "fuzzy.h" #if defined(__GNUC__) && __GNUC__ >= 3 #define likely(x) __builtin_expect(!!(x), 1) @@ -36,8 +37,6 @@ #define unlikely(x) x #endif -#define SPAMSUM_LENGTH 64 -#define FUZZY_MAX_RESULT (SPAMSUM_LENGTH + (SPAMSUM_LENGTH/2 + 20)) #define ROLLING_WINDOW 7 #define MIN_BLOCKSIZE 3 #define HASH_PRIME 0x01000193 @@ -0,0 +1,104 @@ +/* + * Copyright (C) ManTech International Corporation 2010 + * Copyright (C) 2013 Helmut Grohne <helmut@subdivi.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Earlier versions of this code can be found at: + * http://ssdeep.sf.net/ + */ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef FUZZY_H +#define FUZZY_H + +/** + * @brief Compute the fuzzy hash of a buffer + * + * The computes the fuzzy hash of the first buf_len bytes of the buffer. + * It is the caller's responsibility to append the filename, + * if any, to result after computation. + * @param buf The data to be fuzzy hashed + * @param buf_len The length of the data being hashed + * @param result Where the fuzzy hash of buf is stored. This variable + * must be allocated to hold at least FUZZY_MAX_RESULT bytes. + * @return Returns zero on success, non-zero on error. + */ +extern int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len, + /*@out@*/ char *result); + +/** + * @brief Compute the fuzzy hash of a file using an open handle + * + * Computes the fuzzy hash of the contents of the open file, starting + * at the beginning of the file. When finished, the file pointer is + * returned to its original position. If an error occurs, the file + * pointer's value is undefined. + * It is the callers's responsibility to append the filename + * to the result after computation. + * @param handle Open handle to the file to be hashed + * @param result Where the fuzzy hash of the file is stored. This + * variable must be allocated to hold at least FUZZY_MAX_RESULT bytes. + * @return Returns zero on success, non-zero on error + */ +extern int fuzzy_hash_file(FILE *handle, /*@out@*/ char *result); + +/** + * @brief Compute the fuzzy hash of a stream using an open handle + * + * Computes the fuzzy hash of the contents of the open stream, starting at the + * current file position until reaching EOF. Unlike fuzzy_hash_file the stream + * is never seeked. If an error occurs, the result as well as the file position + * are undefined. + * It is the callers's responsibility to append the filename + * to the result after computation. + * @param handle Open handle to the stream to be hashed + * @param result Where the fuzzy hash of the file is stored. This + * variable must be allocated to hold at least FUZZY_MAX_RESULT bytes. + * @return Returns zero on success, non-zero on error + */ +extern int fuzzy_hash_stream(FILE *handle, /*@out@*/ char *result); + +/** + * @brief Compute the fuzzy hash of a file + * + * Opens, reads, and hashes the contents of the file 'filename' + * The result must be allocated to hold FUZZY_MAX_RESULT characters. + * It is the caller's responsibility to append the filename + * to the result after computation. + * @param filename The file to be hashed + * @param result Where the fuzzy hash of the file is stored. This + * variable must be allocated to hold at least FUZZY_MAX_RESULT bytes. + * @return Returns zero on success, non-zero on error. + */ +extern int fuzzy_hash_filename(const char *filename, /*@out@*/ char * result); + +/** Length of an individual fuzzy hash signature component. */ +#define SPAMSUM_LENGTH 64 + +/** The longest possible length for a fuzzy hash signature + * (without the filename) */ +#define FUZZY_MAX_RESULT (SPAMSUM_LENGTH + (SPAMSUM_LENGTH/2 + 20)) + +#ifdef __cplusplus +} +#endif + +#endif |