test_crapi_digest.c | test_crapi_digest.c | |||
---|---|---|---|---|
skipping to change at line 62 | skipping to change at line 62 | |||
} | } | |||
int main (int argc, char *argv[]) | int main (int argc, char *argv[]) | |||
{ | { | |||
uint8_t md5_dst[16]; | uint8_t md5_dst[16]; | |||
size_t md5_dstlen = sizeof md5_dst; | size_t md5_dstlen = sizeof md5_dst; | |||
uint8_t sha1_dst[20]; | uint8_t sha1_dst[20]; | |||
size_t sha1_dstlen = sizeof sha1_dst; | size_t sha1_dstlen = sizeof sha1_dst; | |||
uint8_t sha256_dst[32]; | ||||
size_t sha256_dstlen = sizeof sha256_dst; | ||||
char *orig_md5sum, comp_md5sum[(sizeof md5_dst * 2) + 1]; | char *orig_md5sum, comp_md5sum[(sizeof md5_dst * 2) + 1]; | |||
char *orig_sha1sum, comp_sha1sum[(sizeof sha1_dst * 2) + 1]; | char *orig_sha1sum, comp_sha1sum[(sizeof sha1_dst * 2) + 1]; | |||
char *orig_sha256sum, comp_sha256sum[(sizeof sha256_dst * 2) + 1]; | ||||
char *filename; | char *filename; | |||
int fd; | int fd; | |||
if (argc != 4) { | if (argc != 5) { | |||
fprintf (stderr, "Usage: %s <file> <md5sum> <sha1sum>\n", a | fprintf (stderr, "Usage: %s <file> <md5sum> <sha1sum> <sha2 | |||
rgv[0]); | 56sum>\n", argv[0]); | |||
return (1); | return (1); | |||
} | } | |||
filename = argv[1]; | filename = argv[1]; | |||
orig_md5sum = argv[2]; | orig_md5sum = argv[2]; | |||
orig_sha1sum = argv[3]; | orig_sha1sum = argv[3]; | |||
orig_sha256sum = argv[4]; | ||||
if (crapi_init (NULL) != 0) { | if (crapi_init (NULL) != 0) { | |||
fprintf (stderr, "crapi_init() != 0\n"); | fprintf (stderr, "crapi_init() != 0\n"); | |||
abort (); | abort (); | |||
} | } | |||
fd = open (filename, O_RDONLY); | fd = open (filename, O_RDONLY); | |||
if (fd < 0) { | if (fd < 0) { | |||
perror ("open"); | perror ("open"); | |||
skipping to change at line 117 | skipping to change at line 122 | |||
abort (); | abort (); | |||
} | } | |||
mem2hex (sha1_dst, sha1_dstlen, comp_sha1sum, sizeof comp_sha1sum); | mem2hex (sha1_dst, sha1_dstlen, comp_sha1sum, sizeof comp_sha1sum); | |||
if (strcmp (orig_sha1sum, comp_sha1sum) != 0) { | if (strcmp (orig_sha1sum, comp_sha1sum) != 0) { | |||
fprintf (stderr, "crapi_digest::SHA1(%s) != %s (== %s)\n", filename, orig_sha1sum, comp_sha1sum); | fprintf (stderr, "crapi_digest::SHA1(%s) != %s (== %s)\n", filename, orig_sha1sum, comp_sha1sum); | |||
abort (); | abort (); | |||
} | } | |||
if (lseek (fd, 0, SEEK_SET) == (off_t)-1) { | ||||
perror ("lseek"); | ||||
return (2); | ||||
} | ||||
if (crapi_digest_fd (fd, CRAPI_DIGEST_SHA256, &sha256_dst, &sha256_ | ||||
dstlen) != 0) { | ||||
fprintf (stderr, "crapi_digest() != 0\n"); | ||||
abort (); | ||||
} | ||||
mem2hex (sha256_dst, sha256_dstlen, comp_sha256sum, sizeof comp_sha | ||||
256sum); | ||||
if (strcmp (orig_sha256sum, comp_sha256sum) != 0) { | ||||
fprintf (stderr, "crapi_digest::SHA256(%s) != %s (== %s)\n" | ||||
, filename, orig_sha256sum, comp_sha256sum); | ||||
abort (); | ||||
} | ||||
close (fd); | close (fd); | |||
return (0); | return (0); | |||
} | } | |||
End of changes. 5 change blocks. | ||||
3 lines changed or deleted | 28 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |