Add omac_vprocess()

As a new private API.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel 2024-12-19 15:58:31 +01:00
parent 197be81918
commit 8bdc093fae
2 changed files with 28 additions and 17 deletions

View file

@ -168,6 +168,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
int ocb3_int_ntz(unsigned long x);
void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len);
int omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args);
/* tomcrypt_math.h */

View file

@ -10,6 +10,31 @@
#ifdef LTC_OMAC
static LTC_INLINE int s_omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args)
{
const unsigned char * curptr = in;
unsigned long curlen = inlen;
int err;
for (;;) {
/* process buf */
if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
return err;
}
/* step to next */
curptr = va_arg(args, const unsigned char*);
if (curptr == NULL) {
break;
}
curlen = va_arg(args, unsigned long);
}
return CRYPT_OK;
}
int omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args)
{
return s_omac_vprocess(omac, in, inlen, args);
}
/**
OMAC multiple blocks of memory
@param cipher The index of the desired cipher
@ -30,8 +55,6 @@ int omac_memory_multi(int cipher,
int err;
omac_state *omac;
va_list args;
const unsigned char *curptr;
unsigned long curlen;
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(in != NULL);
@ -49,23 +72,10 @@ int omac_memory_multi(int cipher,
goto LBL_ERR;
}
va_start(args, inlen);
curptr = in;
curlen = inlen;
for (;;) {
/* process buf */
if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
goto LBL_ERR;
}
/* step to next */
curptr = va_arg(args, const unsigned char*);
if (curptr == NULL) {
break;
}
curlen = va_arg(args, unsigned long);
}
if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
if ((err = s_omac_vprocess(omac, in, inlen, args)) != CRYPT_OK) {
goto LBL_ERR;
}
err = omac_done(omac, out, outlen);
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(omac, sizeof(omac_state));