Skip to content

Commit

Permalink
Aim to fix the duplicated sha symbols from rvc cyclic dep ##build
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Nov 2, 2024
1 parent acde077 commit e25d1be
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 82 deletions.
59 changes: 29 additions & 30 deletions libr/crypto/hash/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,10 @@ static const ut64 sha512_initial_hash_value[8] = {
* Constant used by SHA256/384/512_End() functions for converting the
* digest to a readable hexadecimal character string:
*/
static const char * const sha2_hex_digits = "0123456789abcdef";
static const char sha2_hex_digits[] = "0123456789abcdef";


/*** SHA-256: *********************************************************/
R_IPI void r_sha256_init(RSha256Context *context) {
R_IPI void R_SHA2_API(r_sha256_init)(RSha256Context *context) {
if (context == (RSha256Context *) 0) {
return;
}
Expand Down Expand Up @@ -465,7 +464,7 @@ static void SHA256_Transform(RSha256Context *context, const ut32 *data) {

#endif /* SHA2_UNROLL_TRANSFORM */

R_IPI void r_sha256_update(RSha256Context *context, const ut8 *data, size_t len) {
R_IPI void R_SHA2_API(r_sha256_update)(RSha256Context *context, const ut8 *data, size_t len) {
R_RETURN_IF_FAIL (context);
if (!data || len == 0) {
return;
Expand Down Expand Up @@ -503,7 +502,7 @@ R_IPI void r_sha256_update(RSha256Context *context, const ut8 *data, size_t len)
}
}

R_IPI void r_sha256_final(ut8 digest[R_SHA256_DIGEST_LENGTH], RSha256Context *context) {
R_IPI void R_SHA2_API(r_sha256_final)(ut8 digest[R_SHA256_DIGEST_LENGTH], RSha256Context *context) {
R_RETURN_IF_FAIL (context);
ut32 *d = (ut32 *) digest;
unsigned int usedspace;
Expand Down Expand Up @@ -570,7 +569,7 @@ R_IPI void r_sha256_final(ut8 digest[R_SHA256_DIGEST_LENGTH], RSha256Context *co
usedspace = 0;
}

R_IPI char *r_sha256_end(RSha256Context *context, char buffer[R_SHA256_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha256_end)(RSha256Context *context, char buffer[R_SHA256_DIGEST_STRING_LENGTH]) {
ut8 digest[R_SHA256_DIGEST_LENGTH], *d = digest;
int i;

Expand All @@ -579,7 +578,7 @@ R_IPI char *r_sha256_end(RSha256Context *context, char buffer[R_SHA256_DIGEST_ST
}

if (buffer) {
r_sha256_final (digest, context);
R_SHA2_API (r_sha256_final) (digest, context);
for (i = 0; i < R_SHA256_DIGEST_LENGTH; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
Expand All @@ -593,15 +592,15 @@ R_IPI char *r_sha256_end(RSha256Context *context, char buffer[R_SHA256_DIGEST_ST
return buffer;
}

R_IPI char *r_sha256_data(const ut8 *data, size_t len, char digest[R_SHA256_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha256_data)(const ut8 *data, size_t len, char digest[R_SHA256_DIGEST_STRING_LENGTH]) {
RSha256Context context;
r_sha256_init (&context);
r_sha256_update (&context, data, len);
return r_sha256_end (&context, digest);
R_SHA2_API (r_sha256_init) (&context);
R_SHA2_API (r_sha256_update) (&context, data, len);
return R_SHA2_API (r_sha256_end) (&context, digest);
}

/*** SHA-512: *********************************************************/
R_IPI void r_sha512_init(RSha512Context *context) {
R_IPI void R_SHA2_API(r_sha512_init)(RSha512Context *context) {
if (context == (RSha512Context *) 0) {
return;
}
Expand Down Expand Up @@ -778,7 +777,7 @@ static void SHA512_Transform(RSha512Context *context, const ut64 *data) {

#endif /* SHA2_UNROLL_TRANSFORM */

R_IPI void r_sha512_update(RSha512Context *context, const ut8 *data, size_t len) {
R_IPI void R_SHA2_API(r_sha512_update)(RSha512Context *context, const ut8 *data, size_t len) {
if (!context || !data || len < 1) {
return;
}
Expand Down Expand Up @@ -867,7 +866,7 @@ static void SHA512_Last(RSha512Context *context) {
SHA512_Transform (context, (ut64 *) context->buffer);
}

R_IPI void r_sha512_final(ut8 digest[R_SHA512_DIGEST_LENGTH], RSha512Context *context) {
R_IPI void R_SHA2_API(r_sha512_final)(ut8 digest[R_SHA512_DIGEST_LENGTH], RSha512Context *context) {
ut64 *d = (ut64 *) digest;

/* Sanity check: */
Expand Down Expand Up @@ -898,7 +897,7 @@ R_IPI void r_sha512_final(ut8 digest[R_SHA512_DIGEST_LENGTH], RSha512Context *co
r_mem_zero (context, sizeof (*context));
}

R_IPI char *r_sha512_end(RSha512Context *context, char buffer[R_SHA512_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha512_end)(RSha512Context *context, char buffer[R_SHA512_DIGEST_STRING_LENGTH]) {
ut8 digest[R_SHA512_DIGEST_LENGTH];
ut8 *d = digest;
int i;
Expand All @@ -909,7 +908,7 @@ R_IPI char *r_sha512_end(RSha512Context *context, char buffer[R_SHA512_DIGEST_ST
}

if (buffer) {
r_sha512_final (digest, context);
R_SHA2_API (r_sha512_final) (digest, context);
for (i = 0; i < R_SHA512_DIGEST_LENGTH; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
Expand All @@ -923,27 +922,27 @@ R_IPI char *r_sha512_end(RSha512Context *context, char buffer[R_SHA512_DIGEST_ST
return buffer;
}

R_IPI char *r_sha512_data(const ut8 *data, size_t len, char digest[R_SHA512_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha512_data)(const ut8 *data, size_t len, char digest[R_SHA512_DIGEST_STRING_LENGTH]) {
RSha512Context context;
r_sha512_init (&context);
r_sha512_update (&context, data, len);
return r_sha512_end (&context, digest);
R_SHA2_API (r_sha512_init) (&context);
R_SHA2_API (r_sha512_update) (&context, data, len);
return R_SHA2_API (r_sha512_end) (&context, digest);
}

/*** SHA-384: *********************************************************/
R_IPI void r_sha384_init(RSha384Context *context) {
R_IPI void R_SHA2_API(r_sha384_init)(RSha384Context *context) {
R_RETURN_IF_FAIL (context);
memcpy (context->state, sha384_initial_hash_value, R_SHA512_DIGEST_LENGTH);
memset (context->buffer, 0, R_SHA384_BLOCK_LENGTH);
context->bitcount[0] = context->bitcount[1] = 0;
}

R_IPI void r_sha384_update(RSha384Context *context, const ut8 *data, size_t len) {
R_IPI void R_SHA2_API(r_sha384_update)(RSha384Context *context, const ut8 *data, size_t len) {
// wat :D 512 is not 384 looks like a bad function name to me
r_sha512_update ((RSha512Context *) context, data, len);
R_SHA2_API (r_sha512_update) ((RSha512Context *) context, data, len);
}

R_IPI void r_sha384_final(ut8 digest[R_SHA384_DIGEST_LENGTH], RSha384Context *context) {
R_IPI void R_SHA2_API(r_sha384_final)(ut8 digest[R_SHA384_DIGEST_LENGTH], RSha384Context *context) {
ut64 *d = (ut64 *) digest;

/* Sanity check: */
Expand Down Expand Up @@ -974,7 +973,7 @@ R_IPI void r_sha384_final(ut8 digest[R_SHA384_DIGEST_LENGTH], RSha384Context *co
memset (context, 0, sizeof (*context));
}

R_IPI char *r_sha384_end(RSha384Context *context, char buffer[R_SHA384_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha384_end)(RSha384Context *context, char buffer[R_SHA384_DIGEST_STRING_LENGTH]) {
ut8 digest[R_SHA384_DIGEST_LENGTH], *d = digest;
int i;

Expand All @@ -984,7 +983,7 @@ R_IPI char *r_sha384_end(RSha384Context *context, char buffer[R_SHA384_DIGEST_ST
}

if (buffer) {
r_sha384_final (digest, context);
R_SHA2_API (r_sha384_final) (digest, context);

for (i = 0; i < sizeof (digest); i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
Expand All @@ -999,9 +998,9 @@ R_IPI char *r_sha384_end(RSha384Context *context, char buffer[R_SHA384_DIGEST_ST
return buffer;
}

R_IPI char *r_sha384_data(const ut8 *data, size_t len, char digest[R_SHA384_DIGEST_STRING_LENGTH]) {
R_IPI char *R_SHA2_API(r_sha384_data)(const ut8 *data, size_t len, char digest[R_SHA384_DIGEST_STRING_LENGTH]) {
RSha384Context context;
r_sha384_init (&context);
r_sha384_update (&context, data, len);
return r_sha384_end (&context, digest);
R_SHA2_API (r_sha384_init) (&context);
R_SHA2_API (r_sha384_update) (&context, data, len);
return R_SHA2_API (r_sha384_end) (&context, digest);
}
34 changes: 19 additions & 15 deletions libr/crypto/hash/sha2.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extern "C" {
#if R_CRYPTO_INTERNAL
#undef R_IPI
#define R_IPI R_UNUSED static
#define IPI static
#define R_SHA2_API(x) __sha2_##x
#else
#define R_SHA2_API(x) x
#endif

/*** SHA-256/384/512 Various Length Definitions ***********************/
Expand All @@ -60,23 +64,23 @@ extern "C" {

/*** SHA-256/384/512 Function Prototypes ******************************/

R_IPI void r_sha256_init(RSha256Context *);
R_IPI void r_sha256_update(RSha256Context*, const ut8*, size_t);
R_IPI void r_sha256_final(ut8[R_SHA256_DIGEST_LENGTH], RSha256Context*);
R_IPI char* r_sha256_end(RSha256Context*, char[R_SHA256_DIGEST_STRING_LENGTH]);
R_IPI char* r_sha256_data(const ut8*, size_t, char[R_SHA256_DIGEST_STRING_LENGTH]);
R_IPI void R_SHA2_API(r_sha256_init)(RSha256Context *);
R_IPI void R_SHA2_API(r_sha256_update)(RSha256Context*, const ut8*, size_t);
R_IPI void R_SHA2_API(r_sha256_final)(ut8[R_SHA256_DIGEST_LENGTH], RSha256Context*);
R_IPI char* R_SHA2_API(r_sha256_end)(RSha256Context*, char[R_SHA256_DIGEST_STRING_LENGTH]);
R_IPI char* R_SHA2_API(r_sha256_data)(const ut8*, size_t, char[R_SHA256_DIGEST_STRING_LENGTH]);

R_IPI void r_sha384_init(RSha384Context*);
R_IPI void r_sha384_update(RSha384Context*, const ut8*, size_t);
R_IPI void r_sha384_final(ut8[R_SHA384_DIGEST_LENGTH], RSha384Context*);
R_IPI char* r_sha384_end(RSha384Context*, char[R_SHA384_DIGEST_STRING_LENGTH]);
R_IPI char* r_sha384_data(const ut8*, size_t, char[R_SHA384_DIGEST_STRING_LENGTH]);
R_IPI void R_SHA2_API(r_sha384_init)(RSha384Context*);
R_IPI void R_SHA2_API(r_sha384_update)(RSha384Context*, const ut8*, size_t);
R_IPI void R_SHA2_API(r_sha384_final)(ut8[R_SHA384_DIGEST_LENGTH], RSha384Context*);
R_IPI char* R_SHA2_API(r_sha384_end)(RSha384Context*, char[R_SHA384_DIGEST_STRING_LENGTH]);
R_IPI char* R_SHA2_API(r_sha384_data)(const ut8*, size_t, char[R_SHA384_DIGEST_STRING_LENGTH]);

R_IPI void r_sha512_init(RSha512Context*);
R_IPI void r_sha512_update(RSha512Context*, const ut8*, size_t);
R_IPI void r_sha512_final(ut8[R_SHA512_DIGEST_LENGTH], RSha512Context*);
R_IPI char* r_sha512_end(RSha512Context*, char[R_SHA512_DIGEST_STRING_LENGTH]);
R_IPI char* r_sha512_data(const ut8*, size_t, char[R_SHA512_DIGEST_STRING_LENGTH]);
R_IPI void R_SHA2_API(r_sha512_init)(RSha512Context*);
R_IPI void R_SHA2_API(r_sha512_update)(RSha512Context*, const ut8*, size_t);
R_IPI void R_SHA2_API(r_sha512_final)(ut8[R_SHA512_DIGEST_LENGTH], RSha512Context*);
R_IPI char* R_SHA2_API(r_sha512_end)(RSha512Context*, char[R_SHA512_DIGEST_STRING_LENGTH]);
R_IPI char* R_SHA2_API(r_sha512_data)(const ut8*, size_t, char[R_SHA512_DIGEST_STRING_LENGTH]);

#ifdef __cplusplus
}
Expand Down
6 changes: 5 additions & 1 deletion libr/include/rvc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2021-2023 - RHL120, pancake */
/* radare - LGPL - Copyright 2021-2024 - RHL120, pancake */

#ifndef R_RVC_H
#define R_RVC_H 1
Expand Down Expand Up @@ -42,7 +42,10 @@ typedef bool (*RvcPluginClone)(const struct r_vc_t *rvc, const char *dst);
typedef bool (*RvcPluginSave)(struct r_vc_t *vc);
typedef Rvc *(*RvcPluginOpen)(const char *path);

// R2_600 typedef char *(*RvcPluginHash)(const ut8 *data, size_t len);

typedef struct rvc_plugin_t {
// TODO: R2_600 - Use RPluginMeta
const char *const name;
const char *const author;
const char *const desc;
Expand All @@ -60,6 +63,7 @@ typedef struct rvc_plugin_t {
RvcPluginClose close;
RvcPluginSave save;
RvcPluginOpen open;
// R2_600 RvcPluginHash hash;
} RvcPlugin;

R_API Rvc *rvc_open(const char *rp, RvcType type);
Expand Down
4 changes: 3 additions & 1 deletion libr/util/rvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ R_API void rvc_free(Rvc *vc) {
}

R_API RvcType rvc_repo_type(const char *path) {
R_RETURN_VAL_IF_FAIL (path, RVC_TYPE_INV);
const char *paths[] = {".git", ".rvc"};
const RvcType types[] = {RVC_TYPE_GIT, RVC_TYPE_RVC};
const RvcType types[] = { RVC_TYPE_GIT, RVC_TYPE_RVC };
size_t i = 0;
for (; i < sizeof (paths) / sizeof (char *)
&& i < sizeof (types) / sizeof (RvcType); i++) {
char *p = r_file_new (path, paths[i], NULL);
if (r_file_is_directory (p)) {
free (p);
return types[i];
}
free (p);
Expand Down
Loading

0 comments on commit e25d1be

Please sign in to comment.