Browse Source

Add `omac_vprocess()`

As a new private API.

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 9 months ago
parent
commit
8bdc093fae
2 changed files with 28 additions and 17 deletions
  1. 1 0
      src/headers/tomcrypt_private.h
  2. 27 17
      src/mac/omac/omac_memory_multi.c

+ 1 - 0
src/headers/tomcrypt_private.h

@@ -168,6 +168,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
 int ocb3_int_ntz(unsigned long x);
 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);
 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 */
 /* tomcrypt_math.h */
 
 

+ 27 - 17
src/mac/omac/omac_memory_multi.c

@@ -10,6 +10,31 @@
 
 
 #ifdef LTC_OMAC
 #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
    OMAC multiple blocks of memory
    @param cipher    The index of the desired cipher
    @param cipher    The index of the desired cipher
@@ -30,8 +55,6 @@ int omac_memory_multi(int cipher,
    int                  err;
    int                  err;
    omac_state          *omac;
    omac_state          *omac;
    va_list              args;
    va_list              args;
-   const unsigned char *curptr;
-   unsigned long        curlen;
 
 
    LTC_ARGCHK(key    != NULL);
    LTC_ARGCHK(key    != NULL);
    LTC_ARGCHK(in     != NULL);
    LTC_ARGCHK(in     != NULL);
@@ -49,23 +72,10 @@ int omac_memory_multi(int cipher,
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
    va_start(args, inlen);
    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;
       goto LBL_ERR;
    }
    }
+   err = omac_done(omac, out, outlen);
 LBL_ERR:
 LBL_ERR:
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    zeromem(omac, sizeof(omac_state));
    zeromem(omac, sizeof(omac_state));