Skip to content

Commit

Permalink
Update RHash to latest master (rhash/RHash@d916787) which is after v1…
Browse files Browse the repository at this point in the history
….4.4.
  • Loading branch information
MouriNaruto committed Apr 13, 2024
1 parent b577d12 commit ef1988c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NanaZip.Codecs/RHash/aich.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ size_t rhash_aich_export(const aich_ctx* ctx, void* out, size_t size)
if (out_ptr && ARE_OPENSSL_METHODS(ctx->sha1_methods)) {
int* error_ptr = (int*)((char*)out + head_size + offsetof(aich_ctx, error));
*error_ptr |= AICH_CTX_OSSL_FLAG;
RHASH_ASSERT(sizeof(*error_ptr) == sizeof(ctx->error));
RHASH_ASSERT(sizeof(*error_ptr) == sizeof(ctx->error));
}
#endif
return exported_size;
Expand Down
4 changes: 2 additions & 2 deletions NanaZip.Codecs/RHash/byte_order.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extern "C" {
#ifdef RHASH_BYTE_ORDER
#elif defined(CPU_IA32) || defined(CPU_X64) || defined(__ia64) || defined(__ia64__) || \
defined(__alpha__) || defined(_M_ALPHA) || defined(vax) || defined(MIPSEL) || \
defined(_ARM_) || defined(__arm__) || defined(_M_ARM) || defined(_M_ARM64) || \
defined(_M_ARM64EC) || defined(__loongarch64)
defined(_ARM_) || defined(__arm__) || defined(_M_ARM64) || defined(_M_ARM64EC) || \
defined(__loongarch64)
# define RHASH_BYTE_ORDER RHASH_BYTE_ORDER_LE
#elif defined(__sparc) || defined(__sparc__) || defined(sparc) || \
defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_POWER) || \
Expand Down
3 changes: 3 additions & 0 deletions NanaZip.Codecs/RHash/hex.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ size_t rhash_base64_url_encoded_helper(char* dst, const unsigned char* src, size
char buffer[164];
RHASH_ASSERT((BASE64_LENGTH(B64_CHUNK_SIZE) + 4) <= sizeof(buffer));
RHASH_ASSERT((B64_CHUNK_SIZE % 6) == 0);
#ifdef __clang_analyzer__
memset(buffer, 0, sizeof(buffer));
#endif
if (url_encode) {
size_t result_length = 0;
for (; length > 0; src += B64_CHUNK_SIZE) {
Expand Down
26 changes: 13 additions & 13 deletions NanaZip.Codecs/RHash/torrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ void bt_final(torrent_ctx* ctx, unsigned char result[20])
static int bt_str_ensure_length(torrent_ctx* ctx, size_t length)
{
char* new_str;
if (ctx->error)
return 0;
if (length >= ctx->content.allocated) {
if (ctx->error)
return 0;
if (length >= ctx->content.allocated) {
length++; /* allocate one character more */
if (length < 64) length = 64;
else length = (length + 255) & ~255;
Expand Down Expand Up @@ -529,10 +529,10 @@ static void bt_generate_torrent(torrent_ctx* ctx)

/* calculate BTIH */
SHA1_INIT(ctx);
if (ctx->content.str) {
SHA1_UPDATE(ctx, (unsigned char*)ctx->content.str + info_start_pos,
ctx->content.length - info_start_pos - 1);
}
if (ctx->content.str) {
SHA1_UPDATE(ctx, (unsigned char*)ctx->content.str + info_start_pos,
ctx->content.length - info_start_pos - 1);
}
SHA1_FINAL(ctx, ctx->btih);
}

Expand Down Expand Up @@ -764,7 +764,7 @@ size_t bt_export(const torrent_ctx* ctx, void* out, size_t size)
if (out_ptr) {
if (size < exported_size)
return 0;
assert(ctx->content.str != NULL);
assert(ctx->content.str != NULL);
memcpy(out_ptr, ctx->content.str, ctx->content.length + 1);
out_ptr += aligned_length;
}
Expand All @@ -773,11 +773,11 @@ size_t bt_export(const torrent_ctx* ctx, void* out, size_t size)
assert(!out || (size_t)(out_ptr - (char*)out) == exported_size);

#if defined(USE_OPENSSL)
if (out_ptr && ARE_OPENSSL_METHODS(ctx->sha1_methods)) {
size_t* error_ptr = (size_t*)((char*)out + head_size + offsetof(torrent_ctx, error));
*error_ptr |= BT_CTX_OSSL_FLAG;
RHASH_ASSERT(sizeof(*error_ptr) == sizeof(ctx->error));
}
if (out_ptr && ARE_OPENSSL_METHODS(ctx->sha1_methods)) {
size_t* error_ptr = (size_t*)((char*)out + head_size + offsetof(torrent_ctx, error));
*error_ptr |= BT_CTX_OSSL_FLAG;
RHASH_ASSERT(sizeof(*error_ptr) == sizeof(ctx->error));
}
#endif
return exported_size;
}
Expand Down
7 changes: 4 additions & 3 deletions NanaZip.Codecs/RHash/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef UTIL_H
#define UTIL_H

#include <stdlib.h> /* for aligned_alloc and __GLIBC__ version macros */

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -42,11 +44,11 @@ extern "C" {
# define rhash_aligned_free(ptr) _aligned_free(ptr)

#elif !defined(NO_STDC_ALIGNED_ALLOC) && (__STDC_VERSION__ >= 201112L || defined(_ISOC11_SOURCE)) \
&& !defined(__APPLE__) && !defined(__HAIKU__) \
&& !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__sun) \
&& (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 15)) \
&& (!defined(__ANDROID_API__) || __ANDROID_API__ >= 28)

# define HAS_STDC_ALIGNED_ALLOC
# include <stdlib.h>
# define rhash_aligned_alloc(alignment, size) aligned_alloc((alignment), ALIGN_SIZE_BY(size, alignment))
# define rhash_aligned_free(ptr) free(ptr)

Expand All @@ -57,7 +59,6 @@ extern "C" {
# if !defined(NO_POSIX_ALIGNED_ALLOC) && (_POSIX_VERSION >= 200112L || _XOPEN_SOURCE >= 600)

# define HAS_POSIX_ALIGNED_ALLOC
# include <stdlib.h>
# define rhash_aligned_alloc(alignment, size) rhash_px_aalloc((alignment), ALIGN_SIZE_BY(size, sizeof(void*)))
# define rhash_aligned_free(ptr) free(ptr)
void* rhash_px_aalloc(size_t size, size_t alignment);
Expand Down

0 comments on commit ef1988c

Please sign in to comment.