Changeset View
Changeset View
Standalone View
Standalone View
sbin/md5/md5.c
Show All 25 Lines | |||||
#include <err.h> | #include <err.h> | ||||
#include <md5.h> | #include <md5.h> | ||||
#include <ripemd.h> | #include <ripemd.h> | ||||
#include <sha.h> | #include <sha.h> | ||||
#include <sha256.h> | #include <sha256.h> | ||||
#include <sha384.h> | #include <sha384.h> | ||||
#include <sha512.h> | #include <sha512.h> | ||||
#include <sha512t.h> | #include <sha512t.h> | ||||
#include <skein.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
/* | /* | ||||
* Length of test block, number of test blocks. | * Length of test block, number of test blocks. | ||||
Show All 14 Lines | |||||
extern const char *MD5TestOutput[MDTESTCOUNT]; | extern const char *MD5TestOutput[MDTESTCOUNT]; | ||||
extern const char *SHA1_TestOutput[MDTESTCOUNT]; | extern const char *SHA1_TestOutput[MDTESTCOUNT]; | ||||
extern const char *SHA256_TestOutput[MDTESTCOUNT]; | extern const char *SHA256_TestOutput[MDTESTCOUNT]; | ||||
extern const char *SHA384_TestOutput[MDTESTCOUNT]; | extern const char *SHA384_TestOutput[MDTESTCOUNT]; | ||||
extern const char *SHA512_TestOutput[MDTESTCOUNT]; | extern const char *SHA512_TestOutput[MDTESTCOUNT]; | ||||
extern const char *SHA512t256_TestOutput[MDTESTCOUNT]; | extern const char *SHA512t256_TestOutput[MDTESTCOUNT]; | ||||
extern const char *RIPEMD160_TestOutput[MDTESTCOUNT]; | extern const char *RIPEMD160_TestOutput[MDTESTCOUNT]; | ||||
extern const char *SKEIN256_TestOutput[MDTESTCOUNT]; | |||||
extern const char *SKEIN512_TestOutput[MDTESTCOUNT]; | |||||
extern const char *SKEIN1024_TestOutput[MDTESTCOUNT]; | |||||
typedef struct Algorithm_t { | typedef struct Algorithm_t { | ||||
const char *progname; | const char *progname; | ||||
const char *name; | const char *name; | ||||
const char *(*TestOutput)[MDTESTCOUNT]; | const char *(*TestOutput)[MDTESTCOUNT]; | ||||
DIGEST_Init *Init; | DIGEST_Init *Init; | ||||
DIGEST_Update *Update; | DIGEST_Update *Update; | ||||
DIGEST_End *End; | DIGEST_End *End; | ||||
Show All 10 Lines | |||||
typedef union { | typedef union { | ||||
MD5_CTX md5; | MD5_CTX md5; | ||||
SHA1_CTX sha1; | SHA1_CTX sha1; | ||||
SHA256_CTX sha256; | SHA256_CTX sha256; | ||||
SHA384_CTX sha384; | SHA384_CTX sha384; | ||||
SHA512_CTX sha512; | SHA512_CTX sha512; | ||||
RIPEMD160_CTX ripemd160; | RIPEMD160_CTX ripemd160; | ||||
SKEIN256_CTX skein256; | |||||
SKEIN512_CTX skein512; | |||||
SKEIN1024_CTX skein1024; | |||||
} DIGEST_CTX; | } DIGEST_CTX; | ||||
/* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH, | /* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH, | ||||
SHA256_DIGEST_LENGTH, SHA512_DIGEST_LENGTH, | SHA256_DIGEST_LENGTH, SHA512_DIGEST_LENGTH, | ||||
RIPEMD160_DIGEST_LENGTH)*2+1 */ | RIPEMD160_DIGEST_LENGTH, SKEIN1024_DIGEST_LENGTH)*2+1 */ | ||||
#define HEX_DIGEST_LENGTH 129 | #define HEX_DIGEST_LENGTH 257 | ||||
/* algorithm function table */ | /* algorithm function table */ | ||||
static const struct Algorithm_t Algorithm[] = { | static const struct Algorithm_t Algorithm[] = { | ||||
{ "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init, | { "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init, | ||||
(DIGEST_Update*)&MD5_Update, (DIGEST_End*)&MD5End, | (DIGEST_Update*)&MD5_Update, (DIGEST_End*)&MD5End, | ||||
&MD5Data, &MD5File }, | &MD5Data, &MD5File }, | ||||
{ "sha1", "SHA1", &SHA1_TestOutput, (DIGEST_Init*)&SHA1_Init, | { "sha1", "SHA1", &SHA1_TestOutput, (DIGEST_Init*)&SHA1_Init, | ||||
(DIGEST_Update*)&SHA1_Update, (DIGEST_End*)&SHA1_End, | (DIGEST_Update*)&SHA1_Update, (DIGEST_End*)&SHA1_End, | ||||
&SHA1_Data, &SHA1_File }, | &SHA1_Data, &SHA1_File }, | ||||
{ "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init, | { "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init, | ||||
(DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End, | (DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End, | ||||
&SHA256_Data, &SHA256_File }, | &SHA256_Data, &SHA256_File }, | ||||
{ "sha384", "SHA384", &SHA384_TestOutput, (DIGEST_Init*)&SHA384_Init, | { "sha384", "SHA384", &SHA384_TestOutput, (DIGEST_Init*)&SHA384_Init, | ||||
(DIGEST_Update*)&SHA384_Update, (DIGEST_End*)&SHA384_End, | (DIGEST_Update*)&SHA384_Update, (DIGEST_End*)&SHA384_End, | ||||
&SHA384_Data, &SHA384_File }, | &SHA384_Data, &SHA384_File }, | ||||
{ "sha512", "SHA512", &SHA512_TestOutput, (DIGEST_Init*)&SHA512_Init, | { "sha512", "SHA512", &SHA512_TestOutput, (DIGEST_Init*)&SHA512_Init, | ||||
(DIGEST_Update*)&SHA512_Update, (DIGEST_End*)&SHA512_End, | (DIGEST_Update*)&SHA512_Update, (DIGEST_End*)&SHA512_End, | ||||
&SHA512_Data, &SHA512_File }, | &SHA512_Data, &SHA512_File }, | ||||
{ "sha512t256", "SHA512t256", &SHA512t256_TestOutput, (DIGEST_Init*)&SHA512_256_Init, | { "sha512t256", "SHA512t256", &SHA512t256_TestOutput, (DIGEST_Init*)&SHA512_256_Init, | ||||
(DIGEST_Update*)&SHA512_256_Update, (DIGEST_End*)&SHA512_256_End, | (DIGEST_Update*)&SHA512_256_Update, (DIGEST_End*)&SHA512_256_End, | ||||
&SHA512_256_Data, &SHA512_256_File }, | &SHA512_256_Data, &SHA512_256_File }, | ||||
{ "rmd160", "RMD160", &RIPEMD160_TestOutput, | { "rmd160", "RMD160", &RIPEMD160_TestOutput, | ||||
(DIGEST_Init*)&RIPEMD160_Init, (DIGEST_Update*)&RIPEMD160_Update, | (DIGEST_Init*)&RIPEMD160_Init, (DIGEST_Update*)&RIPEMD160_Update, | ||||
(DIGEST_End*)&RIPEMD160_End, &RIPEMD160_Data, &RIPEMD160_File } | (DIGEST_End*)&RIPEMD160_End, &RIPEMD160_Data, &RIPEMD160_File }, | ||||
{ "skein256", "Skein256", &SKEIN256_TestOutput, | |||||
(DIGEST_Init*)&SKEIN256_Init, (DIGEST_Update*)&SKEIN256_Update, | |||||
(DIGEST_End*)&SKEIN256_End, &SKEIN256_Data, &SKEIN256_File }, | |||||
{ "skein512", "Skein512", &SKEIN512_TestOutput, | |||||
(DIGEST_Init*)&SKEIN512_Init, (DIGEST_Update*)&SKEIN512_Update, | |||||
(DIGEST_End*)&SKEIN512_End, &SKEIN512_Data, &SKEIN512_File }, | |||||
{ "skein1024", "Skein1024", &SKEIN1024_TestOutput, | |||||
(DIGEST_Init*)&SKEIN1024_Init, (DIGEST_Update*)&SKEIN1024_Update, | |||||
(DIGEST_End*)&SKEIN1024_End, &SKEIN1024_Data, &SKEIN1024_File } | |||||
}; | }; | ||||
static void | static void | ||||
MD5_Update(MD5_CTX *c, const unsigned char *data, size_t len) | MD5_Update(MD5_CTX *c, const unsigned char *data, size_t len) | ||||
{ | { | ||||
MD5Update(c, data, len); | MD5Update(c, data, len); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | MDTimeTrial(const Algorithm_t *alg) | ||||
/* Stop timer */ | /* Stop timer */ | ||||
getrusage(RUSAGE_SELF, &after); | getrusage(RUSAGE_SELF, &after); | ||||
timersub(&after.ru_utime, &before.ru_utime, &total); | timersub(&after.ru_utime, &before.ru_utime, &total); | ||||
seconds = total.tv_sec + (float) total.tv_usec / 1000000; | seconds = total.tv_sec + (float) total.tv_usec / 1000000; | ||||
printf(" done\n"); | printf(" done\n"); | ||||
printf("Digest = %s", p); | printf("Digest = %s", p); | ||||
printf("\nTime = %f seconds\n", seconds); | printf("\nTime = %f seconds\n", seconds); | ||||
printf("Speed = %f bytes/second\n", | printf("Speed = %f MiB/second\n", (float) TEST_BLOCK_LEN * | ||||
(float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds); | (float) TEST_BLOCK_COUNT / seconds / (1 << 20)); | ||||
cem: Why'd you revert this? | |||||
Not Done Inline ActionsI didn't know if it was a good idea to change the output of all of the hashing commands. Do you think it is ok to change it to the more readable format? allanjude: I didn't know if it was a good idea to change the output of all of the hashing commands.
I… | |||||
Not Done Inline ActionsI don't think anything should depend on it... but now's the time to "break" it anyway, before 11 freezes. cem: I don't think anything should depend on it... but now's the time to "break" it anyway, before… | |||||
} | } | ||||
/* | /* | ||||
* Digests a reference suite of strings and prints the results. | * Digests a reference suite of strings and prints the results. | ||||
*/ | */ | ||||
static const char *MDTestInput[MDTESTCOUNT] = { | static const char *MDTestInput[MDTESTCOUNT] = { | ||||
"", | "", | ||||
"a", | "a", | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | const char *RIPEMD160_TestOutput[MDTESTCOUNT] = { | ||||
"9c1185a5c5e9fc54612808977ee8f548b2258d31", | "9c1185a5c5e9fc54612808977ee8f548b2258d31", | ||||
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", | "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", | ||||
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", | "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", | ||||
"5d0689ef49d2fae572b881b123a85ffa21595f36", | "5d0689ef49d2fae572b881b123a85ffa21595f36", | ||||
"f71c27109c692c1b56bbdceb5b9d2865b3708dbc", | "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", | ||||
"b0e20b6e3116640286ed3a87a5713079b21f5189", | "b0e20b6e3116640286ed3a87a5713079b21f5189", | ||||
"9b752e45573d4b39f4dbd3323cab82bf63326bfb", | "9b752e45573d4b39f4dbd3323cab82bf63326bfb", | ||||
"5feb69c6bf7c29d95715ad55f57d8ac5b2b7dd32" | "5feb69c6bf7c29d95715ad55f57d8ac5b2b7dd32" | ||||
}; | |||||
const char *SKEIN256_TestOutput[MDTESTCOUNT] = { | |||||
"c8877087da56e072870daa843f176e9453115929094c3a40c463a196c29bf7ba", | |||||
"7fba44ff1a31d71a0c1f82e6e82fb5e9ac6c92a39c9185b9951fed82d82fe635", | |||||
"258bdec343b9fde1639221a5ae0144a96e552e5288753c5fec76c05fc2fc1870", | |||||
"4d2ce0062b5eb3a4db95bc1117dd8aa014f6cd50fdc8e64f31f7d41f9231e488", | |||||
"46d8440685461b00e3ddb891b2ecc6855287d2bd8834a95fb1c1708b00ea5e82", | |||||
"7c5eb606389556b33d34eb2536459528dc0af97adbcd0ce273aeb650f598d4b2", | |||||
"4def7a7e5464a140ae9c3a80279fbebce4bd00f9faad819ab7e001512f67a10d", | |||||
"d9c017dbe355f318d036469eb9b5fbe129fc2b5786a9dc6746a516eab6fe0126" | |||||
}; | |||||
const char *SKEIN512_TestOutput[MDTESTCOUNT] = { | |||||
"bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af41fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a", | |||||
"b1cd8d33f61b3737adfd59bb13ad82f4a9548e92f22956a8976cca3fdb7fee4fe91698146c4197cec85d38b83c5d93bdba92c01fd9a53870d0c7f967bc62bdce", | |||||
"8f5dd9ec798152668e35129496b029a960c9a9b88662f7f9482f110b31f9f93893ecfb25c009baad9e46737197d5630379816a886aa05526d3a70df272d96e75", | |||||
"15b73c158ffb875fed4d72801ded0794c720b121c0c78edf45f900937e6933d9e21a3a984206933d504b5dbb2368000411477ee1b204c986068df77886542fcc", | |||||
"23793ad900ef12f9165c8080da6fdfd2c8354a2929b8aadf83aa82a3c6470342f57cf8c035ec0d97429b626c4d94f28632c8f5134fd367dca5cf293d2ec13f8c", | |||||
"0c6bed927e022f5ddcf81877d42e5f75798a9f8fd3ede3d83baac0a2f364b082e036c11af35fe478745459dd8f5c0b73efe3c56ba5bb2009208d5a29cc6e469c", | |||||
"2ca9fcffb3456f297d1b5f407014ecb856f0baac8eb540f534b1f187196f21e88f31103128c2f03fcc9857d7a58eb66f9525e2302d88833ee069295537a434ce", | |||||
"1131f2aaa0e97126c9314f9f968cc827259bbfabced2943bb8c9274448998fb3b78738b4580dd500c76105fd3c03e465e1414f2c29664286b1f79d3e51128125" | |||||
}; | |||||
const char *SKEIN1024_TestOutput[MDTESTCOUNT] = { | |||||
"0fff9563bb3279289227ac77d319b6fff8d7e9f09da1247b72a0a265cd6d2a62645ad547ed8193db48cff847c06494a03f55666d3b47eb4c20456c9373c86297d630d5578ebd34cb40991578f9f52b18003efa35d3da6553ff35db91b81ab890bec1b189b7f52cb2a783ebb7d823d725b0b4a71f6824e88f68f982eefc6d19c6", | |||||
"6ab4c4ba9814a3d976ec8bffa7fcc638ceba0544a97b3c98411323ffd2dc936315d13dc93c13c4e88cda6f5bac6f2558b2d8694d3b6143e40d644ae43ca940685cb37f809d3d0550c56cba8036dee729a4f8fb960732e59e64d57f7f7710f8670963cdcdc95b41daab4855fcf8b6762a64b173ee61343a2c7689af1d293eba97", | |||||
"35a599a0f91abcdb4cb73c19b8cb8d947742d82c309137a7caed29e8e0a2ca7a9ff9a90c34c1908cc7e7fd99bb15032fb86e76df21b72628399b5f7c3cc209d7bb31c99cd4e19465622a049afbb87c03b5ce3888d17e6e667279ec0aa9b3e2712624c01b5f5bbe1a564220bdcf6990af0c2539019f313fdd7406cca3892a1f1f", | |||||
"ea891f5268acd0fac97467fc1aa89d1ce8681a9992a42540e53babee861483110c2d16f49e73bac27653ff173003e40cfb08516cd34262e6af95a5d8645c9c1abb3e813604d508b8511b30f9a5c1b352aa0791c7d2f27b2706dccea54bc7de6555b5202351751c3299f97c09cf89c40f67187e2521c0fad82b30edbb224f0458", | |||||
"f23d95c2a25fbcd0e797cd058fec39d3c52d2b5afd7a9af1df934e63257d1d3dcf3246e7329c0f1104c1e51e3d22e300507b0c3b9f985bb1f645ef49835080536becf83788e17fed09c9982ba65c3cb7ffe6a5f745b911c506962adf226e435c42f6f6bc08d288f9c810e807e3216ef444f3db22744441deefa4900982a1371f", | |||||
"cf3889e8a8d11bfd3938055d7d061437962bc5eac8ae83b1b71c94be201b8cf657fdbfc38674997a008c0c903f56a23feb3ae30e012377f1cfa080a9ca7fe8b96138662653fb3335c7d06595bf8baf65e215307532094cfdfa056bd8052ab792a3944a2adaa47b30335b8badb8fe9eb94fe329cdca04e58bbc530f0af709f469", | |||||
"cf21a613620e6c119eca31fdfaad449a8e02f95ca256c21d2a105f8e4157048f9fe1e897893ea18b64e0e37cb07d5ac947f27ba544caf7cbc1ad094e675aed77a366270f7eb7f46543bccfa61c526fd628408058ed00ed566ac35a9761d002e629c4fb0d430b2f4ad016fcc49c44d2981c4002da0eecc42144160e2eaea4855a", | |||||
"e6799b78db54085a2be7ff4c8007f147fa88d326abab30be0560b953396d8802feee9a15419b48a467574e9283be15685ca8a079ee52b27166b64dd70b124b1d4e4f6aca37224c3f2685e67e67baef9f94b905698adc794a09672aba977a61b20966912acdb08c21a2c37001785355dc884751a21f848ab36e590331ff938138" | |||||
}; | }; | ||||
static void | static void | ||||
MDTestSuite(const Algorithm_t *alg) | MDTestSuite(const Algorithm_t *alg) | ||||
{ | { | ||||
int i; | int i; | ||||
char buffer[HEX_DIGEST_LENGTH]; | char buffer[HEX_DIGEST_LENGTH]; | ||||
Show All 38 Lines |
Why'd you revert this?