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
00038
00039 #ifndef __SHA2_H__
00040 #define __SHA2_H__
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00046
00047 #define SHA256_BLOCK_LENGTH 64
00048 #define SHA256_DIGEST_LENGTH 32
00049 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
00050 #define SHA384_BLOCK_LENGTH 128
00051 #define SHA384_DIGEST_LENGTH 48
00052 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
00053 #define SHA512_BLOCK_LENGTH 128
00054 #define SHA512_DIGEST_LENGTH 64
00055 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
00056
00057 #ifdef __minix
00058 #include <assert.h>
00059 #include <string.h>
00060 #include <sys/types.h>
00061 #include <minix/u64.h>
00062
00063 typedef u8_t u_int8_t;
00064 typedef u32_t u_int32_t;
00065 typedef u64_t u_int64_t;
00066
00067 #ifndef __P
00068 #define __P(x) x
00069 #endif
00070
00071 #define NO_64BIT 1
00072 #define MINIX_64BIT 1
00073
00074 #define SHA2_BYTE_ORDER 0x04030201
00075 #define SHA2_LITTLE_ENDIAN 0x04030201
00076 #define SHA2_BIG_ENDIAN 0x01020204
00077 #define bcopy(s,d,l) (memmove((d),(s),(l)))
00078 #define bzero(d,l) (memset((d),'\0',(l)))
00079 #endif
00080
00081
00082
00083
00084
00085
00086 #if 0
00087 typedef unsigned char u_int8_t;
00088 typedef unsigned int u_int32_t;
00089 typedef unsigned long long u_int64_t;
00090 #endif
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #if 0
00108
00109 typedef struct _SHA256_CTX {
00110 uint32_t state[8];
00111 uint64_t bitcount;
00112 uint8_t buffer[SHA256_BLOCK_LENGTH];
00113 } SHA256_CTX;
00114 typedef struct _SHA512_CTX {
00115 uint64_t state[8];
00116 uint64_t bitcount[2];
00117 uint8_t buffer[SHA512_BLOCK_LENGTH];
00118 } SHA512_CTX;
00119
00120 #else
00121
00122 typedef struct _SHA256_CTX {
00123 u_int32_t state[8];
00124 u_int64_t bitcount;
00125 u_int8_t buffer[SHA256_BLOCK_LENGTH];
00126 } SHA256_CTX;
00127 typedef struct _SHA512_CTX {
00128 u_int64_t state[8];
00129 u_int64_t bitcount[2];
00130 u_int8_t buffer[SHA512_BLOCK_LENGTH];
00131 } SHA512_CTX;
00132
00133 #endif
00134
00135 typedef SHA512_CTX SHA384_CTX;
00136
00137
00138
00139 void SHA256_Init __P((SHA256_CTX *));
00140 void SHA256_Update __P((SHA256_CTX*, const u_int8_t*, size_t));
00141 void SHA256_Final __P((u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
00142 char* SHA256_End __P((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
00143 char* SHA256_Data __P((const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
00144
00145 void SHA384_Init __P((SHA384_CTX*));
00146 void SHA384_Update __P((SHA384_CTX*, const u_int8_t*, size_t));
00147 void SHA384_Final __P((u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
00148 char* SHA384_End __P((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
00149 char* SHA384_Data __P((const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
00150
00151 void SHA512_Init __P((SHA512_CTX*));
00152 void SHA512_Update __P((SHA512_CTX*, const u_int8_t*, size_t));
00153 void SHA512_Final __P((u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
00154 char* SHA512_End __P((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
00155 char* SHA512_Data __P((const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
00156
00157 #ifdef __cplusplus
00158 }
00159 #endif
00160
00161 #endif
00162
00163
00164
00165