From c2e4377cc236513375c0c1d7965e688b14449c77 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Thu, 30 Sep 2010 18:22:00 -0700 Subject: [PATCH] SHA384 --- lib/hcrypto/evp-hcrypto.c | 25 ++++++++++++++++++++++++- lib/hcrypto/evp-hcrypto.h | 2 ++ lib/hcrypto/evp.c | 23 +++++++++++++++++++++++ lib/hcrypto/evp.h | 2 ++ lib/hcrypto/libhcrypto-exports.def | 1 + lib/hcrypto/mdtest.c | 17 ++++++----------- lib/hcrypto/sha.h | 8 ++++++++ lib/hcrypto/sha512.c | 30 ++++++++++++++++++++++++++++++ lib/hcrypto/version-script.map | 2 ++ 9 files changed, 98 insertions(+), 12 deletions(-) diff --git a/lib/hcrypto/evp-hcrypto.c b/lib/hcrypto/evp-hcrypto.c index 7075c0fdd..bf37b42ed 100644 --- a/lib/hcrypto/evp-hcrypto.c +++ b/lib/hcrypto/evp-hcrypto.c @@ -290,7 +290,30 @@ EVP_hcrypto_sha256(void) } /** - * The message digest SHA256 - hcrypto + * The message digest SHA384 - hcrypto + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_hcrypto_sha384(void) +{ + static const struct hc_evp_md sha384 = { + 48, + 128, + sizeof(SHA384_CTX), + (hc_evp_md_init)SHA384_Init, + (hc_evp_md_update)SHA384_Update, + (hc_evp_md_final)SHA384_Final, + NULL + }; + return &sha384; +} + +/** + * The message digest SHA512 - hcrypto * * @return the message digest type. * diff --git a/lib/hcrypto/evp-hcrypto.h b/lib/hcrypto/evp-hcrypto.h index df82c227b..b7876c67c 100644 --- a/lib/hcrypto/evp-hcrypto.h +++ b/lib/hcrypto/evp-hcrypto.h @@ -42,6 +42,7 @@ #define EVP_hcrypto_md5 hc_EVP_hcrypto_md5 #define EVP_hcrypto_sha1 hc_EVP_hcrypto_sha1 #define EVP_hcrypto_sha256 hc_EVP_hcrypto_sha256 +#define EVP_hcrypto_sha384 hc_EVP_hcrypto_sha384 #define EVP_hcrypto_sha512 hc_EVP_hcrypto_sha512 #define EVP_hcrypto_des_cbc hc_EVP_hcrypto_des_cbc #define EVP_hcrypto_des_ede3_cbc hc_EVP_hcrypto_des_ede3_cbc @@ -71,6 +72,7 @@ const EVP_MD * EVP_hcrypto_md4(void); const EVP_MD * EVP_hcrypto_md5(void); const EVP_MD * EVP_hcrypto_sha1(void); const EVP_MD * EVP_hcrypto_sha256(void); +const EVP_MD * EVP_hcrypto_sha384(void); const EVP_MD * EVP_hcrypto_sha512(void); const EVP_CIPHER * EVP_hcrypto_rc4(void); diff --git a/lib/hcrypto/evp.c b/lib/hcrypto/evp.c index e28691598..7bd066fd5 100644 --- a/lib/hcrypto/evp.c +++ b/lib/hcrypto/evp.c @@ -360,6 +360,29 @@ EVP_sha256(void) return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha256); } +/** + * The message digest SHA384 + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_sha384(void) +{ + hcrypto_validate(); + return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha384); +} + +/** + * The message digest SHA512 + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + const EVP_MD * EVP_sha512(void) { diff --git a/lib/hcrypto/evp.h b/lib/hcrypto/evp.h index b60d5586f..c56eedec4 100644 --- a/lib/hcrypto/evp.h +++ b/lib/hcrypto/evp.h @@ -96,6 +96,7 @@ #define EVP_sha hc_EVP_sha #define EVP_sha1 hc_EVP_sha1 #define EVP_sha256 hc_EVP_sha256 +#define EVP_sha384 hc_EVP_sha384 #define EVP_sha512 hc_EVP_sha512 #define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1 #define EVP_BytesToKey hc_EVP_BytesToKey @@ -226,6 +227,7 @@ HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md5(void); const EVP_MD *EVP_sha(void); const EVP_MD *EVP_sha1(void); const EVP_MD *EVP_sha256(void); +const EVP_MD *EVP_sha384(void); const EVP_MD *EVP_sha512(void); const EVP_CIPHER * EVP_aes_128_cbc(void); diff --git a/lib/hcrypto/libhcrypto-exports.def b/lib/hcrypto/libhcrypto-exports.def index 8fa083442..f2b5beedd 100644 --- a/lib/hcrypto/libhcrypto-exports.def +++ b/lib/hcrypto/libhcrypto-exports.def @@ -160,6 +160,7 @@ EXPORTS hc_EVP_sha hc_EVP_sha1 hc_EVP_sha256 + hc_EVP_sha384 hc_EVP_sha512 ;! hc_EVP_cc_md2 diff --git a/lib/hcrypto/mdtest.c b/lib/hcrypto/mdtest.c index 9f474c712..fd90ee73a 100644 --- a/lib/hcrypto/mdtest.c +++ b/lib/hcrypto/mdtest.c @@ -101,16 +101,15 @@ struct hash_foo sha256 = { (void (*)(void*, void*))SHA256_Final, EVP_sha256 }; -#ifdef HAVE_SHA384 struct hash_foo sha384 = { "SHA-384", sizeof(SHA384_CTX), 48, (void (*)(void*))SHA384_Init, (void (*)(void*,const void*, size_t))SHA384_Update, - (void (*)(void*, void*))SHA384_Final + (void (*)(void*, void*))SHA384_Final, + EVP_sha384 }; -#endif struct hash_foo sha512 = { "SHA-512", sizeof(SHA512_CTX), @@ -207,7 +206,6 @@ struct test sha256_tests[] = { { NULL } }; -#ifdef HAVE_SHA384 struct test sha384_tests[] = { { "abc", { 0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b, @@ -233,7 +231,6 @@ struct test sha384_tests[] = { 0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85}}, {NULL} }; -#endif struct test sha512_tests[] = { { "abc", @@ -344,10 +341,8 @@ main (void) hash_test(&md2, md2_tests) + hash_test(&md4, md4_tests) + hash_test(&md5, md5_tests) + - hash_test(&sha1, sha1_tests) - + hash_test(&sha256, sha256_tests) -#ifdef HAVE_SHA384 - + hash_test(&sha384, sha384_tests) -#endif - + hash_test(&sha512, sha512_tests); + hash_test(&sha1, sha1_tests) + + hash_test(&sha256, sha256_tests) + + hash_test(&sha384, sha384_tests) + + hash_test(&sha512, sha512_tests); } diff --git a/lib/hcrypto/sha.h b/lib/hcrypto/sha.h index cefe7dca0..a1f5a9931 100644 --- a/lib/hcrypto/sha.h +++ b/lib/hcrypto/sha.h @@ -98,4 +98,12 @@ void SHA512_Init (SHA512_CTX *); void SHA512_Update (SHA512_CTX *, const void *, size_t); void SHA512_Final (void *, SHA512_CTX *); +#define SHA384_DIGEST_LENGTH 48 + +typedef struct hc_sha512state SHA384_CTX; + +void SHA384_Init (SHA384_CTX *); +void SHA384_Update (SHA384_CTX *, const void *, size_t); +void SHA384_Final (void *, SHA384_CTX *); + #endif /* HEIM_SHA_H */ diff --git a/lib/hcrypto/sha512.c b/lib/hcrypto/sha512.c index 66c86d16d..18447b6c6 100644 --- a/lib/hcrypto/sha512.c +++ b/lib/hcrypto/sha512.c @@ -242,3 +242,33 @@ SHA512_Final (void *res, SHA512_CTX *m) } } } + +void +SHA384_Init(SHA384_CTX *m) +{ + m->sz[0] = 0; + m->sz[1] = 0; + A = 0xcbbb9d5dc1059ed8; + B = 0x629a292a367cd507; + C = 0x9159015a3070dd17; + D = 0x152fecd8f70e5939; + E = 0x67332667ffc00b31; + F = 0x8eb44a8768581511; + G = 0xdb0c2e0d64f98fa7; + H = 0x47b5481dbefa4fa4; +} + +void +SHA384_Update (SHA384_CTX *m, const void *v, size_t len) +{ + SHA512_Update(m, v, len); +} + +void +SHA384_Final (void *res, SHA384_CTX *m) +{ + unsigned char data[SHA512_DIGEST_LENGTH]; + SHA512_Final(data, m); + memcpy(res, data, SHA384_DIGEST_LENGTH); +} + diff --git a/lib/hcrypto/version-script.map b/lib/hcrypto/version-script.map index 2c6afc451..0cde14fe6 100644 --- a/lib/hcrypto/version-script.map +++ b/lib/hcrypto/version-script.map @@ -167,6 +167,7 @@ HEIMDAL_CRYPTO_1.0 { hc_EVP_sha; hc_EVP_sha1; hc_EVP_sha256; + hc_EVP_sha384; hc_EVP_sha512; hc_EVP_cc_md2; @@ -187,6 +188,7 @@ HEIMDAL_CRYPTO_1.0 { hc_EVP_hcrypto_md5; hc_EVP_hcrypto_sha1; hc_EVP_hcrypto_sha256; + hc_EVP_hcrypto_sha384; hc_EVP_hcrypto_sha512; hc_EVP_hcrypto_des_ede3_cbc; hc_EVP_hcrypto_aes_128_cbc; -- 2.11.4.GIT