SHA512 support
authorLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Sep 2010 06:37:34 +0000 (23:37 -0700)
committerLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Sep 2010 06:41:15 +0000 (23:41 -0700)
lib/hcrypto/Makefile.am
lib/hcrypto/evp-hcrypto.c
lib/hcrypto/evp-hcrypto.h
lib/hcrypto/evp.c
lib/hcrypto/evp.h
lib/hcrypto/hash.h
lib/hcrypto/libhcrypto-exports.def
lib/hcrypto/mdtest.c
lib/hcrypto/sha.h
lib/hcrypto/version-script.map

index f119d8c88d5a050494421d0f2ac27a88b1a9d3d0..a2a213279d01f7446b52a846b858110e2693411c 100644 (file)
@@ -154,6 +154,7 @@ libhcrypto_la_SOURCES =     \
        sha.c           \
        sha.h           \
        sha256.c        \
+       sha512.c        \
        validate.c      \
        ui.c            \
        ui.h
index 9e063545e168342462156568b95de987be53e3ba..7075c0fdd4e9e6712b5df82c6f9b0370de3b77ab 100644 (file)
@@ -289,6 +289,29 @@ EVP_hcrypto_sha256(void)
     return &sha256;
 }
 
+/**
+ * The message digest SHA256 - hcrypto
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
+const EVP_MD *
+EVP_hcrypto_sha512(void)
+{
+    static const struct hc_evp_md sha512 = {
+       64,
+       128,
+       sizeof(SHA512_CTX),
+       (hc_evp_md_init)SHA512_Init,
+       (hc_evp_md_update)SHA512_Update,
+       (hc_evp_md_final)SHA512_Final,
+       NULL
+    };
+    return &sha512;
+}
+
 /**
  * The message digest SHA1 - hcrypto
  *
index 7915046bdcea12852c8fc67585e20f79cf225055..df82c227b320d318977d28a960e35125b10249ad 100644 (file)
@@ -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_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
 #define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc
@@ -70,6 +71,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_sha512(void);
 
 const EVP_CIPHER * EVP_hcrypto_rc4(void);
 const EVP_CIPHER * EVP_hcrypto_rc4_40(void);
index da1a8940be865962f20a75b18832c436d9d932c0..e28691598fcbed4c5107c409ff1051f38e95bef6 100644 (file)
@@ -360,6 +360,13 @@ EVP_sha256(void)
     return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha256);
 }
 
+const EVP_MD *
+EVP_sha512(void)
+{
+    hcrypto_validate();
+    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha512);
+}
+
 /**
  * The message digest SHA1
  *
index 03ec175d5976784eaa7774d76bf9b5d8b221f308..b60d5586f47eab0d87c644694b22ec69dd41af99 100644 (file)
@@ -96,6 +96,7 @@
 #define EVP_sha hc_EVP_sha
 #define EVP_sha1 hc_EVP_sha1
 #define EVP_sha256 hc_EVP_sha256
+#define EVP_sha512 hc_EVP_sha512
 #define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1
 #define EVP_BytesToKey hc_EVP_BytesToKey
 #define EVP_get_cipherbyname hc_EVP_get_cipherbyname
@@ -225,6 +226,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_sha512(void);
 
 const EVP_CIPHER * EVP_aes_128_cbc(void);
 const EVP_CIPHER * EVP_aes_192_cbc(void);
index cfec9cf3f34deffa27b6282c3386376a0b4d145e..498e5b1af01ccbff67f138f63604950954c0a11f 100644 (file)
@@ -66,4 +66,10 @@ cshift (uint32_t x, unsigned int n)
     return CRAYFIX((x << n) | (x >> (32 - n)));
 }
 
+static inline uint64_t
+cshift64 (uint64_t x, unsigned int n)
+{
+  return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n));
+}
+
 #endif /* __hash_h__ */
index 440acfea3053e4fd0ad66fd66915b8abcc5fdf57..8fa083442982b0af73c1cdb0b299dfcbfb9f16b3 100644 (file)
@@ -160,6 +160,7 @@ EXPORTS
        hc_EVP_sha
        hc_EVP_sha1
        hc_EVP_sha256
