mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 11:14:39 +00:00
Add on-the-fly SpamSum calculation support
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
|
#include "spamsum.h"
|
||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
#include "utarray.h"
|
#include "utarray.h"
|
||||||
|
|
||||||
@@ -213,14 +214,16 @@ typedef struct aaruformatContext
|
|||||||
hash_map_t *sectorHashMap; ///< Deduplication hash map (fingerprint->entry mapping).
|
hash_map_t *sectorHashMap; ///< Deduplication hash map (fingerprint->entry mapping).
|
||||||
bool deduplicate; ///< Storage deduplication active (duplicates coalesce).
|
bool deduplicate; ///< Storage deduplication active (duplicates coalesce).
|
||||||
|
|
||||||
bool rewinded; ///< True if stream has been rewound after open (write path).
|
bool rewinded; ///< True if stream has been rewound after open (write path).
|
||||||
uint64_t last_written_block; ///< Last written block number (write path).
|
uint64_t last_written_block; ///< Last written block number (write path).
|
||||||
bool calculating_md5; ///< True if whole-image MD5 being calculated on-the-fly.
|
bool calculating_md5; ///< True if whole-image MD5 being calculated on-the-fly.
|
||||||
md5_ctx md5_context; ///< Opaque MD5 context for streaming updates
|
md5_ctx md5_context; ///< Opaque MD5 context for streaming updates
|
||||||
bool calculating_sha1; ///< True if whole-image SHA-1 being calculated on-the-fly.
|
bool calculating_sha1; ///< True if whole-image SHA-1 being calculated on-the-fly.
|
||||||
sha1_ctx sha1_context; ///< Opaque SHA-1 context for streaming updates
|
sha1_ctx sha1_context; ///< Opaque SHA-1 context for streaming updates
|
||||||
bool calculating_sha256; ///< True if whole-image SHA-256 being calculated on-the-fly.
|
bool calculating_sha256; ///< True if whole-image SHA-256 being calculated on-the-fly.
|
||||||
sha256_ctx sha256_context; ///< Opaque SHA-256 context for streaming updates
|
sha256_ctx sha256_context; ///< Opaque SHA-256 context for streaming updates
|
||||||
|
bool calculating_spamsum; ///< True if whole-image SpamSum being calculated on-the-fly.
|
||||||
|
spamsum_ctx *spamsum_context; ///< Opaque SpamSum context for streaming updates
|
||||||
} aaruformatContext;
|
} aaruformatContext;
|
||||||
|
|
||||||
/** \struct DumpHardwareEntriesWithData
|
/** \struct DumpHardwareEntriesWithData
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "decls.h"
|
|
||||||
|
|
||||||
#define SPAMSUM_LENGTH 64
|
#define SPAMSUM_LENGTH 64
|
||||||
#define NUM_BLOCKHASHES 31
|
#define NUM_BLOCKHASHES 31
|
||||||
#define ROLLING_WINDOW 7
|
#define ROLLING_WINDOW 7
|
||||||
|
|||||||
@@ -516,6 +516,13 @@ int aaruf_close(void *context)
|
|||||||
ctx->checksums.hasSha256 = true;
|
ctx->checksums.hasSha256 = true;
|
||||||
aaruf_sha256_final(&ctx->sha256_context, ctx->checksums.sha256);
|
aaruf_sha256_final(&ctx->sha256_context, ctx->checksums.sha256);
|
||||||
}
|
}
|
||||||
|
if(ctx->calculating_spamsum)
|
||||||
|
{
|
||||||
|
ctx->checksums.hasSpamSum = true;
|
||||||
|
ctx->checksums.spamsum = calloc(1, FUZZY_MAX_RESULT);
|
||||||
|
aaruf_spamsum_final(ctx->spamsum_context, ctx->checksums.spamsum);
|
||||||
|
aaruf_spamsum_free(ctx->spamsum_context);
|
||||||
|
}
|
||||||
|
|
||||||
// Write the checksums block
|
// Write the checksums block
|
||||||
bool has_checksums =
|
bool has_checksums =
|
||||||
|
|||||||
@@ -325,6 +325,11 @@ void *aaruf_create(const char *filepath, const uint32_t media_type, const uint32
|
|||||||
ctx->calculating_sha256 = true;
|
ctx->calculating_sha256 = true;
|
||||||
aaruf_sha256_init(&ctx->sha256_context);
|
aaruf_sha256_init(&ctx->sha256_context);
|
||||||
}
|
}
|
||||||
|
if(parsed_options.spamsum)
|
||||||
|
{
|
||||||
|
ctx->calculating_spamsum = true;
|
||||||
|
ctx->spamsum_context = aaruf_spamsum_init();
|
||||||
|
}
|
||||||
|
|
||||||
// Is writing
|
// Is writing
|
||||||
ctx->isWriting = true;
|
ctx->isWriting = true;
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative
|
|||||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||||
// Disable SHA256 calculation
|
// Disable SHA256 calculation
|
||||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||||
|
// Disable SpamSum calculation
|
||||||
|
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ctx->last_written_block = sector_address;
|
ctx->last_written_block = sector_address;
|
||||||
@@ -172,6 +174,9 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative
|
|||||||
// Calculate SHA256 on-the-fly if requested and sector is within user sectors (not negative or overflow)
|
// Calculate SHA256 on-the-fly if requested and sector is within user sectors (not negative or overflow)
|
||||||
if(ctx->calculating_sha256 && !negative && sector_address <= ctx->imageInfo.Sectors)
|
if(ctx->calculating_sha256 && !negative && sector_address <= ctx->imageInfo.Sectors)
|
||||||
aaruf_sha256_update(&ctx->sha256_context, data, length);
|
aaruf_sha256_update(&ctx->sha256_context, data, length);
|
||||||
|
// Calculate SpamSum on-the-fly if requested and sector is within user sectors (not negative or overflow)
|
||||||
|
if(ctx->calculating_sha256 && !negative && sector_address <= ctx->imageInfo.Sectors)
|
||||||
|
aaruf_spamsum_update(&ctx->spamsum_context, data, length);
|
||||||
|
|
||||||
// TODO: If optical disc check track
|
// TODO: If optical disc check track
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user