aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/check/sha256.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
commit7d17818cec8597f847b0a2537fde991bbc3d9e96 (patch)
tree9c41502e3eb96f103fe98e13456b382fbba7a292 /src/liblzma/check/sha256.c
parentUpdate the file format specification draft. The new one is (diff)
downloadxz-7d17818cec8597f847b0a2537fde991bbc3d9e96.tar.xz
Update the code to mostly match the new simpler file format
specification. Simplify things by removing most of the support for known uncompressed size in most places. There are some miscellaneous changes here and there too. The API of liblzma has got many changes and still some more will be done soon. While most of the code has been updated, some things are not fixed (the command line tool will choke with invalid filter chain, if nothing else). Subblock filter is somewhat broken for now. It will be updated once the encoded format of the Subblock filter has been decided.
Diffstat (limited to '')
-rw-r--r--src/liblzma/check/sha256.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/liblzma/check/sha256.c b/src/liblzma/check/sha256.c
index 8e3d375a..ea51896e 100644
--- a/src/liblzma/check/sha256.c
+++ b/src/liblzma/check/sha256.c
@@ -20,7 +20,7 @@
#include "check.h"
#ifndef WORDS_BIGENDIAN
-# include "check_byteswap.h"
+# include "../../common/bswap.h"
#endif
// At least on x86, GCC is able to optimize this to a rotate instruction.
@@ -104,18 +104,18 @@ transform(uint32_t state[static 8], const uint32_t data[static 16])
static void
-process(lzma_sha256 *sha256)
+process(lzma_check *check)
{
#ifdef WORDS_BIGENDIAN
- transform(sha256->state, (uint32_t *)(sha256->buffer));
+ transform(check->state.sha256.state, (uint32_t *)(check->buffer));
#else
uint32_t data[16];
for (size_t i = 0; i < 16; ++i)
- data[i] = bswap_32(*((uint32_t*)(sha256->buffer) + i));
+ data[i] = bswap_32(*((uint32_t*)(check->buffer) + i));
- transform(sha256->state, data);
+ transform(check->state.sha256.state, data);
#endif
return;
@@ -123,41 +123,41 @@ process(lzma_sha256 *sha256)
extern void
-lzma_sha256_init(lzma_sha256 *sha256)
+lzma_sha256_init(lzma_check *check)
{
static const uint32_t s[8] = {
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
};
- memcpy(sha256->state, s, sizeof(s));
- sha256->size = 0;
+ memcpy(check->state.sha256.state, s, sizeof(s));
+ check->state.sha256.size = 0;
return;
}
extern void
-lzma_sha256_update(const uint8_t *buf, size_t size, lzma_sha256 *sha256)
+lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check *check)
{
// Copy the input data into a properly aligned temporary buffer.
// This way we can be called with arbitrarily sized buffers
// (no need to be multiple of 64 bytes), and the code works also
// on architectures that don't allow unaligned memory access.
while (size > 0) {
- const size_t copy_start = sha256->size & 0x3F;
+ const size_t copy_start = check->state.sha256.size & 0x3F;
size_t copy_size = 64 - copy_start;
if (copy_size > size)
copy_size = size;
- memcpy(sha256->buffer + copy_start, buf, copy_size);
+ memcpy(check->buffer + copy_start, buf, copy_size);
buf += copy_size;
size -= copy_size;
- sha256->size += copy_size;
+ check->state.sha256.size += copy_size;
- if ((sha256->size & 0x3F) == 0)
- process(sha256);
+ if ((check->state.sha256.size & 0x3F) == 0)
+ process(check);
}
return;
@@ -165,38 +165,41 @@ lzma_sha256_update(const uint8_t *buf, size_t size, lzma_sha256 *sha256)
extern void
-lzma_sha256_finish(lzma_sha256 *sha256)
+lzma_sha256_finish(lzma_check *check)
{
// Add padding as described in RFC 3174 (it describes SHA-1 but
// the same padding style is used for SHA-256 too).
- size_t pos = sha256->size & 0x3F;
- sha256->buffer[pos++] = 0x80;
+ size_t pos = check->state.sha256.size & 0x3F;
+ check->buffer[pos++] = 0x80;
while (pos != 64 - 8) {
if (pos == 64) {
- process(sha256);
+ process(check);
pos = 0;
}
- sha256->buffer[pos++] = 0x00;
+ check->buffer[pos++] = 0x00;
}
// Convert the message size from bytes to bits.
- sha256->size *= 8;
+ check->state.sha256.size *= 8;
#ifdef WORDS_BIGENDIAN
- *(uint64_t *)(sha256->buffer + 64 - 8) = sha256->size;
+ *(uint64_t *)(check->buffer + 64 - 8) = check->state.sha256.size;
#else
- *(uint64_t *)(sha256->buffer + 64 - 8) = bswap_64(sha256->size);
+ *(uint64_t *)(check->buffer + 64 - 8)
+ = bswap_64(check->state.sha256.size);
#endif
- process(sha256);
+ process(check);
for (size_t i = 0; i < 8; ++i)
#ifdef WORDS_BIGENDIAN
- ((uint32_t *)(sha256->buffer))[i] = sha256->state[i];
+ ((uint32_t *)(check->buffer))[i]
+ = check->state.sha256.state[i];
#else
- ((uint32_t *)(sha256->buffer))[i] = bswap_32(sha256->state[i]);
+ ((uint32_t *)(check->buffer))[i]
+ = bswap_32(check->state.sha256.state[i]);
#endif
return;