+       hc_EVP_sha512
 
 ;!     hc_EVP_cc_md2
 ;!     hc_EVP_cc_md4
index d67c04a6bd68ffe8e409cedddad0285c4fdbb2dc..9f474c712ff8b448c11f2ceaa39404f38e18a290 100644 (file)
@@ -104,23 +104,22 @@ struct hash_foo sha256 = {
 #ifdef HAVE_SHA384
 struct hash_foo sha384 = {
     "SHA-384",
-    sizeof(struct sha512),
+    sizeof(SHA384_CTX),
     48,
     (void (*)(void*))SHA384_Init,
     (void (*)(void*,const void*, size_t))SHA384_Update,
     (void (*)(void*, void*))SHA384_Final
 };
 #endif
-#ifdef HAVE_SHA512
 struct hash_foo sha512 = {
     "SHA-512",
-    sizeof(struct sha512),
+    sizeof(SHA512_CTX),
     64,
     (void (*)(void*))SHA512_Init,
     (void (*)(void*,const void*, size_t))SHA512_Update,
-    (void (*)(void*, void*))SHA512_Final
+    (void (*)(void*, void*))SHA512_Final,
+    EVP_sha512
 };
-#endif
 
 struct test {
     char *str;
@@ -235,7 +234,7 @@ struct test sha384_tests[] = {
     {NULL}
 };
 #endif
-#ifdef HAVE_SHA512
+
 struct test sha512_tests[] = {
     { "abc",
       { 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
@@ -267,7 +266,6 @@ struct test sha512_tests[] = {
        0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b }},
     { NULL }
 };
-#endif
 
 static int
 hash_test (struct hash_foo *hash, struct test *tests)
@@ -351,8 +349,5 @@ main (void)
 #ifdef HAVE_SHA384
        + hash_test(&sha384, sha384_tests)
 #endif
-#ifdef HAVE_SHA512
-       + hash_test(&sha512, sha512_tests)
-#endif
-       ;
+       + hash_test(&sha512, sha512_tests);
 }
index 39e33cf8d0ade341778f9f42b677381e821d47a6..cefe7dca0253f34a90cccc4df189b8d7c3fc2a3e 100644 (file)
@@ -80,4 +80,22 @@ void SHA256_Init (SHA256_CTX *);
 void SHA256_Update (SHA256_CTX *, const void *, size_t);
 void SHA256_Final (void *, SHA256_CTX *);
 
+/*
+ * SHA-2 512
+ */
+
+#define SHA512_DIGEST_LENGTH 64
+
+struct hc_sha512state {
+  uint64_t sz[2];
+  uint64_t counter[8];
+  unsigned char save[128];
+};
+
+typedef struct hc_sha512state SHA512_CTX;
+
+void SHA512_Init (SHA512_CTX *);
+void SHA512_Update (SHA512_CTX *, const void *, size_t);
+void SHA512_Final (void *, SHA512_CTX *);
+
 #endif /* HEIM_SHA_H */
index fad05683e53709fcbd6f8e8422b05b8d02e42fea..2c6afc45122c6ad9d248c3c0fc8bc46092866b27 100644 (file)
@@ -167,6 +167,7 @@ HEIMDAL_CRYPTO_1.0 {
                hc_EVP_sha;
                hc_EVP_sha1;
                hc_EVP_sha256;
+               hc_EVP_sha512;
 
                hc_EVP_cc_md2;
                hc_EVP_cc_md4;
@@ -186,6 +187,7 @@ HEIMDAL_CRYPTO_1.0 {
                hc_EVP_hcrypto_md5;
                hc_EVP_hcrypto_sha1;
                hc_EVP_hcrypto_sha256;
+               hc_EVP_hcrypto_sha512;
                hc_EVP_hcrypto_des_ede3_cbc;
                hc_EVP_hcrypto_aes_128_cbc;
                hc_EVP_hcrypto_aes_192_cbc;