mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Add SHA-1 checksum calculation support
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "hash_map.h"
|
||||
#include "lru.h"
|
||||
#include "md5.h"
|
||||
#include "sha1.h"
|
||||
#include "structs.h"
|
||||
#include "utarray.h"
|
||||
|
||||
@@ -215,6 +216,8 @@ typedef struct aaruformatContext
|
||||
uint64_t last_written_block; ///< Last written block number (write path).
|
||||
bool calculating_md5; ///< True if whole-image MD5 being calculated on-the-fly.
|
||||
md5_ctx md5_context; ///< Opaque MD5 context for streaming updates
|
||||
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
|
||||
} aaruformatContext;
|
||||
|
||||
/** \struct DumpHardwareEntriesWithData
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "crc64.h"
|
||||
#include "md5.h"
|
||||
#include "sha1.h"
|
||||
#include "simd.h"
|
||||
#include "spamsum.h"
|
||||
#ifdef __cplusplus
|
||||
@@ -163,6 +164,11 @@ AARU_EXPORT void AARU_CALL aaruf_md5_update(md5_ctx *ctx, const void *data, unsi
|
||||
AARU_EXPORT void AARU_CALL aaruf_md5_final(md5_ctx *ctx, unsigned char *result);
|
||||
AARU_EXPORT void AARU_CALL aaruf_md5_buffer(const void *data, unsigned long size, unsigned char *result);
|
||||
|
||||
AARU_EXPORT void AARU_CALL aaruf_sha1_init(sha1_ctx *ctx);
|
||||
AARU_EXPORT void AARU_CALL aaruf_sha1_update(sha1_ctx *ctx, const void *data, unsigned long size);
|
||||
AARU_EXPORT void AARU_CALL aaruf_sha1_final(sha1_ctx *ctx, unsigned char *result);
|
||||
AARU_EXPORT void AARU_CALL aaruf_sha1_buffer(const void *data, unsigned long size, unsigned char *result);
|
||||
|
||||
#if defined(__x86_64__) || defined(__amd64) || defined(_M_AMD64) || defined(_M_X64) || defined(__I386__) || \
|
||||
defined(__i386__) || defined(__THW_INTEL) || defined(_M_IX86)
|
||||
|
||||
|
||||
53
include/sha1.h
Normal file
53
include/sha1.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Public domain or MIT-licensed SHA-1 implementation for libaaruformat.
|
||||
*
|
||||
* Based on a clean-room implementation referencing the FIPS PUB 180-1 specification.
|
||||
*
|
||||
* This code is released into the public domain. If that is not recognized
|
||||
* in your jurisdiction, you may treat it under the terms of the MIT license:
|
||||
*
|
||||
* MIT License
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef LIBAARUFORMAT_SHA1_H
|
||||
#define LIBAARUFORMAT_SHA1_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef SHA1_DIGEST_LENGTH
|
||||
#define SHA1_DIGEST_LENGTH 20
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t state[5]; /* A,B,C,D,E */
|
||||
uint64_t count; /* Bits processed */
|
||||
uint8_t buffer[64];
|
||||
} sha1_ctx;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LIBAARUFORMAT_SHA1_H */
|
||||
Reference in New Issue
Block a user