00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __SHA2_H__
00038 #define __SHA2_H__
00039
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043
00044
00045
00046
00047
00048
00049
00050 #include <sys/types.h>
00051
00052 #ifdef RUBY
00053 # ifdef HAVE_PROTOTYPES
00054 # undef NOPROTO
00055 # else
00056 # define NOPROTO
00057 # endif
00058 # ifndef BYTE_ORDER
00059 # define LITTLE_ENDIAN 1234
00060 # define BIG_ENDIAN 4321
00061 # ifdef WORDS_BIGENDIAN
00062 # define BYTE_ORDER BIG_ENDIAN
00063 # else
00064 # define BYTE_ORDER LITTLE_ENDIAN
00065 # endif
00066 # endif
00067 # define SHA2_USE_INTTYPES_H
00068 #else
00069 #ifdef SHA2_USE_INTTYPES_H
00070
00071 #include <inttypes.h>
00072
00073 #endif
00074 #endif
00075
00076
00077
00078 #define SHA256_BLOCK_LENGTH 64
00079 #define SHA256_DIGEST_LENGTH 32
00080 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
00081 #define SHA384_BLOCK_LENGTH 128
00082 #define SHA384_DIGEST_LENGTH 48
00083 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
00084 #define SHA512_BLOCK_LENGTH 128
00085 #define SHA512_DIGEST_LENGTH 64
00086 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
00087
00088
00089
00090
00091
00092
00093
00094 #ifndef SHA2_USE_INTTYPES_H
00095 # ifdef HAVE_U_INT8_T
00096 typedef u_int8_t uint8_t;
00097 typedef u_int32_t uint32_t;
00098 typedef u_int64_t uint64_t;
00099 # else
00100 typedef unsigned char uint8_t;
00101 typedef unsigned int uint32_t;
00102 typedef unsigned long long uint64_t;
00103 # endif
00104 #endif
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 typedef struct _SHA256_CTX {
00123 uint32_t state[8];
00124 uint64_t bitcount;
00125 uint8_t buffer[SHA256_BLOCK_LENGTH];
00126 } SHA256_CTX;
00127 typedef struct _SHA512_CTX {
00128 uint64_t state[8];
00129 uint64_t bitcount[2];
00130 uint8_t buffer[SHA512_BLOCK_LENGTH];
00131 } SHA512_CTX;
00132
00133 typedef SHA512_CTX SHA384_CTX;
00134
00135
00136
00137 #ifdef RUBY
00138 #define SHA256_Init rb_Digest_SHA256_Init
00139 #define SHA256_Update rb_Digest_SHA256_Update
00140 #define SHA256_Finish rb_Digest_SHA256_Finish
00141 #define SHA256_Data rb_Digest_SHA256_Data
00142 #define SHA256_End rb_Digest_SHA256_End
00143 #define SHA256_Last rb_Digest_SHA256_Last
00144 #define SHA256_Transform rb_Digest_SHA256_Transform
00145 #define SHA256_Final(d, c) SHA256_Finish(c, d)
00146
00147 #define SHA384_Init rb_Digest_SHA384_Init
00148 #define SHA384_Update rb_Digest_SHA384_Update
00149 #define SHA384_Finish rb_Digest_SHA384_Finish
00150 #define SHA384_Data rb_Digest_SHA384_Data
00151 #define SHA384_End rb_Digest_SHA384_End
00152 #define SHA384_Last rb_Digest_SHA384_Last
00153 #define SHA384_Transform rb_Digest_SHA384_Transform
00154 #define SHA384_Final(d, c) SHA384_Finish(c, d)
00155
00156 #define SHA512_Init rb_Digest_SHA512_Init
00157 #define SHA512_Update rb_Digest_SHA512_Update
00158 #define SHA512_Finish rb_Digest_SHA512_Finish
00159 #define SHA512_Data rb_Digest_SHA512_Data
00160 #define SHA512_End rb_Digest_SHA512_End
00161 #define SHA512_Last rb_Digest_SHA512_Last
00162 #define SHA512_Transform rb_Digest_SHA512_Transform
00163 #define SHA512_Final(d, c) SHA512_Finish(c, d)
00164 #endif
00165
00166 #ifndef NOPROTO
00167
00168 void SHA256_Init(SHA256_CTX *);
00169 void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
00170 void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
00171 char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
00172 char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
00173
00174 void SHA384_Init(SHA384_CTX*);
00175 void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
00176 void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
00177 char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
00178 char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
00179
00180 void SHA512_Init(SHA512_CTX*);
00181 void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
00182 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
00183 char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
00184 char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
00185
00186 #else
00187
00188 void SHA256_Init();
00189 void SHA256_Update();
00190 #ifdef RUBY
00191 void SHA256_Finish();
00192 #else
00193 void SHA256_Final();
00194 #endif
00195 char* SHA256_End();
00196 char* SHA256_Data();
00197
00198 void SHA384_Init();
00199 void SHA384_Update();
00200 #ifdef RUBY
00201 void SHA384_Finish();
00202 #else
00203 void SHA384_Final();
00204 #endif
00205 char* SHA384_End();
00206 char* SHA384_Data();
00207
00208 void SHA512_Init();
00209 void SHA512_Update();
00210 #ifdef RUBY
00211 void SHA512_Finish();
00212 #else
00213 void SHA512_Final();
00214 #endif
00215 char* SHA512_End();
00216 char* SHA512_Data();
00217
00218 #endif
00219
00220 #ifdef __cplusplus
00221 }
00222 #endif
00223
00224 #endif
00225
00226