OpenCores
URL https://opencores.org/ocsvn/bluespec_md6/bluespec_md6/trunk

Subversion Repositories bluespec_md6

[/] [bluespec_md6/] [trunk/] [C_implementation/] [gwt.c] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kfleming
/* gwt.c
2
** Ronald L. Rivest
3
** 5/14/08
4
** Routines to work with differential properties of g
5
*/
6
 
7
#include <stdio.h>
8
 
9
#include <stdint.h>
10
typedef uint64_t md6_word;
11
#define w 64
12
 
13
/* Useful macros: min and max */
14
#define min(a,b) ((a)<(b)? (a) : (b))
15
#define max(a,b) ((a)>(b)? (a) : (b))
16
 
17
md6_word g(md6_word x,int r,int ell)
18
{
19
  x = x ^ (x >> r);
20
  x = x ^ (x << ell);
21
  return x;
22
}
23
 
24
md6_word ginv(md6_word x, int r,int ell)
25
{
26
  int i;
27
  md6_word y,z,xx,yy;
28
  y = 0;
29
  xx = x;
30
  for (i=0;xx!=0;i++)
31
    { y = y ^ xx;
32
      xx = xx << ell;
33
    }
34
  z = 0;
35
  yy = y;
36
  for (i=0;yy!=0;i++)
37
    { z = z ^ yy;
38
      yy = yy >> r;
39
    }
40
  return z;
41
}
42
 
43
int wt(md6_word x)
44
{
45
  int i,c=0;
46
  for (i=0;i<w;i++)
47
    c += ( 1 & (x>>i) ) ;
48
  return c;
49
}
50
 
51
// standard shift table, for MD6 as of 6/1/08
52
int Ar[16] =   { 28,18,1,15,12, 5,6,22,23,10,3,13,32,10,11,4 };
53
int Aell[16] = { 14,15,3,13,29,20,3, 7,15,24,9, 8, 4,19, 6,5};
54
 
55
int test1()
56
// print out difference tables for possibly useful r,ell pairs
57
{ int i,r,ell;
58
  md6_word x;
59
  int wt_table_g[w+1];
60
  int wt_table_ginv[w+1];
61
  if (w>16){ printf("w=%d too large!",w); return 1; }
62
  for (r=1;r<w;r++)
63
    for (ell=1;ell<=w;ell++)
64
      {
65
        if (r==ell) continue;
66
        if (r+ell>=w) continue;
67
 
68
        // compute difference table for g
69
        for (i=0;i<=w;i++) wt_table_g[i] = 2*w;
70
        for (x=0;;x++)
71
          {
72
            int in_wt = wt(x);
73
            int out_wt = wt(g(x,r,ell));
74
            wt_table_g[in_wt] = min(wt_table_g[in_wt],out_wt);
75
            if (x==(md6_word)(-1)) break;
76
          }
77
 
78
        // compute difference table for ginv
79
        for (i=0;i<=w;i++) wt_table_ginv[i] = 2*w;
80
        for (x=0;;x++)
81
          {
82
            int in_wt = wt(x);
83
            int out_wt = wt(ginv(x,r,ell));
84
            wt_table_ginv[in_wt] = min(wt_table_ginv[in_wt],out_wt);
85
            if (x==(md6_word)(-1)) break;
86
          }
87
 
88
        // print results
89
        if (wt_table_ginv[1]>2)
90
          { printf("r=%2d,ell=%2d ",r,ell);
91
            for (i=0;i<=w;i++) printf("%2d ",wt_table_g[i]);
92
            printf("\n");
93
            printf("r=%2d,ell=%2d ",r,ell);
94
            for (i=0;i<=w;i++) printf("%2d ",wt_table_ginv[i]);
95
            printf("\n\n");
96
          }
97
      }
98
  return 0;
99
}
100
 
101
int test2()
102
{
103
  int r,ell;
104
  md6_word x;
105
  int gamma[w][w];  // gamma[r][ell] is min weight of ginv(x,r,ell) for 
106
                    // weight-one inputs x
107
 
108
  printf("Table of weights of min-weight ginv outputs for ginv inputs of weight 1 (i.e. of gamma(r,ell))\n");
109
  printf("  ell=");
110
  for (ell=1;ell<w;ell++) printf("%2d ",ell);
111
  printf("\n");
112
  for (r=1;r<w;r++)
113
    {
114
      printf("r=%2d: ",r);
115
      for (ell=1;ell<w;ell++)
116
        {
117
          gamma[r][ell] = 2*w;
118
          for (x=1;x>0;x=x<<1)
119
            gamma[r][ell] = min(gamma[r][ell],wt(ginv(x,r,ell)));
120
          printf("%2d ",gamma[r][ell]);
121
          if (gamma[r][ell]==2 &&
122
              ( (r != 2*ell) &&
123
                (r != ell) &&
124
                (ell != 2*r) &&
125
                (2*r+ell<=w) ) )
126
              printf("\nConjecture wrong! r=%d ell=%d",r,ell);
127
        }
128
      printf("\n");
129
      }
130
  return 0;
131
 
132
}
133
 
134
int main()
135
{
136
  // return test1();
137
  return test2();
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.