Files
Aaru.Checksums.Native/spamsum.h

71 lines
2.1 KiB
C
Raw Normal View History

2021-09-22 00:46:07 +01:00
/*
* This file is part of the Aaru Data Preservation Suite.
2024-12-19 15:21:40 +00:00
* Copyright (c) 2019-2025 Natalia Portillo.
2021-09-22 00:46:07 +01:00
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
2021-10-13 03:30:02 +01:00
#ifndef AARU_CHECKSUMS_NATIVE_SPAMSUM_H
#define AARU_CHECKSUMS_NATIVE_SPAMSUM_H
2024-04-30 15:12:48 +01:00
#define SPAMSUM_LENGTH 64
#define NUM_BLOCKHASHES 31
#define ROLLING_WINDOW 7
#define HASH_INIT 0x28021967
#define HASH_PRIME 0x01000193
#define MIN_BLOCKSIZE 3
2021-09-22 01:27:28 +01:00
#define FUZZY_MAX_RESULT ((2 * SPAMSUM_LENGTH) + 20)
2021-09-22 00:46:07 +01:00
2021-09-22 01:27:28 +01:00
typedef struct
2021-09-22 00:46:07 +01:00
{
2021-09-22 01:27:28 +01:00
uint32_t h;
uint32_t half_h;
uint8_t digest[SPAMSUM_LENGTH];
uint8_t half_digest;
uint32_t d_len;
2021-09-22 01:05:23 +01:00
} blockhash_ctx;
2021-09-22 00:46:07 +01:00
2021-09-22 01:27:28 +01:00
typedef struct
2021-09-22 00:46:07 +01:00
{
2021-09-22 01:05:23 +01:00
uint8_t window[ROLLING_WINDOW];
uint32_t h1;
uint32_t h2;
uint32_t h3;
uint32_t n;
} roll_state;
2021-09-22 00:46:07 +01:00
2021-09-22 01:27:28 +01:00
typedef struct
2021-09-22 00:46:07 +01:00
{
2021-09-22 01:27:28 +01:00
uint32_t bh_start;
uint32_t bh_end;
blockhash_ctx bh[NUM_BLOCKHASHES];
uint64_t total_size;
roll_state roll;
2021-09-22 00:46:07 +01:00
} spamsum_ctx;
2023-09-23 18:55:52 +01:00
AARU_EXPORT spamsum_ctx *AARU_CALL spamsum_init(void);
2024-04-30 15:12:48 +01:00
AARU_EXPORT int AARU_CALL spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len);
AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx *ctx, uint8_t *result);
AARU_EXPORT void AARU_CALL spamsum_free(spamsum_ctx *ctx);
2021-09-22 00:46:07 +01:00
2023-09-23 18:55:52 +01:00
FORCE_INLINE void fuzzy_engine_step(spamsum_ctx *ctx, uint8_t c);
FORCE_INLINE void roll_hash(spamsum_ctx *ctx, uint8_t c);
FORCE_INLINE void fuzzy_try_reduce_blockhash(spamsum_ctx *ctx);
FORCE_INLINE void fuzzy_try_fork_blockhash(spamsum_ctx *ctx);
2021-10-13 03:30:02 +01:00
2024-04-30 15:12:48 +01:00
#endif // AARU_CHECKSUMS_NATIVE_SPAMSUM_H