FourQ_ARM/ARM/fp2_1271_arm_Cortex-M4.S [230:438]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  sub    r13, r13, #32
  adds   r3, r3, r0
  adcs   r4, r4, r1
  adcs   r5, r5, r7   
  adcs   r6, r6, r8
  ldmia  r13!, {r7-r8}
  ldmia  r13!, {r0-r1}
  adcs   r7, r7, r9
  adcs   r8, r8, r10
  adcs   r9, r0, r11
  adcs   r10, r1, r12
    
  // Reducing and storing c1
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31
  lsl    r7, r7, #1
  orr    r7, r7, r6, lsr #31    
  and    r6, r6, #0x7FFFFFFF
  
  lsls   r10, r10, #1
  adcs   r3, r3, r7      
  adcs   r4, r4, r8                 
  adcs   r5, r5, r9
  adcs   r6, r6, r10, lsr #1 
  
  and    r7, r6, #0x7FFFFFFF 
  adds   r3, r3, r6, lsr #31        
  adcs   r4, r4, #0                 
  adcs   r5, r5, #0 
  adcs   r6, r7, #0    
  stmia  r2!, {r3-r6}         // Storing c1 
  
  add    r13, r13, #28        // Restoring stack  
  pop    {r4-r12}
  bx     lr


//***********************************************************************
//  Squaring over GF(p^2)
//  Operation: c [reg_p2] = a^2 [reg_p1]
//*********************************************************************** 
.global fp2sqr1271_a
.type	fp2sqr1271_a, %function
fp2sqr1271_a:
  push   {r4-r12}
  sub    r13, r13, #16        // Allocating space in the stack
  
  // t0 = a0 + a1
  ldm    r0, {r2-r9}
  adds   r2, r2, r6
  adcs   r3, r3, r7
  adcs   r4, r4, r8
  adcs   r5, r5, r9
  stm    r13, {r2-r5}         // Store in stack
  
  // t1 = a0 - a1
  ldm    r0, {r2-r5}
  subs   r2, r2, r6
  sbcs   r3, r3, r7
  sbcs   r4, r4, r8
  sbcs   r5, r5, r9 
  
  and    r6, r5, #0x7FFFFFFF 
  subs   r2, r2, r5, lsr #31        
  sbcs   r3, r3, #0                 
  sbcs   r4, r4, #0 
  sbcs   r5, r6, #0
  
  // T0 = t0 * t1 = (a0 + a1)*(a0 - a1)
  ldr    r12, [r13]    
  mov    r9, #0
  mov    r10, #0
  mov    r11, #0
  umull  r6, r7, r12, r2      
  umlal  r7, r9, r12, r3
  umlal  r9, r10, r12, r4
  umlal  r10, r11, r12, r5
  ldr    r12, [r13, #4]
  str    r6, [r13]            // Store in stack
  mov    r6, #0
  
  umlal  r7, r6, r12, r2      
  umaal  r6, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r13, #8]
  str    r7, [r13, #4]        // Store in stack
  mov    r7, #0
  
  umlal  r6, r7, r12, r2      
  umaal  r7, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r13, #12]
  mov    r8, #0
  
  umlal  r7, r8, r12, r2    
  umaal  r8, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  
  // Reduction
  lsl    r11, r11, #1
  orr    r11, r11, r10, lsr #31
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31 
  ldm    r13, {r4,r5}  
  and    r7, r7, #0x7FFFFFFF
  
  lsls   r11, r11, #1 
  adcs   r4, r4, r8      
  adcs   r5, r5, r9                 
  adcs   r6, r6, r10
  adcs   r7, r7, r11, lsr #1 
  
  and    r8, r7, #0x7FFFFFFF 
  adds   r9, r4, r7, lsr #31        
  adcs   r10, r5, #0 
  ldm    r0, {r2-r5}                
  adcs   r11, r6, #0 
  adcs   r12, r8, #0 
  
  // t0 = 2*a0
  adds   r2, r2, r2
  adcs   r3, r3, r3
  adcs   r4, r4, r4
  adcs   r5, r5, r5
  
  stmia  r1!, {r9-r12}        // Storing c0
  
  // T1 = 2a0 * a1
  ldr    r12, [r0, #16]    
  mov    r9, #0
  mov    r10, #0
  mov    r11, #0
  umull  r6, r7, r12, r2      
  umlal  r7, r9, r12, r3
  umlal  r9, r10, r12, r4
  umlal  r10, r11, r12, r5
  ldr    r12, [r0, #20]
  str    r6, [r13]            // Store in stack
  mov    r6, #0
  
  umlal  r7, r6, r12, r2      
  umaal  r6, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r0, #24]
  str    r7, [r13, #4]        // Store in stack
  mov    r7, #0
  
  umlal  r6, r7, r12, r2      
  umaal  r7, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r0, #28]
  mov    r8, #0
  
  umlal  r7, r8, r12, r2    
  umaal  r8, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  
  // Reduction
  lsl    r11, r11, #1
  orr    r11, r11, r10, lsr #31
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31 
  ldm    r13, {r4,r5}  
  and    r7, r7, #0x7FFFFFFF
  
  lsls   r11, r11, #1
  adcs   r4, r4, r8      
  adcs   r5, r5, r9                 
  adcs   r6, r6, r10
  adcs   r7, r7, r11, lsr #1 
  
  and    r8, r7, #0x7FFFFFFF 
  adds   r4, r4, r7, lsr #31        
  adcs   r5, r5, #0                 
  adcs   r6, r6, #0 
  adcs   r7, r8, #0 
  stmia  r1!, {r4-r7}         // Storing c1  
  
  add    r13, r13, #16        // Restoring stack  
  pop    {r4-r12}
  bx     lr


//***********************************************************************
//  Addition over GF(p^2)
//  Operation: c [reg_p3] = a [reg_p1] + b [reg_p2] mod p, p = 2^127-1
//*********************************************************************** 
.global fp2add1271_a
.type	fp2add1271_a, %function
fp2add1271_a:
  push   {r4-r10}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



FourQ_ARM_side_channel/ARM/fp2_1271_arm.S [225:433]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  sub    r13, r13, #32
  adds   r3, r3, r0
  adcs   r4, r4, r1
  adcs   r5, r5, r7   
  adcs   r6, r6, r8
  ldmia  r13!, {r7-r8}
  ldmia  r13!, {r0-r1}
  adcs   r7, r7, r9
  adcs   r8, r8, r10
  adcs   r9, r0, r11
  adcs   r10, r1, r12
    
  // Reducing and storing c1
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31
  lsl    r7, r7, #1
  orr    r7, r7, r6, lsr #31    
  and    r6, r6, #0x7FFFFFFF
  
  lsls   r10, r10, #1
  adcs   r3, r3, r7      
  adcs   r4, r4, r8                 
  adcs   r5, r5, r9
  adcs   r6, r6, r10, lsr #1 
  
  and    r7, r6, #0x7FFFFFFF 
  adds   r3, r3, r6, lsr #31        
  adcs   r4, r4, #0                 
  adcs   r5, r5, #0 
  adcs   r6, r7, #0    
  stmia  r2!, {r3-r6}         // Storing c1 
  
  add    r13, r13, #28        // Restoring stack  
  pop    {r4-r12}
  bx     lr


//***********************************************************************
//  Squaring over GF(p^2)
//  Operation: c [reg_p2] = a^2 [reg_p1]
//*********************************************************************** 
.global fp2sqr1271_a
.type	fp2sqr1271_a, %function
fp2sqr1271_a:
  push   {r4-r12}
  sub    r13, r13, #16        // Allocating space in the stack
  
  // t0 = a0 + a1
  ldm    r0, {r2-r9}
  adds   r2, r2, r6
  adcs   r3, r3, r7
  adcs   r4, r4, r8
  adcs   r5, r5, r9
  stm    r13, {r2-r5}         // Store in stack
  
  // t1 = a0 - a1
  ldm    r0, {r2-r5}
  subs   r2, r2, r6
  sbcs   r3, r3, r7
  sbcs   r4, r4, r8
  sbcs   r5, r5, r9 
  
  and    r6, r5, #0x7FFFFFFF 
  subs   r2, r2, r5, lsr #31        
  sbcs   r3, r3, #0                 
  sbcs   r4, r4, #0 
  sbcs   r5, r6, #0
  
  // T0 = t0 * t1 = (a0 + a1)*(a0 - a1)
  ldr    r12, [r13]    
  mov    r9, #0
  mov    r10, #0
  mov    r11, #0
  umull  r6, r7, r12, r2      
  umlal  r7, r9, r12, r3
  umlal  r9, r10, r12, r4
  umlal  r10, r11, r12, r5
  ldr    r12, [r13, #4]
  str    r6, [r13]            // Store in stack
  mov    r6, #0
  
  umlal  r7, r6, r12, r2      
  umaal  r6, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r13, #8]
  str    r7, [r13, #4]        // Store in stack
  mov    r7, #0
  
  umlal  r6, r7, r12, r2      
  umaal  r7, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r13, #12]
  mov    r8, #0
  
  umlal  r7, r8, r12, r2    
  umaal  r8, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  
  // Reduction
  lsl    r11, r11, #1
  orr    r11, r11, r10, lsr #31
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31 
  ldm    r13, {r4,r5}  
  and    r7, r7, #0x7FFFFFFF
  
  lsls   r11, r11, #1 
  adcs   r4, r4, r8      
  adcs   r5, r5, r9                 
  adcs   r6, r6, r10
  adcs   r7, r7, r11, lsr #1 
  
  and    r8, r7, #0x7FFFFFFF 
  adds   r9, r4, r7, lsr #31        
  adcs   r10, r5, #0 
  ldm    r0, {r2-r5}                
  adcs   r11, r6, #0 
  adcs   r12, r8, #0 
  
  // t0 = 2*a0
  adds   r2, r2, r2
  adcs   r3, r3, r3
  adcs   r4, r4, r4
  adcs   r5, r5, r5
  
  stmia  r1!, {r9-r12}        // Storing c0
  
  // T1 = 2a0 * a1
  ldr    r12, [r0, #16]    
  mov    r9, #0
  mov    r10, #0
  mov    r11, #0
  umull  r6, r7, r12, r2      
  umlal  r7, r9, r12, r3
  umlal  r9, r10, r12, r4
  umlal  r10, r11, r12, r5
  ldr    r12, [r0, #20]
  str    r6, [r13]            // Store in stack
  mov    r6, #0
  
  umlal  r7, r6, r12, r2      
  umaal  r6, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r0, #24]
  str    r7, [r13, #4]        // Store in stack
  mov    r7, #0
  
  umlal  r6, r7, r12, r2      
  umaal  r7, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  ldr    r12, [r0, #28]
  mov    r8, #0
  
  umlal  r7, r8, r12, r2    
  umaal  r8, r9, r12, r3 
  umaal  r9, r10, r12, r4 
  umaal  r10, r11, r12, r5 
  
  // Reduction
  lsl    r11, r11, #1
  orr    r11, r11, r10, lsr #31
  lsl    r10, r10, #1
  orr    r10, r10, r9, lsr #31
  lsl    r9, r9, #1
  orr    r9, r9, r8, lsr #31
  lsl    r8, r8, #1
  orr    r8, r8, r7, lsr #31 
  ldm    r13, {r4,r5}  
  and    r7, r7, #0x7FFFFFFF
  
  lsls   r11, r11, #1
  adcs   r4, r4, r8      
  adcs   r5, r5, r9                 
  adcs   r6, r6, r10
  adcs   r7, r7, r11, lsr #1 
  
  and    r8, r7, #0x7FFFFFFF 
  adds   r4, r4, r7, lsr #31        
  adcs   r5, r5, #0                 
  adcs   r6, r6, #0 
  adcs   r7, r8, #0 
  stmia  r1!, {r4-r7}         // Storing c1  
  
  add    r13, r13, #16        // Restoring stack  
  pop    {r4-r12}
  bx     lr


//***********************************************************************
//  Addition over GF(p^2)
//  Operation: c [reg_p3] = a [reg_p1] + b [reg_p2] mod p, p = 2^127-1
//*********************************************************************** 
.global fp2add1271_a
.type	fp2add1271_a, %function
fp2add1271_a:
  push   {r4-r10}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



