int vs size_t

This commit is contained in:
Frank Denis 2016-03-06 13:58:10 +01:00
parent f4397f12d0
commit 212841b28d

View File

@ -8,25 +8,25 @@ static unsigned char a[64];
int main(void) int main(void)
{ {
int clen; size_t clen;
for (clen = 0; clen < sizeof c; ++clen) { for (clen = 0; clen < sizeof c; ++clen) {
randombytes_buf(key, sizeof key); randombytes_buf(key, sizeof key);
randombytes_buf(c, clen); randombytes_buf(c, clen);
crypto_auth_hmacsha512(a, c, clen, key); crypto_auth_hmacsha512(a, c, clen, key);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) { if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) {
printf("fail %d\n", clen); printf("fail %u\n", (unsigned int) clen);
return 100; return 100;
} }
if (clen > 0) { if (clen > 0) {
c[rand() % clen] += 1 + (rand() % 255); c[(size_t) rand() % clen] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) { if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
printf("forgery %d\n", clen); printf("forgery %u\n", (unsigned int) clen);
return 100; return 100;
} }
a[rand() % sizeof a] += 1 + (rand() % 255); a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) { if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
printf("forgery %d\n", clen); printf("forgery %u\n", (unsigned int) clen);
return 100; return 100;
} }
} }