Skip to content

Commit

Permalink
Add omac_vprocess()
Browse files Browse the repository at this point in the history
As a new private API.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
  • Loading branch information
sjaeckel committed Dec 28, 2024
1 parent 197be81 commit 8bdc093
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/headers/tomcrypt_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
44 changes: 27 additions & 17 deletions src/mac/omac/omac_memory_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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));
Expand Down

2 comments on commit 8bdc093

@diamante0018
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit fails to compile on gcc/clang because there is no header that includes va_list

@sjaeckel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, CI says something different.

What's your environment?
How can you reproduce?

Please sign in to comment.