From 39daa5234a3438a5af3eae147c929dea44beb3b5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Wed, 3 Feb 2010 19:13:04 +0100 Subject: [PATCH] Implement SHA-224 and SHA-384 hashes --- src/crypto.c | 2 ++ src/isds.c | 4 ++++ src/isds.h | 2 ++ test/compute_hash.c | 26 ++++++++++++++++++++++++++ test/isds-hash_algorithm.c | 4 ++++ 5 files changed, 38 insertions(+) diff --git a/src/crypto.c b/src/crypto.c index 37087af..4753988 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -59,7 +59,9 @@ _hidden isds_error compute_hash(const void *input, const size_t length, switch (hash->algorithm) { case HASH_ALGORITHM_MD5: g_algorithm = GCRY_MD_MD5; break; case HASH_ALGORITHM_SHA_1: g_algorithm = GCRY_MD_SHA1; break; + case HASH_ALGORITHM_SHA_224: g_algorithm = GCRY_MD_SHA224; break; case HASH_ALGORITHM_SHA_256: g_algorithm = GCRY_MD_SHA256; break; + case HASH_ALGORITHM_SHA_384: g_algorithm = GCRY_MD_SHA384; break; case HASH_ALGORITHM_SHA_512: g_algorithm = GCRY_MD_SHA512; break; default: return IE_NOTSUP; } diff --git a/src/isds.c b/src/isds.c index 2418c92..2baea48 100644 --- a/src/isds.c +++ b/src/isds.c @@ -1483,8 +1483,12 @@ static isds_error string2isds_hash_algorithm(const xmlChar *string, *algorithm = HASH_ALGORITHM_MD5; else if (!xmlStrcmp(string, BAD_CAST "SHA-1")) *algorithm = HASH_ALGORITHM_SHA_1; + else if (!xmlStrcmp(string, BAD_CAST "SHA-224")) + *algorithm = HASH_ALGORITHM_SHA_224; else if (!xmlStrcmp(string, BAD_CAST "SHA-256")) *algorithm = HASH_ALGORITHM_SHA_256; + else if (!xmlStrcmp(string, BAD_CAST "SHA-384")) + *algorithm = HASH_ALGORITHM_SHA_384; else if (!xmlStrcmp(string, BAD_CAST "SHA-512")) *algorithm = HASH_ALGORITHM_SHA_512; else diff --git a/src/isds.h b/src/isds.h index 16fcf65..ac3f5e6 100644 --- a/src/isds.h +++ b/src/isds.h @@ -148,7 +148,9 @@ typedef enum { typedef enum { HASH_ALGORITHM_MD5, HASH_ALGORITHM_SHA_1, + HASH_ALGORITHM_SHA_224, HASH_ALGORITHM_SHA_256, + HASH_ALGORITHM_SHA_384, HASH_ALGORITHM_SHA_512, } isds_hash_algorithm; diff --git a/test/compute_hash.c b/test/compute_hash.c index 06e8252..7f76d11 100644 --- a/test/compute_hash.c +++ b/test/compute_hash.c @@ -86,6 +86,18 @@ int main(int argc, char **argv) { TEST("MD5", test_compute_hash, IE_SUCCESS, &correct, &test, input, sizeof(input)); + correct.algorithm = HASH_ALGORITHM_SHA_224; + correct.length = 28; + correct.value = (uint8_t[]) { + 0x58, 0x8d, 0x39, 0xd2, 0x1a, 0x1f, 0xef, 0x0b, + 0x89, 0xdf, 0x62, 0x1b, 0x3e, 0xb1, 0x41, 0x62, + 0x70, 0x22, 0xe5, 0x8f, 0xe9, 0x25, 0x83, 0x06, + 0x73, 0xcb, 0x2b, 0x03 + }; + test.algorithm = HASH_ALGORITHM_SHA_224; + TEST("SHA-224", test_compute_hash, IE_SUCCESS, &correct, &test, input, + sizeof(input)); + correct.algorithm = HASH_ALGORITHM_SHA_256; correct.length = 32; correct.value = (uint8_t[]) { @@ -98,6 +110,20 @@ int main(int argc, char **argv) { TEST("SHA-256", test_compute_hash, IE_SUCCESS, &correct, &test, input, sizeof(input)); + correct.algorithm = HASH_ALGORITHM_SHA_384; + correct.length = 48; + correct.value = (uint8_t[]) { + 0x81, 0x2b, 0x94, 0x0b, 0x9c, 0x58, 0x60, 0x31, + 0xb8, 0x20, 0x4b, 0xa7, 0xf1, 0x96, 0xdb, 0x5b, + 0xfe, 0x55, 0xec, 0x87, 0x33, 0x92, 0x78, 0x5a, + 0x78, 0x0a, 0x38, 0xe4, 0xaa, 0x9e, 0xe0, 0x4d, + 0x0b, 0xbe, 0x55, 0x43, 0x2c, 0x9a, 0x85, 0x29, + 0xb4, 0x8d, 0x6b, 0x6f, 0xea, 0xd1, 0x95, 0xa8 + }; + test.algorithm = HASH_ALGORITHM_SHA_384; + TEST("SHA-384", test_compute_hash, IE_SUCCESS, &correct, &test, input, + sizeof(input)); + correct.algorithm = HASH_ALGORITHM_SHA_512; correct.length = 64; correct.value = (uint8_t[]) { diff --git a/test/isds-hash_algorithm.c b/test/isds-hash_algorithm.c index 1d1bb81..22d8659 100644 --- a/test/isds-hash_algorithm.c +++ b/test/isds-hash_algorithm.c @@ -25,14 +25,18 @@ int main(int argc, char **argv) { xmlChar *names[] = { BAD_CAST "MD5", BAD_CAST "SHA-1", + BAD_CAST "SHA-224", BAD_CAST "SHA-256", + BAD_CAST "SHA-384", BAD_CAST "SHA-512" }; isds_hash_algorithm algos[] = { HASH_ALGORITHM_MD5, HASH_ALGORITHM_SHA_1, + HASH_ALGORITHM_SHA_224, HASH_ALGORITHM_SHA_256, + HASH_ALGORITHM_SHA_384, HASH_ALGORITHM_SHA_512, }; -- 2.11.4.GIT