#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | SHA1Context |
Defines | |
#define | SHA1HashSize 20 |
Enumerations | |
enum | { shaSuccess = 0, shaNull, shaInputTooLong, shaStateError } |
Functions | |
int | SHA1Input (SHA1Context *, const uint8_t *, unsigned int) |
int | SHA1Reset (SHA1Context *) |
int | SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize]) |
anonymous enum |
Definition at line 40 of file sha1.h.
00041 { 00042 shaSuccess = 0, 00043 shaNull, /* Null pointer parameter */ 00044 shaInputTooLong, /* input data too long */ 00045 shaStateError /* called Input after Result */ 00046 };
int SHA1Input | ( | SHA1Context * | , | |
const uint8_t * | , | |||
unsigned | int | |||
) |
Definition at line 183 of file sha1.c.
References context, SHA1ProcessMessageBlock(), shaNull, shaStateError, and shaSuccess.
Referenced by ast_sha1_hash().
00184 { 00185 if (!length) { 00186 return shaSuccess; 00187 } 00188 00189 if (!context || !message_array) { 00190 return shaNull; 00191 } 00192 00193 if (context->Computed) { 00194 context->Corrupted = shaStateError; 00195 return shaStateError; 00196 } 00197 00198 if (context->Corrupted) { 00199 return context->Corrupted; 00200 } 00201 00202 while (length-- && !context->Corrupted) { 00203 context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); 00204 00205 context->Length_Low += 8; 00206 if (context->Length_Low == 0) { 00207 context->Length_High++; 00208 if (context->Length_High == 0) { 00209 /* Message is too long */ 00210 context->Corrupted = 1; 00211 } 00212 } 00213 00214 if (context->Message_Block_Index == 64) { 00215 SHA1ProcessMessageBlock(context); 00216 } 00217 00218 message_array++; 00219 } 00220 00221 return shaSuccess; 00222 }
int SHA1Reset | ( | SHA1Context * | ) |
Definition at line 91 of file sha1.c.
References context, shaNull, and shaSuccess.
Referenced by ast_sha1_hash().
00092 { 00093 if (!context) { 00094 return shaNull; 00095 } 00096 00097 context->Length_Low = 0; 00098 context->Length_High = 0; 00099 context->Message_Block_Index = 0; 00100 00101 context->Intermediate_Hash[0] = 0x67452301; 00102 context->Intermediate_Hash[1] = 0xEFCDAB89; 00103 context->Intermediate_Hash[2] = 0x98BADCFE; 00104 context->Intermediate_Hash[3] = 0x10325476; 00105 context->Intermediate_Hash[4] = 0xC3D2E1F0; 00106 00107 context->Computed = 0; 00108 context->Corrupted = 0; 00109 00110 return shaSuccess; 00111 }
int SHA1Result | ( | SHA1Context * | , | |
uint8_t | Message_Digest[SHA1HashSize] | |||
) |
Definition at line 132 of file sha1.c.
References context, SHA1PadMessage(), shaNull, and shaSuccess.
Referenced by ast_sha1_hash().
00134 { 00135 int i; 00136 00137 if (!context || !Message_Digest) { 00138 return shaNull; 00139 } 00140 00141 if (context->Corrupted) { 00142 return context->Corrupted; 00143 } 00144 00145 if (!context->Computed) { 00146 SHA1PadMessage(context); 00147 for (i = 0; i < 64; ++i) { 00148 /* message may be sensitive, clear it out */ 00149 context->Message_Block[i] = 0; 00150 } 00151 context->Length_Low = 0; /* and clear length */ 00152 context->Length_High = 0; 00153 context->Computed = 1; 00154 } 00155 00156 for (i = 0; i < SHA1HashSize; ++i) { 00157 Message_Digest[i] = context->Intermediate_Hash[i >> 2] >> 8 * ( 3 - ( i & 0x03 ) ); 00158 } 00159 00160 return shaSuccess; 00161 }