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

Subversion Repositories nfcc

[/] [nfcc/] [trunk/] [camellia/] [camellia.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 arif_endro
#include <stdio.h>
2
#include <string.h>
3
#include "genpat.h"
4
 
5
char *inttostr(entier)
6
int entier;
7
 {
8
 char *str;
9
 str = (char *) mbkalloc (32 * sizeof (char));
10
 sprintf (str, "%d",entier);
11
 return(str);
12
 }
13
  /*------------------------------*/
14
  /* end of the description       */
15
  /*------------------------------*/
16
 
17
main (int argc, char *argv[])
18
{
19
int i,c;
20
int Nk,ks,ps;
21
char sNk[4];
22
FILE *f1, *f2;
23
char *fname1 = "key.lst";
24
char *fname2 = "pt.lst";
25
char  key[0xff][0x4f];
26
char  fpt[0xff][0x4f];
27
 
28
Nk = 4;
29
/* remember argc start from 1 not zero and command line is the first array */
30
if (argc > 1 ) {
31
  if (argc == 4) {
32
    fname1 = argv[3]; /* key */
33
    fname2 = argv[2]; /* plain text*/
34
    sscanf(argv[1], "%d", &Nk);
35
    printf("Using Nk(0x%x) plain-text (%s) key (%s)\n", Nk, fname2, fname1);
36
  } else {
37
    printf("Usage %s: Nk plain-text key\n", argv[0]);
38
    return 0;
39
  }
40
}
41
 
42
sprintf(sNk, "0x%x", Nk);
43
 
44
if(fname1 && (f1 = fopen(fname1, "rt"))) {
45
  i = 0;
46
  while(fgets(key[i],sizeof(key[i]),f1) != NULL) {
47
    c = strlen(key[i]);
48
    if(key[i][c-1] == '\n') key[i][c-1] = '\0';
49
    i++;
50
  }
51
  fclose (f1);
52
} else {
53
  fclose (f1);
54
}
55
 
56
ks = i;
57
 
58
if(fname2 && (f2 = fopen(fname2, "rt"))) {
59
  i = 0;
60
  while(fgets(fpt[i],sizeof(fpt[i]),f2) != NULL) {
61
    c = strlen(fpt[i]);
62
    if(fpt[i][c-1] == '\n') fpt[i][c-1] = '\0';
63
    i++;
64
  }
65
  fclose (f2);
66
} else {
67
  fclose (f2);
68
}
69
 
70
ps = i;
71
//printf("ps: %d\n",ps);
72
 
73
DEF_GENPAT("camellia");
74
SETTUNIT("ns");
75
 
76
/* interface */
77
DECLAR ("clk", ":1", "B", IN , ""           , "" );
78
DECLAR ("rst", ":1", "B", IN , ""           , "" );
79
DECLAR ("ldpt",":1", "B", IN , ""           , "" );
80
DECLAR ( "pt", ":2", "X", IN , "63 downto 0", "" );
81
//DECLAR ("cipher_inst_ildpt", ":1", "B", SIGNAL , ""           , "" );
82
//DECLAR ("cipher_inst_ipt"  , ":1", "X", SIGNAL , "31 downto 0", "" );
83
DECLAR ( "Nk", ":2", "X", IN , " 3 downto 0", "" );
84
//DECLAR ( "st", ":2", "X", OUT, " 7 downto 0", "" );
85
DECLAR ("key", ":2", "X", IN , "63 downto 0", "" );
86
DECLAR ( "ct", ":2", "X", OUT, "63 downto 0", "" );
87
//DECLAR ( "rc_prb", ":2", "X", OUT, " 2 downto 0", "" );
88
//DECLAR ( "l_prb", ":2", "X", OUT, "63 downto 0", "" );
89
//DECLAR ( "r_prb", ":2", "X", OUT, "63 downto 0", "" );
90
//DECLAR ( "fla_prb", ":2", "X", OUT, "63 downto 0", "" );
91
//DECLAR ( "z_prb", ":2", "X", OUT, "63 downto 0", "" );
92
//DECLAR ( "il_prb", ":2", "X", OUT, "63 downto 0", "" );
93
//DECLAR ( "ir_prb", ":2", "X", OUT, "63 downto 0", "" );
94
DECLAR (  "v", ":1", "B", OUT, ""           , "" );
95
//DECLAR ("cipher_inst_rnd", ":1", "X", SIGNAL , "  3 downto 0"           , "" );
96
//DECLAR ("cipher_inst_swp", ":1", "B", SIGNAL , ""           , "" );
97
//DECLAR ("ct2b_1", ":1", "B", SIGNAL , ""           , "" );
98
//DECLAR ("ct2b_0", ":1", "B", SIGNAL , ""           , "" );
99
//DECLAR ("cipher_inst_ireg1", ":1", "X", SIGNAL , "127 downto 0"           , "" );
100
//DECLAR ("cipher_inst_ireg2", ":1", "X", SIGNAL , "127 downto 0"           , "" );
101
//DECLAR ("cipher_inst_swp1", ":1", "B", SIGNAL , ""           , "" );
102
DECLAR ("vss", ":1", "B", IN , ""           , "" );
103
DECLAR ("vdd", ":1", "B", IN , ""           , "" );
104
 
105
AFFECT ("0", "vss", "0b0");
106
AFFECT ("0", "vdd", "0b1");
107
 
108
AFFECT (  "0",  "pt", "0x0000000000000000");
109
AFFECT (  "0", "key", "0x0000000000000000");
110
AFFECT (  "0", "rst", "0b1");
111
AFFECT (  "0","ldpt", "0b0");
112
AFFECT (  "0",  "Nk",  sNk );
113
AFFECT (  "0", "clk", "0b0");
114
AFFECT ("+50", "clk", "0b1");
115
AFFECT ("+50", "clk", "0b0");
116
AFFECT ( "+0", "rst", "0b0");
117
AFFECT ( "+0","ldpt", "0b1");
118
 
119
//if(Nk==0x4)
120
//AFFECT ( "+0",  "pt", "0x3243f6a8");
121
 
122
for (i=0; i < ps; i++)
123
{
124
  AFFECT ( "+0",  "pt", fpt[i]);
125
  AFFECT ("+50", "clk", "0b1" );
126
  AFFECT ("+50", "clk", "0b0" );
127
  AFFECT ( "+0", "key", key[i]);
128
 
129
//if ((i==1) && (Nk==0x4))
130
//AFFECT ( "+0",  "pt", "0x885a308d");
131
//if ((i==2) && (Nk==0x4))
132
//AFFECT ( "+0",  "pt", "0x313198a2");
133
//if ((i==3) && (Nk==0x4))
134
//AFFECT ( "+0",  "pt", "0xe0370734");
135
 
136
}
137
 
138
AFFECT ( "+0","ldpt", "0b0");
139
AFFECT ( "+0",  "pt", "0x0000000000000000");
140
 
141
for (; i < ks; i++)
142
{
143
  AFFECT ("+50", "clk", "0b1" );
144
  AFFECT ("+50", "clk", "0b0" );
145
  AFFECT ( "+0", "key", key[i]);
146
}
147
 
148
AFFECT ("+50", "clk", "0b1" );
149
AFFECT ("+50", "clk", "0b0" );
150
AFFECT ( "+0", "key", "0x0000000000000000");
151
 
152
for (; i < 0x2f; i++)
153
{
154
  AFFECT ("+50", "clk", "0b1" );
155
  AFFECT ("+50", "clk", "0b0" );
156
}
157
 
158
AFFECT ("+50", "clk", "0b1");
159
 
160
SAV_GENPAT ();
161
}
162
 

powered by: WebSVN 2.1.0

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