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

Subversion Repositories bluespec_md6

[/] [bluespec_md6/] [trunk/] [C_implementation/] [ginv.c] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kfleming
/* ginv.c
2
** Ronald L. Rivest
3
** 5/14/08
4
** Routines to work with g and ginv
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;i<w;i++)
31
    { y = y ^ xx;
32
      xx = xx << ell;
33
    }
34
  z = 0;
35
  yy = y;
36
  for (i=0;i<w;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
int Ar[16] =   { 28,18,1,15,12,5,6,22,23,10,3,13,32,10,11,4 };
52
int Aell[16] = { 14,15,3,13,29,20,3,7,15,24,9,8,4,19,6,5};
53
 
54
int main()
55
{ int i,i1,i2,minwt,r,ell,j;
56
  md6_word x,y;
57
  for (j=0;j<16;j++)
58
    {
59
      r = Ar[j];
60
      ell = Aell[j];
61
      printf("r=%d ell=%d: g(x,r,ell)=y ginv(y,r,ell)=x\n",r,ell);
62
 
63
      minwt = 64;
64
      for (i=0;i<w;i++)
65
        {
66
          x = ((md6_word)1)<<i;
67
          y = g(x,r,ell);
68
          minwt = min(minwt,wt(y));
69
        }
70
      printf("g:    r=%d ell=%d xwt=1, minywt=%d\n",r,ell,minwt);
71
 
72
      minwt = 64;
73
      for (i=0;i<w;i++)
74
        {
75
          y = ((md6_word)1)<<i;
76
          x = ginv(y,r,ell);
77
          minwt = min(minwt,wt(x));
78
        }
79
      printf("ginv: r=%d ell=%d ywt=1, minxwt=%d\n",r,ell,minwt);
80
 
81
      minwt = 64;
82
      for (i1=0;i1<w;i1++)
83
        for (i2=i1+1;i2<w;i2++)
84
          {
85
            x = (1LL<<i1)+(1LL<<i2);
86
            y = g(x,r,ell);
87
            minwt = min(minwt,wt(y));
88
          }
89
      printf("g:    r=%d ell=%d xwt=2, minywt=%d\n",r,ell,minwt);
90
 
91
      minwt = 64;
92
      for (i1=0;i1<w;i1++)
93
        for (i2=i1+1;i2<w;i2++)
94
          {
95
            y = (1LL<<i1)+(1LL<<i2);
96
            x = ginv(y,r,ell);
97
            minwt = min(minwt,wt(x));
98
          }
99
      printf("ginv: r=%d ell=%d ywt=2, minxwt=%d\n",r,ell,minwt);
100
 
101
    }
102
  return 0;
103
}

powered by: WebSVN 2.1.0

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