title: GCM Multiplication Implementation
body: <p>I am puting up a C code for the Multiplication of block (Alogrithm 1) in the GCM SP-800-38D document <a href="http://www.google.com.ng/url?sa=t&amp;rct=j&amp;q=GCM%20sp%20800%2038d&amp;source=web&amp;cd=1&amp;ved=0CFYQFjAA&amp;url=http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf&amp;ei=n162T4bRDsnL0QXjiqW0Cg&amp;usg=AFQjCNEElGcj_hAkPTB-5voW5YxfN7iocg&amp;cad=rja" rel="nofollow">here</a>. Page 11-12.</p>
  
  <p>Having completed the code, I want to see if there are any way I can test the code. You can find attached below the code I have put up. Note that instead of the 128 bit block, I used a 24 bit block just for testing purposed. I will appreciate any suggestions where necessary.</p>
  
  <pre><code>void BLK_MUL (u8 *val_1,u8 *val_2, u8 *out_val)
  { 
  
      u8 xdata R_val = 0xE1;     
      u8 xdata Z_val[3],V_val[3];
      u8 mask_b   = 0x80;        
      u16 i;  u8 j;           
      bit rnd;                
  
      for(j=0;j&lt;3;j++,++val_2)    
      {
          Z_val[j]=0x00;      
          V_val[j]=*val_2;    
      }       
  
  
      for(i=0;i&lt;24;i++)
      { 
          if (*val_1 &amp; mask_b)
          {
              for(j=0;j&lt;3;j++)    
                  Z_val[j]^=V_val[j]; 
          }
          if (!(V_val[2] &amp; 0x01))
          {//if LSB of V_val is 0
              for(j=0;j&lt;3;j++)
              { //V_val = rightshift(V_val)
                  if (j!=0)
                      if (V_val[2-j] &amp; 0x01)
                          V_val[3-j] |= 0x80;
                  V_val[2-j]&gt;&gt;=1;          
              }
          }
          else
          {//if LSB of V_val is 1
              for(j=0;j&lt;3;j++)
              {//V_val = rightshift(V_val)
                  if (j!=0)
                      if (V_val[2-j] &amp; 0x01)
                          V_val[3-j] |= 0x80;
                  V_val[2-j]&gt;&gt;=1;          
              }
              V_val[0]^=R_val; //V_val = rightshift(V_val) ^ R                
          }
          if(mask_b &amp; 0x01)   { val_1++; rnd=1;}  
          mask_b &gt;&gt;= 1;                       
          if (rnd)    { mask_b=0x80; rnd=0; } 
      }
  
      STR_CPY(out_val,Z_val,3);   
  
      return ;        
  }
  
  
  void main()
  {
  
      code unsigned char val_1[3] ={  0x2b,0x7e,0x15  };
      code unsigned char val_2[3] ={  0x39,0x25,0x84  };
      unsigned char out[3];
  
      BLK_MUL (val_1,val_2,out);
  
      return;
  }
  </code></pre>