I downloaded the Salsa20 source file:
http://cr.yp.to/snuffle/ecrypt.c
the related include files and test vectors:
http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/*checkout*/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?rev=210
I renamed the source file in "Salsa20.cpp".
I tried to compile the code with the VS2008 C++ EE, but I get:
error C2117: 'sigma' : array bounds overflow
error C2117: 'tau' : array bounds overflow
I had to change the lines:
static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";
in:
static const char sigma[] = "expand 32-byte k";
static const char tau[] = "expand 16-byte k";
Then I wrote this code to compare the output of my program with the test
vectors:
const int kbits= 128, ivbits= 64;
ECRYPT_ctx ctx; u8 key[kbits/8], iv[ivbits/8];
for(int i= 0; i < kbits/8; i++) key[i]= 0;
for(int i= 0; i < ivbits/8; i++) iv[i]= 0;
ECRYPT_keysetup(&ctx, key, kbits, ivbits);
ECRYPT_ivsetup(&ctx, iv);
for(int i= 0; i < 512; i++) {
u8 x= 0; ECRYPT_encrypt_bytes(&ctx, &x, &x, 1);
printf("%02X", x);
}
Only the first x is good; for example, with key= 000... and iv= 000... I
get: 65D0D175..., while the result should be: 6513ADAE...
Where is the problem?
Thanks
Cristiano