static void serpent_encrypt(const uint32_t in_blk[4], uint32_t out_blk[], const uint32_t *l_key)
{
    uint32_t a,b,c,d,e,f,g,h;
    uint32_t t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
    
#ifdef  BLOCK_SWAP
    a = byteswap32(in_blk[3]); b = byteswap32(in_blk[2]); 
    c = byteswap32(in_blk[1]); d = byteswap32(in_blk[0]);
#else
    a = in_blk[0]; b = in_blk[1]; c = in_blk[2]; d = in_blk[3];
#endif

    k_xor( 0,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor( 1,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor( 2,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor( 3,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor( 4,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor( 5,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor( 6,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor( 7,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor( 8,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor( 9,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(10,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(11,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(12,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(13,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(14,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(15,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(16,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(17,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(18,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(19,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(20,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(21,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(22,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(23,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(24,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(25,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(26,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(27,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(28,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(29,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
    k_xor(30,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h); 
    k_xor(31,e,f,g,h); sb7(e,f,g,h,a,b,c,d); k_xor(32,a,b,c,d); 
    
#ifdef  BLOCK_SWAP
    out_blk[3] = byteswap32(a); out_blk[2] = byteswap32(b); 
    out_blk[1] = byteswap32(c); out_blk[0] = byteswap32(d);
#else
    out_blk[0] = a; out_blk[1] = b; out_blk[2] = c; out_blk[3] = d;
#endif
};
Пример #2
0
static void
procfile(char *fnam)
{
  FILE *fp = 0;
  char str[120], lasttag[3] = "  ";
  int firstsample = 1;
  printf("processing %s\n", fnam);
  fp = fopen(fnam, "r");
  assert(fp != 0);
  while ((0 != fgets(str, sizeof(str), fp)) && (0 != str[0])) {
    assert(strlen(str) > 2);
    assert(str[2] == ' ');
    str[2] = 0;
    if (!strcmp(lasttag, "DA") && strcmp(str, "DA")) {
      sb1();  /* Over, transfer temporary content into permanent one */
    }
    if (!strcmp(str, "NS")) {
      if (!firstsample) ns1();
      firstsample = 0;
      assert(10 == sscanf(str+3, "%d %d/%d/%d %d:%d:%d %d %d (%d)",
			&nsamp, &yyyy, &mm, &dd, &hh, &nn, &ss, 
			&nevsc, &llock, &nevhf));
      ns0();
    }
    else if (!strcmp(str, "RC")) {
      assert(4 == sscanf(str+3, "%d %s %d %f",
		       &partition, rcstate, &rcevents, &trigrate));
      rc();   /* Debug printout only */
    }
    else if (!strcmp(str, "SB")) {
      char plus[2];
      int nscan;
      nscan = sscanf(str+3, "%s %d %s %s %d %d%s",
		     cratename, &slot, boardname, bufname, &nread, &nspy, plus);
      assert(nscan == 6 || (nscan == 7 && !strcmp(plus, "+")));
      wrap = (nscan == 7);
      ndata = 0;
      if (data) free(data);
      data = (void *) malloc(nread*sizeof(data[0]));
      sb0();   /* Debug printout only */
    }
    else if (!strcmp(str, "DA")) {
      int nscan, i;
      uint4 d[10];
      nscan = sscanf(str+3, "%x %x %x %x %x %x %x %x %x %x",
		     d+0, d+1, d+2, d+3, d+4, d+5, d+6, d+7, d+8, d+9);
      assert(data != 0 && ndata+nscan <= nread);
      for (i = 0; i < nscan; i++)
	data[ndata++] = d[i];
    }
    else {
      assert(0); /* unrecognized tag */
    }
    strcpy(lasttag, str);
  }
  if (fp) fclose(fp);
  if (!strcmp(lasttag, "DA"))
    sb1();
  if (!firstsample) ns1();
}