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

Subversion Repositories nfcc

[/] [nfcc/] [trunk/] [rijndael/] [invcipher/] [invcipher.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 = "invkey.lst";
24
char *fname2 = "ct.lst";
25
char  key[80][20];
26
char  fpt[10][20];
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) cipher-text (%s) key (%s)\n", Nk, fname2, fname1);
36
  } else {
37
    printf("Usage %s: Nk cipher-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
 
72
DEF_GENPAT("invcipher");
73
SETTUNIT("ns");
74
 
75
/* interface */
76
DECLAR ("clk", ":1", "B", IN , ""           , "" );
77
DECLAR ("rst", ":1", "B", IN , ""           , "" );
78
DECLAR ("ldct",":1", "B", IN , ""           , "" );
79
DECLAR ( "ct", ":2", "X", IN , "31 downto 0", "" );
80
//DECLAR ("cipher_inst_ildpt", ":1", "B", SIGNAL , ""           , "" );
81
//DECLAR ("cipher_inst_ipt"  , ":1", "X", SIGNAL , "31 downto 0", "" );
82
DECLAR ( "Nk", ":2", "X", IN , " 3 downto 0", "" );
83
//DECLAR ( "st", ":2", "X", OUT, " 7 downto 0", "" );
84
DECLAR ("key", ":2", "X", IN , "31 downto 0", "" );
85
DECLAR ( "pt", ":2", "X", OUT, "31 downto 0", "" );
86
//DECLAR ("cipher_inst_swp", ":1", "B", SIGNAL , ""           , "" );
87
DECLAR (  "v", ":1", "B", OUT, ""           , "" );
88
DECLAR ("invcipher_inst_rnd", ":1", "X", SIGNAL , "  3 downto 0"           , "" );
89
//DECLAR ( "sr_prb", ":2", "X", OUT, "31 downto 0", "" );
90
//DECLAR ( "sb_prb", ":2", "X", OUT, "31 downto 0", "" );
91
//DECLAR ( "mc_prb", ":2", "X", OUT, "31 downto 0", "" );
92
//DECLAR ("ct2b_1", ":1", "B", SIGNAL , ""           , "" );
93
//DECLAR ("ct2b_0", ":1", "B", SIGNAL , ""           , "" );
94
//DECLAR ("invcipher_inst_wsb", ":1", "X", SIGNAL , "31 downto 0"           , "" );
95
//DECLAR ("invcipher_inst_ireg1", ":1", "X", SIGNAL , "127 downto 0"           , "" );
96
//DECLAR ("invcipher_inst_ireg2", ":1", "X", SIGNAL , "127 downto 0"           , "" );
97
//DECLAR ("cipher_inst_swp1", ":1", "B", SIGNAL , ""           , "" );
98
DECLAR ("vss", ":1", "B", IN , ""           , "" );
99
DECLAR ("vdd", ":1", "B", IN , ""           , "" );
100
 
101
AFFECT ("0", "vss", "0b0");
102
AFFECT ("0", "vdd", "0b1");
103
 
104
AFFECT (  "0",  "ct", "0x00000000");
105
AFFECT (  "0", "key", "0x00000000");
106
AFFECT (  "0", "rst", "0b1");
107
AFFECT (  "0","ldct", "0b0");
108
AFFECT (  "0",  "Nk",  sNk );
109
AFFECT (  "0", "clk", "0b0");
110
AFFECT ("+50", "clk", "0b1");
111
AFFECT ("+50", "clk", "0b0");
112
AFFECT ( "+0", "rst", "0b0");
113
AFFECT ( "+0","ldct", "0b1");
114
 
115
for (i=0; i < ps; i++)
116
{
117
  AFFECT ( "+0",  "ct", fpt[i]);
118
  AFFECT ("+50", "clk", "0b1" );
119
  AFFECT ("+50", "clk", "0b0" );
120
  AFFECT ( "+0", "key", key[i]);
121
 
122
}
123
 
124
AFFECT ( "+0","ldct", "0b0");
125
AFFECT ( "+0",  "ct", "0x00000000");
126
 
127
for (; i < ks; i++)
128
{
129
  AFFECT ("+50", "clk", "0b1" );
130
  AFFECT ("+50", "clk", "0b0" );
131
  AFFECT ( "+0", "key", key[i]);
132
}
133
 
134
AFFECT ("+50", "clk", "0b1" );
135
AFFECT ("+50", "clk", "0b0" );
136
AFFECT ( "+0", "key", "0x00000000");
137
 
138
for (; i < 64; i++)
139
{
140
  AFFECT ("+50", "clk", "0b1" );
141
  AFFECT ("+50", "clk", "0b0" );
142
}
143
 
144
AFFECT ("+50", "clk", "0b1");
145
 
146
SAV_GENPAT ();
147
}
148
 

powered by: WebSVN 2.1.0

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