Thu Jul 9 13:41:33 2009

Asterisk developer's documentation


sha1.h File Reference

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 SHA1HashSize   20

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 Documentation

#define SHA1HashSize   20

Definition at line 41 of file sha1.h.


Enumeration Type Documentation

anonymous enum

Enumerator:
shaSuccess 
shaNull 
shaInputTooLong 
shaStateError 

Definition at line 33 of file sha1.h.

00034 {
00035     shaSuccess = 0,
00036     shaNull,            /* Null pointer parameter */
00037     shaInputTooLong,    /* input data too long */
00038     shaStateError       /* called Input after Result */
00039 };


Function Documentation

int SHA1Input ( SHA1Context context,
const uint8_t *  message_array,
unsigned  length 
)

SHA1Input.

Parameters:
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.
Returns:
sha Error Code.

Definition at line 154 of file sha1.c.

References context, SHA1ProcessMessageBlock(), shaNull, shaStateError, and shaSuccess.

Referenced by ast_sha1_hash().

00155 {
00156    if (!length) {
00157       return shaSuccess;
00158    }
00159 
00160    if (!context || !message_array) {
00161       return shaNull;
00162    }
00163 
00164    if (context->Computed) {
00165       context->Corrupted = shaStateError;
00166       return shaStateError;
00167    }
00168 
00169    if (context->Corrupted) {
00170       return context->Corrupted;
00171    }
00172 
00173    while (length-- && !context->Corrupted) {
00174       context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF);
00175 
00176       context->Length_Low += 8;
00177       if (context->Length_Low == 0) {
00178          context->Length_High++;
00179          if (context->Length_High == 0) {
00180             /* Message is too long */
00181             context->Corrupted = 1;
00182          }
00183       }
00184 
00185       if (context->Message_Block_Index == 64) {
00186          SHA1ProcessMessageBlock(context);
00187       }
00188 
00189       message_array++;
00190    }
00191 
00192    return shaSuccess;
00193 }

int SHA1Reset ( SHA1Context context  ) 

SHA1Reset.

Parameters:
context the context to be reset. This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest.
Returns:
sha Error Code.

Definition at line 81 of file sha1.c.

References context, shaNull, and shaSuccess.

Referenced by ast_sha1_hash().

00082 {
00083    if (!context) {
00084       return shaNull;
00085    }
00086 
00087    context->Length_Low             = 0;
00088    context->Length_High            = 0;
00089    context->Message_Block_Index    = 0;
00090 
00091    context->Intermediate_Hash[0]   = 0x67452301;
00092    context->Intermediate_Hash[1]   = 0xEFCDAB89;
00093    context->Intermediate_Hash[2]   = 0x98BADCFE;
00094    context->Intermediate_Hash[3]   = 0x10325476;
00095    context->Intermediate_Hash[4]   = 0xC3D2E1F0;
00096 
00097    context->Computed               = 0;
00098    context->Corrupted              = 0;
00099 
00100    return shaSuccess;
00101 }

int SHA1Result ( SHA1Context context,
uint8_t  Message_Digest[SHA1HashSize] 
)

SHA1Result.

Parameters:
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.
Note:
The first octet of hash is stored in the 0th element, the last octet of hash in the 19th element.
Returns:
sha Error Code.

Definition at line 113 of file sha1.c.

References context, SHA1PadMessage(), shaNull, and shaSuccess.

Referenced by ast_sha1_hash().

00115 {
00116    int i;
00117 
00118    if (!context || !Message_Digest) {
00119       return shaNull;
00120    }
00121 
00122    if (context->Corrupted) {
00123       return context->Corrupted;
00124    }
00125 
00126    if (!context->Computed) {
00127       SHA1PadMessage(context);
00128       for (i = 0; i < 64; ++i) {
00129          /* message may be sensitive, clear it out */
00130          context->Message_Block[i] = 0;
00131       }
00132       context->Length_Low = 0;    /* and clear length */
00133       context->Length_High = 0;
00134       context->Computed = 1;
00135    }
00136 
00137    for (i = 0; i < SHA1HashSize; ++i) {
00138       Message_Digest[i] = context->Intermediate_Hash[i >> 2] >> 8 * ( 3 - ( i & 0x03 ) );
00139    }
00140 
00141    return shaSuccess;
00142 }


Generated on Thu Jul 9 13:41:33 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7