
Go to the source code of this file.
Data Structures | |
| struct | SHA1Context |
| This structure will hold context information for the SHA-1 hashing operation. More... | |
Defines | |
| #define | _SHA_enum_ |
| #define | SHA1HashSize 20 |
Typedefs | |
| typedef struct SHA1Context | SHA1Context |
| This structure will hold context information for the SHA-1 hashing operation. | |
Enumerations | |
| enum | { shaSuccess = 0, shaNull, shaInputTooLong, shaStateError } |
Functions | |
| int | SHA1Input (SHA1Context *, const uint8_t *, unsigned int) |
| SHA1Input. | |
| int | SHA1Reset (SHA1Context *) |
| SHA1Reset. | |
| int | SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize]) |
| SHA1Result. | |
| #define SHA1HashSize 20 |
Definition at line 41 of file sha1.h.
Referenced by SHA1Result().
| typedef struct SHA1Context SHA1Context |
This structure will hold context information for the SHA-1 hashing operation.
| anonymous enum |
Definition at line 33 of file sha1.h.
{
shaSuccess = 0,
shaNull, /* Null pointer parameter */
shaInputTooLong, /* input data too long */
shaStateError /* called Input after Result */
};
| int SHA1Input | ( | SHA1Context * | context, |
| const uint8_t * | message_array, | ||
| unsigned | length | ||
| ) |
SHA1Input.
| context | [in/out] The SHA context to update |
| message_array | [in] An array of characters representing the next portion of the message. |
| length | [in] The length of the message in message_array. This function accepts an array of octets as the next portion of the message. |
Definition at line 154 of file sha1.c.
References SHA1Context::Computed, SHA1Context::Corrupted, SHA1Context::Length_High, SHA1Context::Length_Low, SHA1Context::Message_Block, SHA1Context::Message_Block_Index, SHA1ProcessMessageBlock(), shaNull, shaStateError, and shaSuccess.
Referenced by ast_sha1_hash().
{
if (!length) {
return shaSuccess;
}
if (!context || !message_array) {
return shaNull;
}
if (context->Computed) {
context->Corrupted = shaStateError;
return shaStateError;
}
if (context->Corrupted) {
return context->Corrupted;
}
while (length-- && !context->Corrupted) {
context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF);
context->Length_Low += 8;
if (context->Length_Low == 0) {
context->Length_High++;
if (context->Length_High == 0) {
/* Message is too long */
context->Corrupted = 1;
}
}
if (context->Message_Block_Index == 64) {
SHA1ProcessMessageBlock(context);
}
message_array++;
}
return shaSuccess;
}
| int SHA1Reset | ( | SHA1Context * | context | ) |
SHA1Reset.
| context | the context to be reset. This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest. |
Definition at line 81 of file sha1.c.
References SHA1Context::Computed, SHA1Context::Corrupted, SHA1Context::Intermediate_Hash, SHA1Context::Length_High, SHA1Context::Length_Low, SHA1Context::Message_Block_Index, shaNull, and shaSuccess.
Referenced by ast_sha1_hash().
{
if (!context) {
return shaNull;
}
context->Length_Low = 0;
context->Length_High = 0;
context->Message_Block_Index = 0;
context->Intermediate_Hash[0] = 0x67452301;
context->Intermediate_Hash[1] = 0xEFCDAB89;
context->Intermediate_Hash[2] = 0x98BADCFE;
context->Intermediate_Hash[3] = 0x10325476;
context->Intermediate_Hash[4] = 0xC3D2E1F0;
context->Computed = 0;
context->Corrupted = 0;
return shaSuccess;
}
| int SHA1Result | ( | SHA1Context * | context, |
| uint8_t | Message_Digest[SHA1HashSize] | ||
| ) |
SHA1Result.
| context | [in/out] The context to use to calculate the SHA-1 hash. |
| Message_Digest | [out] Where the digest is returned. This function will return the 160-bit message digest into the Message_Digest array provided by the caller. |
Definition at line 113 of file sha1.c.
References SHA1Context::Computed, SHA1Context::Corrupted, SHA1Context::Intermediate_Hash, SHA1Context::Length_High, SHA1Context::Length_Low, SHA1Context::Message_Block, SHA1HashSize, SHA1PadMessage(), shaNull, and shaSuccess.
Referenced by ast_sha1_hash().
{
int i;
if (!context || !Message_Digest) {
return shaNull;
}
if (context->Corrupted) {
return context->Corrupted;
}
if (!context->Computed) {
SHA1PadMessage(context);
for (i = 0; i < 64; ++i) {
/* message may be sensitive, clear it out */
context->Message_Block[i] = 0;
}
context->Length_Low = 0; /* and clear length */
context->Length_High = 0;
context->Computed = 1;
}
for (i = 0; i < SHA1HashSize; ++i) {
Message_Digest[i] = context->Intermediate_Hash[i >> 2] >> 8 * ( 3 - ( i & 0x03 ) );
}
return shaSuccess;
}