Loading...
Searching...
No Matches
spamsum.c File Reference
`#include <errno.h>`
`#include <stdint.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "aaruformat.h"`
`#include "spamsum.h"`

Go to the source code of this file.

## Macros

#define | ROLL_SUM(ctx)
#define | SUM_HASH(c, h)
#define | SSDEEP_BS(index)

## Functions

spamsum_ctx * | aaruf_spamsum_init (void)
int | aaruf_spamsum_update (spamsum_ctx *ctx, const uint8_t *data, const uint32_t len)
| Updates the spamsum context with new data.
void | aaruf_spamsum_free (spamsum_ctx *ctx)
| Frees a spamsum (fuzzy hash) context.
void | fuzzy_engine_step (spamsum_ctx *ctx, uint8_t c)
void | roll_hash (spamsum_ctx *ctx, uint8_t c)
void | fuzzy_try_reduce_blockhash (spamsum_ctx *ctx)
void | fuzzy_try_fork_blockhash (spamsum_ctx *ctx)
int | aaruf_spamsum_final (spamsum_ctx *ctx, uint8_t *result)

## Variables

static uint8_t | b64 []

## Macro Definition Documentation

## ROLL_SUM

#define ROLL_SUM | ( |  | ctx | ) |

Value:
((ctx)->roll.h1 + (ctx)->roll.h2 + (ctx)->roll.h3)

Definition at line 80 of file spamsum.c.

Referenced by aaruf_spamsum_final(), and fuzzy_engine_step().

## SSDEEP_BS

#define SSDEEP_BS | ( |  | index | ) |

Value:
(MIN_BLOCKSIZE << (index))
MIN_BLOCKSIZE
#define MIN_BLOCKSIZE
Definition spamsum.h:29

Definition at line 82 of file spamsum.c.

Referenced by aaruf_spamsum_final(), fuzzy_engine_step(), and fuzzy_try_reduce_blockhash().

## SUM_HASH

#define SUM_HASH | ( |  | c,
|  |  | h )

Value:
(((h) * HASH_PRIME) ^ (c));
HASH_PRIME
#define HASH_PRIME
Definition spamsum.h:28

Definition at line 81 of file spamsum.c.

Referenced by fuzzy_engine_step().

## Function Documentation

## aaruf_spamsum_final()

int aaruf_spamsum_final | ( | spamsum_ctx * | ctx,
|  | uint8_t * | result )

Definition at line 191 of file spamsum.c.

References AARU_CALL, AARU_EXPORT, b64, spamsum_ctx::bh, spamsum_ctx::bh_end, spamsum_ctx::bh_start, blockhash_ctx::d_len, blockhash_ctx::digest, FUZZY_MAX_RESULT, blockhash_ctx::h, blockhash_ctx::half_digest, blockhash_ctx::half_h, NUM_BLOCKHASHES, ROLL_SUM, SPAMSUM_LENGTH, and SSDEEP_BS.

Referenced by write_checksum_block().

## aaruf_spamsum_free()

void aaruf_spamsum_free | ( | spamsum_ctx * | ctx | ) |

Frees a spamsum (fuzzy hash) context.

Parameters

  ctx | Pointer to the spamsum context to free.

Definition at line 75 of file spamsum.c.

References AARU_CALL, and AARU_EXPORT.

Referenced by cleanup_failed_create(), and write_checksum_block().

## aaruf_spamsum_init()

spamsum_ctx * aaruf_spamsum_init | ( | void |  | ) |

Definition at line 37 of file spamsum.c.

References AARU_CALL, AARU_EXPORT, spamsum_ctx::bh, spamsum_ctx::bh_end, blockhash_ctx::h, blockhash_ctx::half_h, and HASH_INIT.

Referenced by aaruf_create().

## aaruf_spamsum_update()

int aaruf_spamsum_update | ( | spamsum_ctx * | ctx,
|  | const uint8_t * | data,
|  | const uint32_t | len )

Updates the spamsum context with new data.

Parameters

  ctx | Pointer to the spamsum context.
  data | Pointer to the data to process.
  len | Length of the data in bytes.

Returns
  0 on success, -1 on error.

Definition at line 59 of file spamsum.c.

References AARU_CALL, AARU_EXPORT, fuzzy_engine_step(), and spamsum_ctx::total_size.

Referenced by aaruf_write_sector(), and aaruf_write_sector_long().

## fuzzy_engine_step()

void fuzzy_engine_step | ( | spamsum_ctx * | ctx,
|  | uint8_t | c )

inline

Definition at line 84 of file spamsum.c.

References AARU_LOCAL, b64, spamsum_ctx::bh, spamsum_ctx::bh_start, blockhash_ctx::d_len, blockhash_ctx::digest, fuzzy_try_fork_blockhash(), fuzzy_try_reduce_blockhash(), blockhash_ctx::h, blockhash_ctx::half_digest, blockhash_ctx::half_h, HASH_INIT, roll_hash(), ROLL_SUM, SPAMSUM_LENGTH, SSDEEP_BS, and SUM_HASH.

Referenced by aaruf_spamsum_update().

## fuzzy_try_fork_blockhash()

void fuzzy_try_fork_blockhash | ( | spamsum_ctx * | ctx | ) |

inline

Definition at line 175 of file spamsum.c.

References AARU_LOCAL, spamsum_ctx::bh, spamsum_ctx::bh_end, blockhash_ctx::d_len, blockhash_ctx::digest, blockhash_ctx::h, blockhash_ctx::half_digest, blockhash_ctx::half_h, and NUM_BLOCKHASHES.

Referenced by fuzzy_engine_step().

## fuzzy_try_reduce_blockhash()

void fuzzy_try_reduce_blockhash | ( | spamsum_ctx * | ctx | ) |

inline

Definition at line 155 of file spamsum.c.

References AARU_LOCAL, spamsum_ctx::bh, spamsum_ctx::bh_end, spamsum_ctx::bh_start, blockhash_ctx::d_len, SPAMSUM_LENGTH, SSDEEP_BS, and spamsum_ctx::total_size.

Referenced by fuzzy_engine_step().

## roll_hash()

void roll_hash | ( | spamsum_ctx * | ctx,
|  | uint8_t | c )

inline

Definition at line 137 of file spamsum.c.

References AARU_LOCAL, roll_state::h1, roll_state::h2, roll_state::h3, roll_state::n, spamsum_ctx::roll, ROLLING_WINDOW, and roll_state::window.

Referenced by fuzzy_engine_step().

## Variable Documentation

## b64

uint8_t b64[]

static

Initial value:
= {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F}

Definition at line 32 of file spamsum.c.

Referenced by aaruf_spamsum_final(), and fuzzy_engine_step().