// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/omdsha256k256n104tau160v2/ref/omdsha256.c
// Function: hash
void
hash (hashblock taga, const hashblock key, const unsigned char *ad,
      unsigned long long int adlen)
{
   hashblock lstar, lzero;
   hashblock delta;
   hashblock left, right;
   hashblock xor_res, key_func_res;
   hashblock taures;
   unsigned int  modlen;
   long long int i, l;
   size_t b;

   /* CHANGE FROM V1 TO V2 HERE*/
   /* L* = F_K(0^n, <tau>_m) */
   l2b (taures, OMD_tau);
   key_func (lstar, block0s, key, taures);
   /* L[0] = 4.L* */
   double_block (lzero, lstar);
   double_block (lzero, lzero);

   /*b = n+m*/
   b = OMD_n + OMD_m;

   /* A_1 || A_2 ··· A_{l−1} || A_l = A, where |A_i| = b for 1 ≤ i ≤ l−1
      and |A_l| ≤ b */
   /* l=ceil(adlen/b) */
   l = (adlen + b - 1)/b;

   /* Tag_a = 0^n  */
   memset (taga, 0x00, OMD_n);
   /* If AD="" => Tag_a = 0^n */
   if (adlen == 0)
      {
	 return;
      }

   /* \bar{\delta}_{0,0} = 0^n */
   memset (delta, 0x00, OMD_n);

   /** for i = 1 to l-1 **/
   /**********************/
   for (i = 0; i < l-1; i++)
      {

	 /*  \bar{\delta}_{i, 0} =  \bar{\delta}{i-1, 0} ^ L[ntz(i)]  */
	 increment_masking_associated_data (delta, delta, lzero, i+1);

	 /* Left = A_l[b-1...m]; */
	 memcpy (left, &ad[i*b],  OMD_n);
	 /* Right = A_l[m-1...0]  */
	 memcpy (right,&ad[i*b+OMD_n],OMD_m);

	 /* Tag_a = Tag_a ^ F_K(Left ^ \delta_{i, 0}, right) */
	 xor_block (xor_res, delta, left);
	 key_func (key_func_res, xor_res, key, right);
	 xor_block (taga, taga, key_func_res);
      }
   /**************************/
   /******* endfor ***********/

   /* here adlen!=0, we process last ad block*/

   modlen = adlen%b;

   /* |A_l| = b then */
   if (modlen == 0)
      {
	 /* last mask = \bar{\delta}{l,0}  */
	 increment_masking_associated_data(delta, delta, lzero,l);

	 memcpy (left, &ad[(l-1)*b],      OMD_n);
	 memcpy (right,&ad[(l-1)*b+OMD_n],OMD_m);
      }
   /* |A_l| < b then */
   else
      {
	 /* last mask = \bar{\delta}{l-1,1}  */
	 final_masking_associated_data (delta, delta, lstar);

	 memset (left , 0x00, OMD_n );
	 memset (right, 0x00, OMD_m );

	 memcpy (left, &ad[(l-1)*b], (modlen < OMD_n ? modlen : OMD_n));
	 memcpy (right, &ad[(l-1)*b+OMD_n], (modlen < OMD_n
					     ? 0
					     : modlen - OMD_n));

	 if (modlen < OMD_n)
	    /* pad last block */
	    left[modlen]= 0x80;
	 else
	    right[modlen-OMD_n]=0x80;
   }

   /* Tag_a = Tag_a ^ F_K(Left ^ \delta_{l, 0 or 1}, right) */
   xor_block(xor_res, delta, left);
   key_func(key_func_res, xor_res, key, right);
   xor_block(taga, taga, key_func_res);
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movq %rcx, 0x158(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x14, %esi
callq 0x1150
leaq 0x130(%rsp), %rdi
movq 0x168(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x170e(%rip), %rsi      # 0x3000
callq 0x10c0
leaq 0x110(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x1070
leaq 0x110(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x1070
movq $0x40, 0x30(%rsp)
movq 0x158(%rsp), %rax
addq 0x30(%rsp), %rax
subq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq 0x170(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
cmpq $0x0, 0x158(%rsp)
jne 0x196d
jmp 0x1d28
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x1ac2
leaq 0xf0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x110(%rsp), %rdx
movq 0x40(%rsp), %rax
addq $0x1, %rax
movl %eax, %ecx
callq 0x1050
movq 0x160(%rsp), %rax
movq 0x40(%rsp), %rcx
imulq 0x30(%rsp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0xd0(%rsp)
movq 0x8(%rax,%rcx), %rdx
movq %rdx, 0xd8(%rsp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0xe0(%rsp)
movq 0x18(%rax,%rcx), %rax
movq %rax, 0xe8(%rsp)
movq 0x160(%rsp), %rax
movq 0x40(%rsp), %rcx
imulq 0x30(%rsp), %rcx
movq 0x20(%rax,%rcx), %rdx
movq %rdx, 0xb0(%rsp)
movq 0x28(%rax,%rcx), %rdx
movq %rdx, 0xb8(%rsp)
movq 0x30(%rax,%rcx), %rdx
movq %rdx, 0xc0(%rsp)
movq 0x38(%rax,%rcx), %rax
movq %rax, 0xc8(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x1140
leaq 0x70(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movq 0x168(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
callq 0x10c0
movq 0x170(%rsp), %rdi
movq 0x170(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x1140
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x198a
movq 0x158(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x30(%rsp)
movl %edx, %eax
movl %eax, 0x4c(%rsp)
cmpl $0x0, 0x4c(%rsp)
jne 0x1ba2
leaq 0xf0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x110(%rsp), %rdx
movq 0x38(%rsp), %rax
movl %eax, %ecx
callq 0x1050
movq 0x160(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, 0xd0(%rsp)
movq 0x8(%rax,%rcx), %rdx
movq %rdx, 0xd8(%rsp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0xe0(%rsp)
movq 0x18(%rax,%rcx), %rax
movq %rax, 0xe8(%rsp)
movq 0x160(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
movq 0x20(%rax,%rcx), %rdx
movq %rdx, 0xb0(%rsp)
movq 0x28(%rax,%rcx), %rdx
movq %rdx, 0xb8(%rsp)
movq 0x30(%rax,%rcx), %rdx
movq %rdx, 0xc0(%rsp)
movq 0x38(%rax,%rcx), %rax
movq %rax, 0xc8(%rsp)
jmp 0x1ccf
leaq 0xf0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x10a0
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1040
leaq 0xd0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x160(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
cmpl $0x20, 0x4c(%rsp)
jae 0x1c24
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x1c2f
movl $0x20, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1c2f
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1160
leaq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x160(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
addq $0x20, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
cmpl $0x20, 0x4c(%rsp)
jae 0x1c85
xorl %eax, %eax
movl %eax, 0x4(%rsp)
jmp 0x1c90
movl 0x4c(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1160
cmpl $0x20, 0x4c(%rsp)
jae 0x1cbc
movl 0x4c(%rsp), %eax
movb $-0x80, 0xd0(%rsp,%rax)
jmp 0x1ccd
movl 0x4c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
movb $-0x80, 0xb0(%rsp,%rax)
jmp 0x1ccf
leaq 0x90(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x1140
leaq 0x70(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movq 0x168(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
callq 0x10c0
movq 0x170(%rsp), %rdi
movq 0x170(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x1140
addq $0x178, %rsp            # imm = 0x178
retq