// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/omdsha256k256n104tau160v2/ref/omdsha256.c
// Function: omdsha256_process
int
omdsha256_process(unsigned char *data, const unsigned char* key,
                  const unsigned char *data_process,
                  unsigned long long int data_processlen,
                  const unsigned char *ad, unsigned long long int adlen,
                  const unsigned char *nonce,
                  const enum mode encrypting)
{
   hashblock key_block;
   hashblock lstar, lzero;
   hashblock nonce_block;
   hashblock delta;
   hashblock h;
   hashblock res, res2;
   hashblock taures;
   hashblock taga, tage, tag, tag_prime;
   hashblock xor_res;
   unsigned int statedelta, data_process_modlen;
   long long int i, l = 0;

   /* if |K| > n => return -1  */
   if (10 > OMD_k || OMD_k > OMD_n)
      return -1;

   /* if |N| > n-1 => return -1 */
   if ((12 > OMD_lnonce) || (OMD_lnonce > OMD_n-1))
      return -1;

   /* if |C| < tau => return -1 */
   if ((encrypting == OMD_DECRYPT) && (data_processlen < OMD_tau))
      return -1;

   memset (key_block, 0x00, OMD_n);
   memcpy (key_block, key, OMD_k);

   if (encrypting == OMD_ENCRYPT)
      {
      /* M_1 || M_2 ··· M_{l−1} || M_l = M, where |M_i| = m for 1 ≤ i ≤ l−1
	 and |M_l| ≤ m */
	 /* l = ceil(|M|/m) */
	 l = (data_processlen + (OMD_m-1))/OMD_m;
      }
   else if (encrypting == OMD_DECRYPT)
      {
      /* C_1 || C_2 ··· C_{l−1} || C_l || Tag = \mathbb{C},
	 where |C_i| = m for 1 ≤ i ≤ l−1 and |C_l| ≤ m and |Tag| = \tau*/
      data_processlen = data_processlen - OMD_tau;
      /* l = ceil(|C|/m) */
      l = (data_processlen +(OMD_m-1))/OMD_m;
      }

   
   /* Tag_a computed here to handle a=c overlap */
   /* Tag_a = HASH_k(ad)  */
   hash(taga, key_block, ad, adlen);

   /* CHANGE FROM V1 TO V2 HERE*/
   /* L* = F_K(0^n, <tau>_m) */
   l2b (taures, OMD_tau);
   key_func (lstar, block0s, key_block, taures);

   /* L[0] = 4.L* */
   double_block (lzero, lstar);   /* 2.L_* */
   double_block (lzero, lzero);   /* 2.(2.L_*) */

   /* pad nonce */
   memset (nonce_block, 0x00, OMD_n);
   memcpy (nonce_block, nonce, OMD_lnonce);
   nonce_block[OMD_lnonce] = 0x80;

   /* \delta{N,0,0} = F_K(N || 10^{n-1-|N|}, 0^m  */
   key_func (delta, nonce_block, key_block, block0s);

   /* H = 0^n */
   memset (h, 0x00, OMD_n );

   /* \delta{N,1,0} = \delta{N,0,0} ^ L[ntz(1)]  */
   increment_masking_message (delta, delta, lzero, 1);

   /* H = F_K(H ^ \delta_{N, 1, 0}, <tau>_m)  */
   xor_block (h, h, delta);
   key_func (h, h, key_block, taures);

   /* for i = 1 to l-1 do  */
   /************************/
   for (i = 0; i < l-1; i++)
      {
	 /* C_i = H ^ M_i */
	 /* M_i = H ^ C_i */
	 memcpy(res,&data_process[i*OMD_m],OMD_m);
	 xor_block(res2, h, res);
	 memcpy(&data[i*OMD_m],res2,OMD_m);

	 /* \delta_{N, i+1, 0} = \delta{N, i, 0} ^ L[ntz(i+1)]  */
	 increment_masking_message(delta, delta, lzero, i+2);

	 /* H = F_K(H ^ \delta{N, i, 0}, M_i) */
	 xor_block(xor_res, delta, h);

	 if (encrypting == OMD_ENCRYPT)
	    /* res  = M_i */
	    key_func(h, xor_res, key_block, res);
	 else if (encrypting == OMD_DECRYPT)
	    /* res2 = M_i */
	    key_func(h, xor_res, key_block, res2);
      }

   /************************/
   /******** endfor ********/


   /* |M|>0 */
   if (data_processlen!=0)
      {
	 /* C_l = H ^ M_l */
	 /* M_l = H ^ C_l *//* |M_l| = m then */
	 data_process_modlen = data_processlen%OMD_m;
	 memset (res,0x00,OMD_m);
	 memcpy(res, &data_process[(l-1)*OMD_m], (data_process_modlen==0
						  ? OMD_m
						  : data_process_modlen));
	 xor_block(res2, h, res);
	 memcpy(&data[(l-1)*OMD_m], res2, (data_process_modlen==0
					   ? OMD_m : data_process_modlen));

      /* if |M_\ell|=m */
      if (data_process_modlen == 0)
         statedelta = 1;
      /* else if |M_\ell|<m*/
      else
         statedelta = 2;

      /* \delta{N, l, 1} = \delta{N, l, 0} ^ (2 or 3)*L_* */
      final_masking_message(delta, delta, lstar, statedelta);
      /* Tag_e = F_K(H ^ \delta{N, l, 1}, M_l)  */
      xor_block(h, h, delta);

      if (encrypting == OMD_ENCRYPT)
	 {
	    /* if |M_\ell|<m, we pad*/
	    if (statedelta==2)
	       res[data_process_modlen]=0x80;

	    key_func(tage, h, key_block, res);        /* res  = M_i */
	 }
      else if (encrypting == OMD_DECRYPT)
	 {
	    if(statedelta==2)
	       {
		  /* if |M_\ell|<m, we pad*/
		  res2[data_process_modlen]=0x80;
		  memset(&res2[data_process_modlen+1], 0x00,
			 OMD_m - data_process_modlen - 1);
	       }

         key_func(tage, h, key_block, res2);      /* res2 = M_i */
	 }

      }
   /* |M| = 0 => tage = H */
   else
      {
	 memcpy(tage,h,OMD_n);
      }

   /* Tag = (Tag_e ^ Tag_a)[n-1 ... n- tau]  */
   xor_block(tag, taga, tage);

   /*ENCRYPT => output tag and return 0*/
   if (encrypting == OMD_ENCRYPT)
      {
	 memcpy (&data[data_processlen], tag, OMD_tau);

	 return 0;
      }

   /* or check tag */
   memcpy(tag_prime, &data_process[data_processlen], OMD_tau);

   if (memcmp (tag,tag_prime,OMD_tau) == 0)
      {
	 return 0;
      }

   return -1;
}

