summaryrefslogtreecommitdiff
path: root/ext/digest/sha2/sha2.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:21:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:21:22 +0000
commite6dde8be4d2538464372fd0c7499d625239a3b08 (patch)
tree3e4441f09c6aa5655877a9cb4f6258d6d0d39f4f /ext/digest/sha2/sha2.h
parent034acb5806a718e3ec361af43b902c1ec3591ff3 (diff)
* ext/digest/sha2: Use OpenSSL's SHA1 engine if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/sha2/sha2.h')
-rw-r--r--ext/digest/sha2/sha2.h83
1 files changed, 27 insertions, 56 deletions
diff --git a/ext/digest/sha2/sha2.h b/ext/digest/sha2/sha2.h
index 3536b31..1231de5 100644
--- a/ext/digest/sha2/sha2.h
+++ b/ext/digest/sha2/sha2.h
@@ -91,11 +91,18 @@ extern "C" {
* uintXX_t (from inttypes.h), you may need to define things by hand
* for your system:
*/
-#if 0
-typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
-typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
-typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
+#ifndef SHA2_USE_INTTYPES_H
+# ifdef HAVE_U_INT8_T
+typedef u_int8_t uint8_t; /* 1-byte (8-bits) */
+typedef u_int32_t uint32_t; /* 4-bytes (32-bits) */
+typedef u_int64_t uint64_t; /* 8-bytes (64-bits) */
+# else
+typedef unsigned char uint8_t; /* 1-byte (8-bits) */
+typedef unsigned int uint32_t; /* 4-bytes (32-bits) */
+typedef unsigned long long uint64_t; /* 8-bytes (64-bits) */
+# endif
#endif
+
/*
* Most BSD systems already define u_intXX_t types, as does Linux.
* Some systems, however, like Compaq's Tru64 Unix instead can use
@@ -112,8 +119,6 @@ typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
*
* cc -DSHA2_USE_INTTYPES_H ...
*/
-#ifdef SHA2_USE_INTTYPES_H
-
typedef struct _SHA256_CTX {
uint32_t state[8];
uint64_t bitcount;
@@ -125,21 +130,6 @@ typedef struct _SHA512_CTX {
uint8_t buffer[SHA512_BLOCK_LENGTH];
} SHA512_CTX;
-#else /* SHA2_USE_INTTYPES_H */
-
-typedef struct _SHA256_CTX {
- u_int32_t state[8];
- u_int64_t bitcount;
- u_int8_t buffer[SHA256_BLOCK_LENGTH];
-} SHA256_CTX;
-typedef struct _SHA512_CTX {
- u_int64_t state[8];
- u_int64_t bitcount[2];
- u_int8_t buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
-
-#endif /* SHA2_USE_INTTYPES_H */
-
typedef SHA512_CTX SHA384_CTX;
@@ -148,70 +138,51 @@ typedef SHA512_CTX SHA384_CTX;
#define SHA256_Init rb_Digest_SHA256_Init
#define SHA256_Update rb_Digest_SHA256_Update
#define SHA256_Finish rb_Digest_SHA256_Finish
+#define SHA256_Data rb_Digest_SHA256_Data
+#define SHA256_End rb_Digest_SHA256_End
+#define SHA256_Last rb_Digest_SHA256_Last
+#define SHA256_Transform rb_Digest_SHA256_Transform
+#define SHA256_Final(d, c) SHA256_Finish(c, d)
#define SHA384_Init rb_Digest_SHA384_Init
#define SHA384_Update rb_Digest_SHA384_Update
#define SHA384_Finish rb_Digest_SHA384_Finish
+#define SHA384_Data rb_Digest_SHA384_Data
+#define SHA384_End rb_Digest_SHA384_End
+#define SHA384_Last rb_Digest_SHA384_Last
+#define SHA384_Transform rb_Digest_SHA384_Transform
+#define SHA384_Final(d, c) SHA384_Finish(c, d)
#define SHA512_Init rb_Digest_SHA512_Init
#define SHA512_Update rb_Digest_SHA512_Update
#define SHA512_Finish rb_Digest_SHA512_Finish
+#define SHA512_Data rb_Digest_SHA512_Data
+#define SHA512_End rb_Digest_SHA512_End
+#define SHA512_Last rb_Digest_SHA512_Last
+#define SHA512_Transform rb_Digest_SHA512_Transform
+#define SHA512_Final(d, c) SHA512_Finish(c, d)
#endif /* RUBY */
+
#ifndef NOPROTO
-#ifdef SHA2_USE_INTTYPES_H
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
-#ifdef RUBY
-void SHA256_Finish(SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH]);
-#else
void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-#endif /* RUBY */
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void SHA384_Init(SHA384_CTX*);
void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
-#ifdef RUBY
-void SHA384_Finish(SHA384_CTX*, uint8_t[SHA384_DIGEST_LENGTH]);
-#else
void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-#endif /* RUBY */
char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
void SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
-#ifdef RUBY
-void SHA512_Finish(SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]);
-#else
void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-#endif /* RUBY */
char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
-#else /* SHA2_USE_INTTYPES_H */
-
-void SHA256_Init(SHA256_CTX *);
-void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
-void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
-
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
-void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
-
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
-void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
-
-#endif /* SHA2_USE_INTTYPES_H */
-
#else /* NOPROTO */
void SHA256_Init();