Skip to content

Commit 8bdc093

Browse files
committed
Add omac_vprocess()
As a new private API. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 197be81 commit 8bdc093

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/headers/tomcrypt_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
168168
int ocb3_int_ntz(unsigned long x);
169169
void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len);
170170

171+
int omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args);
171172

172173
/* tomcrypt_math.h */
173174

src/mac/omac/omac_memory_multi.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010

1111
#ifdef LTC_OMAC
1212

13+
static LTC_INLINE int s_omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args)
14+
{
15+
const unsigned char * curptr = in;
16+
unsigned long curlen = inlen;
17+
int err;
18+
for (;;) {
19+
/* process buf */
20+
if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
21+
return err;
22+
}
23+
/* step to next */
24+
curptr = va_arg(args, const unsigned char*);
25+
if (curptr == NULL) {
26+
break;
27+
}
28+
curlen = va_arg(args, unsigned long);
29+
}
30+
return CRYPT_OK;
31+
}
32+
33+
int omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inlen, va_list args)
34+
{
35+
return s_omac_vprocess(omac, in, inlen, args);
36+
}
37+
1338
/**
1439
OMAC multiple blocks of memory
1540
@param cipher The index of the desired cipher
@@ -30,8 +55,6 @@ int omac_memory_multi(int cipher,
3055
int err;
3156
omac_state *omac;
3257
va_list args;
33-
const unsigned char *curptr;
34-
unsigned long curlen;
3558

3659
LTC_ARGCHK(key != NULL);
3760
LTC_ARGCHK(in != NULL);
@@ -49,23 +72,10 @@ int omac_memory_multi(int cipher,
4972
goto LBL_ERR;
5073
}
5174
va_start(args, inlen);
52-
curptr = in;
53-
curlen = inlen;
54-
for (;;) {
55-
/* process buf */
56-
if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
57-
goto LBL_ERR;
58-
}
59-
/* step to next */
60-
curptr = va_arg(args, const unsigned char*);
61-
if (curptr == NULL) {
62-
break;
63-
}
64-
curlen = va_arg(args, unsigned long);
65-
}
66-
if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
75+
if ((err = s_omac_vprocess(omac, in, inlen, args)) != CRYPT_OK) {
6776
goto LBL_ERR;
6877
}
78+
err = omac_done(omac, out, outlen);
6979
LBL_ERR:
7080
#ifdef LTC_CLEAN_STACK
7181
zeromem(omac, sizeof(omac_state));

0 commit comments

Comments
 (0)