Skip to content

Commit

Permalink
libtomcrypt: tomcrypt_private.h: add HASH_PROCESS_NBLOCKS
Browse files Browse the repository at this point in the history
Apply the changes from commit de51851 ("arm64: SHA-1 using ARMv8-A
cryptographic extensions") that touch tomcrypt_private.h only. The rest
of the implementation is not under the path that we synchronize with
upstream (i.e., core/lib/libtomcrypt/src).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jforissier authored and jenswi-linaro committed Apr 24, 2024
1 parent a4281f4 commit ae75124
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions core/lib/libtomcrypt/src/headers/tomcrypt_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ int blowfish_setup_with_data(const unsigned char *key, int keylen,

/* tomcrypt_hash.h */

/* a simple macro for making hash "process" functions */
#define HASH_PROCESS(func_name, compress_name, state_var, block_size) \
/* a macro for making hash "process" functions */
#define HASH_PROCESS_(func_name, compress_name, compress_n_name, state_var, block_size) \
int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \
{ \
unsigned long n; \
unsigned long n, blocks; \
int err; \
int (*compress)(hash_state *, const unsigned char *) = compress_name; \
int (*compress_n)(hash_state *, const unsigned char *, int) = compress_n_name;\
LTC_ARGCHK(md != NULL); \
LTC_ARGCHK(in != NULL); \
if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \
Expand All @@ -129,20 +131,31 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
} \
while (inlen > 0) { \
if (md-> state_var .curlen == 0 && inlen >= block_size) { \
if ((err = compress_name (md, in)) != CRYPT_OK) { \
return err; \
if (compress_n) { \
blocks = inlen / block_size; \
err = compress_n (md, in, blocks); \
} else { \
blocks = 1; \
err = compress (md, in); \
} \
md-> state_var .length += block_size * 8; \
in += block_size; \
inlen -= block_size; \
if (err != CRYPT_OK) \
return err; \
md-> state_var .length += blocks * block_size * 8; \
in += blocks * block_size; \
inlen -= blocks * block_size; \
} else { \
n = MIN(inlen, (block_size - md-> state_var .curlen)); \
XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \
md-> state_var .curlen += n; \
in += n; \
inlen -= n; \
if (md-> state_var .curlen == block_size) { \
if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \
if (compress_n) { \
err = compress_n (md, md-> state_var .buf, 1); \
} else { \
err = compress (md, md-> state_var .buf); \
} \
if (err != CRYPT_OK) { \
return err; \
} \
md-> state_var .length += 8*block_size; \
Expand All @@ -153,6 +166,14 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
return CRYPT_OK; \
}

/* define a hash "process" function based on a 1-block compress function */
#define HASH_PROCESS(func_name, compress_name, state_var, block_size) \
HASH_PROCESS_(func_name, compress_name, NULL, state_var, block_size)

/* define a hash "process" function based on a n-block compress function */
#define HASH_PROCESS_NBLOCKS(func_name, compress_n_name, state_var, block_size) \
HASH_PROCESS_(func_name, NULL, compress_n_name, state_var, block_size)


/* tomcrypt_mac.h */

Expand Down

0 comments on commit ae75124

Please sign in to comment.