我正在尝试使用c-to-verilog工具合成此代码。我做了必要的更改,例如:删除printf,将indd的2d数组更改为1d。但是,当我尝试合成它时,我收到此消息。
/file589:1114: error: conflicting types for 'indata_1d'
/file589:1113: error: previous declaration of 'indata_1d' was here
/file589:1114: warning: initialization makes integer from pointer without a cast
/file589:1114: error: initializer element is not computable at load time
/file589:1114: warning: data definition has no type or storage class
这些是我的代码。我不确定我是否做出了正确的改变
#ifndef SHA_H
#define SHA_H
/* NIST Secure Hash Algorithm */
/* heavily modified from Peter C. Gutmann's implementation */
/* Useful defines & typedefs */
typedef unsigned char BYTE;
typedef unsigned int INT32;
#define SHA_BLOCKSIZE 64
INT32 sha_info_digest[5]; /* message digest */
INT32 sha_info_count_lo, sha_info_count_hi; /* 64-bit bit count */
INT32 sha_info_data[16];
void sha_init ();
void sha_update (const BYTE *, int);
void sha_final ();
void sha_stream ();
void sha_print ();
#define BLOCK_SIZE 8192
#define VSIZE 2
const BYTE indata[VSIZE][BLOCK_SIZE] = {
{75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111,
109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101,
115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100,
103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99,
108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115,
99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102,
101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112,
102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110,
115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116,
84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101,
102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110,
104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98,
121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114,
101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97,
100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, ....
}
}; //exceeded the limit of characters to put here
const BYTE *indata_1d;
indata_1d = indata;
const int in_i[VSIZE] = { 8192, 8192 };
#endif /* SHA_H */
/* SHA f()-functions */
#define f1(x,y,z) ((x & y) | (~x & z))
#define f2(x,y,z) (x ^ y ^ z)
#define f3(x,y,z) ((x & y) | (x & z) | (y & z))
#define f4(x,y,z) (x ^ y ^ z)
/* SHA constants */
#define CONST1 0x5a827999L
#define CONST2 0x6ed9eba1L
#define CONST3 0x8f1bbcdcL
#define CONST4 0xca62c1d6L
/* 32-bit rotate */
#define ROT32(x,n) ((x << n) | (x >> (32 - n)))
#define FUNC(n,i) \
temp = ROT32(A,5) + f##n(B,C,D) + E + W[i] + CONST##n; \
E = D; D = C; C = ROT32(B,30); B = A; A = temp
/* compute the SHA digest of a FILE stream */
void sha_stream ()
{
int i, j;
const BYTE **p;
sha_init ();
for (j = 0; j < VSIZE; j++)
{
i = in_i[j];
p = &indata_1d[j*BLOCK_SIZE + 0];
sha_update (p, i);
}
sha_final ();
}
void local_memset (INT32 * s, int c, int n, int e)
{
INT32 uc;
INT32 *p;
int m;
m = n / 4;
uc = c;
p = (INT32 *) s;
while (e-- > 0)
{
p++;
}
while (m-- > 0)
{
*p++ = uc;
}
}
void local_memcpy (INT32 * s1, const BYTE * s2, int n)
{
INT32 *p1;
BYTE *p2;
INT32 tmp;
int m;
m = n / 4;
p1 = (INT32 *) s1;
p2 = (BYTE *) s2;
while (m-- > 0)
{
tmp = 0;
tmp |= 0xFF & *p2++;
tmp |= (0xFF & *p2++) << 8;
tmp |= (0xFF & *p2++) << 16;
tmp |= (0xFF & *p2++) << 24;
*p1 = tmp;
p1++;
}
}
/* do SHA transformation */
static void sha_transform ()
{
int i;
INT32 temp, A, B, C, D, E, W[80];
for (i = 0; i < 16; ++i)
{
W[i] = sha_info_data[i];
}
for (i = 16; i < 80; ++i)
{
W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
}
A = sha_info_digest[0];
B = sha_info_digest[1];
C = sha_info_digest[2];
D = sha_info_digest[3];
E = sha_info_digest[4];
for (i = 0; i < 20; ++i)
{
FUNC (1, i);
}
for (i = 20; i < 40; ++i)
{
FUNC (2, i);
}
for (i = 40; i < 60; ++i)
{
FUNC (3, i);
}
for (i = 60; i < 80; ++i)
{
FUNC (4, i);
}
sha_info_digest[0] += A;
sha_info_digest[1] += B;
sha_info_digest[2] += C;
sha_info_digest[3] += D;
sha_info_digest[4] += E;
}
/* initialize the SHA digest */
void sha_init ()
{
sha_info_digest[0] = 0x67452301L;
sha_info_digest[1] = 0xefcdab89L;
sha_info_digest[2] = 0x98badcfeL;
sha_info_digest[3] = 0x10325476L;
sha_info_digest[4] = 0xc3d2e1f0L;
sha_info_count_lo = 0L;
sha_info_count_hi = 0L;
}
/* update the SHA digest */
void sha_update (const BYTE * buffer, int count)
{
if ((sha_info_count_lo + ((INT32) count << 3)) < sha_info_count_lo)
{
++sha_info_count_hi;
}
sha_info_count_lo += (INT32) count << 3;
sha_info_count_hi += (INT32) count >> 29;
while (count >= SHA_BLOCKSIZE)
{
local_memcpy (sha_info_data, buffer, SHA_BLOCKSIZE);
sha_transform ();
buffer += SHA_BLOCKSIZE;
count -= SHA_BLOCKSIZE;
}
local_memcpy (sha_info_data, buffer, count);
}
/* finish computing the SHA digest */
void sha_final ()
{
int count;
INT32 lo_bit_count;
INT32 hi_bit_count;
lo_bit_count = sha_info_count_lo;
hi_bit_count = sha_info_count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
sha_info_data[count++] = 0x80;
if (count > 56)
{
local_memset (sha_info_data, 0, 64 - count, count);
sha_transform ();
local_memset (sha_info_data, 0, 56, 0);
}
else
{
local_memset (sha_info_data, 0, 56 - count, count);
}
sha_info_data[14] = hi_bit_count;
sha_info_data[15] = lo_bit_count;
sha_transform ();
}
const INT32 outData[5] =
{0x006a5a37UL, 0x93dc9485UL, 0x2c412112UL, 0x63f7ba43UL, 0xad73f922UL };
int main ()
{
int i;
int main_result;
main_result = 0;
sha_stream ();
for (i = 0; i < 5; i++)
{
main_result += (sha_info_digest[i] != outData[i]);
}
return main_result;
}
有人能帮助我吗?感谢。
答案 0 :(得分:3)
你想使用二维数组进行一维,所以使用下面的代码可能会有帮助
const BYTE *indata_1d = indata[0]; //indata is two-dimensional
//I think maybe you want use the first array
//indata_1d = indata;
并且应该更正以下功能
/* compute the SHA digest of a FILE stream */
void sha_stream()
{
int i, j;
const BYTE *p; //one-dimensional array
sha_init();
for (j = 0; j < VSIZE; j++)
{
i = in_i[j];
p = &indata_1d[j*BLOCK_SIZE + 0]; //indata_1d is one-dimensional array
sha_update(p, i);
}
sha_final();
}
答案 1 :(得分:2)
indata_1d = indata;
这是不允许的
const BYTE *indata_1d = indata ;
发出警告,但第一个版本无效C