summaryrefslogtreecommitdiff
path: root/Source/cm_sha2.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-11-15 20:18:58 -0500
committerBrad King <brad.king@kitware.com>2011-11-16 10:15:44 -0500
commitc1856a33d46384307884ab6ba6db886a7bca0fd2 (patch)
tree4b7ed699dbb2741d9757c776ba0bc735b6bd29d6 /Source/cm_sha2.h
parentfcc3ce5b0dc5bb8ef3447da189d04715f429d822 (diff)
downloadcmake-c1856a33d46384307884ab6ba6db886a7bca0fd2.tar.gz
sha2: Use KWIML fixed-size integer types and endian-ness
These are more portable than those named in the original sha2 code.
Diffstat (limited to 'Source/cm_sha2.h')
-rw-r--r--Source/cm_sha2.h185
1 files changed, 30 insertions, 155 deletions
diff --git a/Source/cm_sha2.h b/Source/cm_sha2.h
index 9459f759cb..284ee6ab62 100644
--- a/Source/cm_sha2.h
+++ b/Source/cm_sha2.h
@@ -36,6 +36,12 @@
#ifndef __SHA2_H__
#define __SHA2_H__
+/* CMake modification: use integer types from cmIML. */
+#include "cmIML/INT.h"
+typedef cmIML_INT_uint8_t cm_sha2_uint8_t;
+typedef cmIML_INT_uint32_t cm_sha2_uint32_t;
+typedef cmIML_INT_uint64_t cm_sha2_uint64_t;
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -48,13 +54,6 @@ extern "C" {
*/
#include <sys/types.h>
-#ifdef SHA2_USE_INTTYPES_H
-
-#include <inttypes.h>
-
-#endif /* SHA2_USE_INTTYPES_H */
-
-
/*** SHA-224/256/384/512 Various Length Definitions *******************/
/* Digest lengths for SHA-1/224/256/384/512 */
@@ -71,185 +70,61 @@ extern "C" {
/*** SHA-224/256/384/512 Context Structures ***************************/
-/* NOTE: If your architecture does not define either u_intXX_t types or
- * 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) */
-#endif
-/*
- * Most BSD systems already define u_intXX_t types, as does Linux.
- * Some systems, however, like Compaq's Tru64 Unix instead can use
- * uintXX_t types defined by very recent ANSI C standards and included
- * in the file:
- *
- * #include <inttypes.h>
- *
- * If you choose to use <inttypes.h> then please define:
- *
- * #define SHA2_USE_INTTYPES_H
- *
- * Or on the command line during compile:
- *
- * cc -DSHA2_USE_INTTYPES_H ...
- */
-#ifdef SHA2_USE_INTTYPES_H
typedef union _SHA_CTX {
/* SHA-1 uses this part of the union: */
struct {
- uint32_t state[5];
- uint64_t bitcount;
- uint8_t buffer[64];
+ cm_sha2_uint32_t state[5];
+ cm_sha2_uint64_t bitcount;
+ cm_sha2_uint8_t buffer[64];
} s1;
/* SHA-224 and SHA-256 use this part of the union: */
struct {
- uint32_t state[8];
- uint64_t bitcount;
- uint8_t buffer[64];
+ cm_sha2_uint32_t state[8];
+ cm_sha2_uint64_t bitcount;
+ cm_sha2_uint8_t buffer[64];
} s256;
/* SHA-384 and SHA-512 use this part of the union: */
struct {
- uint64_t state[8];
- uint64_t bitcount[2];
- uint8_t buffer[128];
+ cm_sha2_uint64_t state[8];
+ cm_sha2_uint64_t bitcount[2];
+ cm_sha2_uint8_t buffer[128];
} s512;
} SHA_CTX;
-#else /* SHA2_USE_INTTYPES_H */
-
-typedef union _SHA_CTX {
- /* SHA-1 uses this part of the union: */
- struct {
- u_int32_t state[5];
- u_int64_t bitcount;
- u_int8_t buffer[64];
- } s1;
-
- /* SHA-224 and SHA-256 use this part of the union: */
- struct {
- u_int32_t state[8];
- u_int64_t bitcount;
- u_int8_t buffer[64];
- } s256;
-
- /* SHA-384 and SHA-512 use this part of the union: */
- struct {
- u_int64_t state[8];
- u_int64_t bitcount[2];
- u_int8_t buffer[128];
- } s512;
-} SHA_CTX;
-
-#endif /* SHA2_USE_INTTYPES_H */
-
-
/*** SHA-256/384/512 Function Prototypes ******************************/
-#ifndef NOPROTO
-#ifdef SHA2_USE_INTTYPES_H
void SHA1_Init(SHA_CTX*);
-void SHA1_Update(SHA_CTX*, const uint8_t*, size_t);
-void SHA1_Final(uint8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
+void SHA1_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA1_Final(cm_sha2_uint8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
char* SHA1_End(SHA_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
-char* SHA1_Data(const uint8_t*, size_t, char[SHA1_DIGEST_STRING_LENGTH]);
+char* SHA1_Data(const cm_sha2_uint8_t*, size_t, char[SHA1_DIGEST_STRING_LENGTH]);
void SHA224_Init(SHA_CTX*);
-void SHA224_Update(SHA_CTX*, const uint8_t*, size_t);
-void SHA224_Final(uint8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
+void SHA224_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA224_Final(cm_sha2_uint8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
char* SHA224_End(SHA_CTX*, char[SHA224_DIGEST_STRING_LENGTH]);
-char* SHA224_Data(const uint8_t*, size_t, char[SHA224_DIGEST_STRING_LENGTH]);
+char* SHA224_Data(const cm_sha2_uint8_t*, size_t, char[SHA224_DIGEST_STRING_LENGTH]);
void SHA256_Init(SHA_CTX*);
-void SHA256_Update(SHA_CTX*, const uint8_t*, size_t);
-void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
+void SHA256_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA256_Final(cm_sha2_uint8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
char* SHA256_End(SHA_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
+char* SHA256_Data(const cm_sha2_uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void SHA384_Init(SHA_CTX*);
-void SHA384_Update(SHA_CTX*, const uint8_t*, size_t);
-void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
+void SHA384_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA384_Final(cm_sha2_uint8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
char* SHA384_End(SHA_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
+char* SHA384_Data(const cm_sha2_uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
void SHA512_Init(SHA_CTX*);
-void SHA512_Update(SHA_CTX*, const uint8_t*, size_t);
-void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
+void SHA512_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
+void SHA512_Final(cm_sha2_uint8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
char* SHA512_End(SHA_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 SHA1_Init(SHA_CTX*);
-void SHA1_Update(SHA_CTX*, const u_int8_t*, size_t);
-void SHA1_Final(u_int8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
-char* SHA1_End(SHA_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
-char* SHA1_Data(const u_int8_t*, size_t, char[SHA1_DIGEST_STRING_LENGTH]);
-
-void SHA224_Init(SHA_CTX*);
-void SHA224_Update(SHA_CTX*, const u_int8_t*, size_t);
-void SHA224_Final(u_int8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
-char* SHA224_End(SHA_CTX*, char[SHA224_DIGEST_STRING_LENGTH]);
-char* SHA224_Data(const u_int8_t*, size_t, char[SHA224_DIGEST_STRING_LENGTH]);
-
-void SHA256_Init(SHA_CTX*);
-void SHA256_Update(SHA_CTX*, const u_int8_t*, size_t);
-void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
-char* SHA256_End(SHA_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
-
-void SHA384_Init(SHA_CTX*);
-void SHA384_Update(SHA_CTX*, const u_int8_t*, size_t);
-void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
-char* SHA384_End(SHA_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
-
-void SHA512_Init(SHA_CTX*);
-void SHA512_Update(SHA_CTX*, const u_int8_t*, size_t);
-void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
-char* SHA512_End(SHA_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 SHA1_Init();
-void SHA1_Update();
-void SHA1_Final();
-char* SHA1_End();
-char* SHA1_Data();
-
-void SHA224_Init();
-void SHA224_Update();
-void SHA224_Final();
-char* SHA224_End();
-char* SHA224_Data();
-
-void SHA256_Init();
-void SHA256_Update();
-void SHA256_Final();
-char* SHA256_End();
-char* SHA256_Data();
-
-void SHA384_Init();
-void SHA384_Update();
-void SHA384_Final();
-char* SHA384_End();
-char* SHA384_Data();
-
-void SHA512_Init();
-void SHA512_Update();
-void SHA512_Final();
-char* SHA512_End();
-char* SHA512_Data();
-
-#endif /* NOPROTO */
+char* SHA512_Data(const cm_sha2_uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#ifdef __cplusplus
}