// Assembly:
subq $0x248, %rsp            # imm = 0x248
movl 0x258(%rsp), %eax
movq 0x250(%rsp), %rax
movq %rdi, 0x238(%rsp)
movq %rsi, 0x230(%rsp)
movq %rdx, 0x228(%rsp)
movq %rcx, 0x220(%rsp)
movq %r8, 0x218(%rsp)
movq %r9, 0x210(%rsp)
movq $0x0, 0x38(%rsp)
cmpl $0x1, 0x258(%rsp)
jne 0x1da4
cmpq $0x14, 0x220(%rsp)
jae 0x1da4
movl $0xffffffff, 0x244(%rsp) # imm = 0xFFFFFFFF
jmp 0x243d
leaq 0x1f0(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
movq 0x230(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x1f0(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x1f8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x200(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x208(%rsp)
cmpl $0x0, 0x258(%rsp)
jne 0x1e10
movq 0x220(%rsp), %rax
addq $0x1f, %rax
shrq $0x5, %rax
movq %rax, 0x38(%rsp)
jmp 0x1e45
cmpl $0x1, 0x258(%rsp)
jne 0x1e43
movq 0x220(%rsp), %rax
subq $0x14, %rax
movq %rax, 0x220(%rsp)
movq 0x220(%rsp), %rax
addq $0x1f, %rax
shrq $0x5, %rax
movq %rax, 0x38(%rsp)
jmp 0x1e45
leaq 0xd0(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
movq 0x218(%rsp), %rdx
movq 0x210(%rsp), %rcx
callq 0x10f0
leaq 0xf0(%rsp), %rdi
movl $0x14, %esi
callq 0x1150
leaq 0x1d0(%rsp), %rdi
leaq 0x1f0(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0x1165(%rip), %rsi      # 0x3000
callq 0x10c0
leaq 0x1b0(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x1070
leaq 0x1b0(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x1070
leaq 0x190(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
movq 0x250(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x190(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x198(%rsp)
movb 0xc(%rax), %al
movb %al, 0x19c(%rsp)
movb $-0x80, 0x19d(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0x10d4(%rip), %rcx      # 0x3000
callq 0x10c0
leaq 0x150(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
leaq 0x170(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
movl $0x1, %ecx
callq 0x1120
leaq 0x150(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x170(%rsp), %rdx
callq 0x1140
leaq 0x150(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
callq 0x10c0
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x2121
movq 0x228(%rsp), %rax
movq 0x40(%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0x130(%rsp)
movq 0x8(%rax,%rcx), %rdx
movq %rdx, 0x138(%rsp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0x140(%rsp)
movq 0x18(%rax,%rcx), %rax
movq %rax, 0x148(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x1140
movq 0x238(%rsp), %rax
movq 0x40(%rsp), %rcx
shlq $0x5, %rcx
movq 0x110(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq 0x118(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movq 0x120(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movq 0x128(%rsp), %rdx
movq %rdx, 0x18(%rax,%rcx)
leaq 0x170(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
movq 0x40(%rsp), %rax
addq $0x2, %rax
movl %eax, %ecx
callq 0x1120
leaq 0x50(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0x1140
cmpl $0x0, 0x258(%rsp)
jne 0x20de
leaq 0x150(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0x130(%rsp), %rcx
callq 0x10c0
jmp 0x210c
cmpl $0x1, 0x258(%rsp)
jne 0x210a
leaq 0x150(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0x110(%rsp), %rcx
callq 0x10c0
jmp 0x210c
jmp 0x210e
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x1fb2
cmpq $0x0, 0x220(%rsp)
je 0x2333
movq 0x220(%rsp), %rax
andq $0x1f, %rax
movl %eax, 0x48(%rsp)
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
leaq 0x130(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x228(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x48(%rsp)
jne 0x2190
movl $0x20, %eax
movl %eax, 0x24(%rsp)
jmp 0x2198
movl 0x48(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
movl 0x24(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1160
leaq 0x110(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x1140
movq 0x238(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x48(%rsp)
jne 0x2208
movl $0x20, %eax
movl %eax, 0xc(%rsp)
jmp 0x2210
movl 0x48(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1160
cmpl $0x0, 0x48(%rsp)
jne 0x2238
movl $0x1, 0x4c(%rsp)
jmp 0x2240
movl $0x2, 0x4c(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0x1030
leaq 0x150(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x170(%rsp), %rdx
callq 0x1140
cmpl $0x0, 0x258(%rsp)
jne 0x22c2
cmpl $0x2, 0x4c(%rsp)
jne 0x229b
movl 0x48(%rsp), %eax
movb $-0x80, 0x130(%rsp,%rax)
leaq 0xb0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0x130(%rsp), %rcx
callq 0x10c0
jmp 0x2331
cmpl $0x1, 0x258(%rsp)
jne 0x232f
cmpl $0x2, 0x4c(%rsp)
jne 0x230a
movl 0x48(%rsp), %eax
movb $-0x80, 0x110(%rsp,%rax)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
leaq 0x110(%rsp), %rdi
addq %rax, %rdi
movl $0x20, %eax
subl 0x48(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x1040
leaq 0xb0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
leaq 0x110(%rsp), %rcx
callq 0x10c0
jmp 0x2331
jmp 0x2373
movq 0x150(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x1140
cmpl $0x0, 0x258(%rsp)
jne 0x23db
movq 0x238(%rsp), %rax
movq 0x220(%rsp), %rcx
movq 0x90(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq 0x98(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movl 0xa0(%rsp), %edx
movl %edx, 0x10(%rax,%rcx)
movl $0x0, 0x244(%rsp)
jmp 0x243d
movq 0x228(%rsp), %rax
movq 0x220(%rsp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0x70(%rsp)
movq 0x8(%rax,%rcx), %rdx
movq %rdx, 0x78(%rsp)
movl 0x10(%rax,%rcx), %eax
movl %eax, 0x80(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x14, %edx
callq 0x1110
cmpl $0x0, %eax
jne 0x2432
movl $0x0, 0x244(%rsp)
jmp 0x243d
movl $0xffffffff, 0x244(%rsp) # imm = 0xFFFFFFFF
movl 0x244(%rsp), %eax
addq $0x248, %rsp            # imm = 0x248
retq
nopl (%rax)