Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Based on the RFC 6234. More...
#include <asterisk/sha1.h>
Go to the source code of this file.
Macros | |
#define | SHA1_ROTL(bits, word) (((word) << (bits)) | ((word) >> (32-(bits)))) |
#define | SHA1AddLength(context, length) |
Functions | |
int | SHA1FinalBits (SHA1Context *context, uint8_t message_bits, unsigned int length) |
SHA1FinalBits Add in any final bits of the message. More... | |
static void | SHA1Finalize (SHA1Context *context, uint8_t Pad_Byte) |
This helper function finishes off the digest calculations. More... | |
int | SHA1Input (SHA1Context *context, const uint8_t *message_array, unsigned length) |
SHA1Input. More... | |
static void | SHA1PadMessage (SHA1Context *context, uint8_t Pad_Byte) |
Pad message to be 512 bits. More... | |
static void | SHA1ProcessMessageBlock (SHA1Context *context) |
Process the next 512 bits of the message stored in the Message_Block array. More... | |
int | SHA1Reset (SHA1Context *context) |
SHA1Reset. More... | |
int | SHA1Result (SHA1Context *context, uint8_t Message_Digest[SHA1HashSize]) |
SHA1Result Returns the resulting 160-bit digest. More... | |
Variables | |
static uint32_t | addTemp |
Based on the RFC 6234.
Copyright (c) 2011 IETF Trust and the persons identified as authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description: This file implements the Secure Hash Algorithm SHA-1 as defined in the U.S. National Institute of Standards and Technology Federal Information Processing Standards Publication (FIPS PUB) 180-3 published in October 2008 and formerly defined in its predecessors, FIPS PUB 180-1 and FIP PUB 180-2.
A combined document showing all algorithms is available at http://csrc.nist.gov/publications/fips/ fips180-3/fips180-3_final.pdf
The SHA-1 algorithm produces a 160-bit message digest for a given data stream that can serve as a means of providing a "fingerprint" for a message.
Portability Issues: SHA-1 is defined in terms of 32-bit "words". This code uses <stdint.h> (included via "sha.h") to define 32- and 8-bit unsigned integer types. If your C compiler does not support 32-bit unsigned integers, this code is not appropriate.
Caveats: SHA-1 is designed to work with messages less than 2^64 bits long. This implementation uses SHA1Input() to hash the bits that are a multiple of the size of an 8-bit octet, and then optionally uses SHA1FinalBits() to hash the final few bits of the input.
Definition in file sha1.c.
#define SHA1AddLength | ( | context, | |
length | |||
) |
int SHA1FinalBits | ( | SHA1Context * | context, |
uint8_t | message_bits, | ||
unsigned int | length | ||
) |
SHA1FinalBits Add in any final bits of the message.
[in,out] | context | The SHA context to update. |
[in] | message_bits | The final bits of the message, in the upper portion of the byte. (Use 0b###00000 instead of 0b00000### to input the three bits ###.) |
[in] | length | The number of bits in message_bits, between 1 and 7. |
Definition at line 179 of file sha1.c.
References voicemailpwcheck::context, SHA1AddLength, SHA1Finalize(), shaBadParam, shaNull, shaStateError, and shaSuccess.
|
static |
This helper function finishes off the digest calculations.
[in,out] | context | The context to pad. |
[in] | Pad_Byte | The last byte to add to the message block before the 0-padding and length. This will contain the last bits of the message followed by another single bit. If the message was an exact multiple of 8-bits long, Pad_Byte will be 0x80. |
Definition at line 344 of file sha1.c.
References voicemailpwcheck::context, SHA1_Message_Block_Size, and SHA1PadMessage().
Referenced by SHA1FinalBits(), and SHA1Result().
int SHA1Input | ( | SHA1Context * | context, |
const uint8_t * | message_array, | ||
unsigned | length | ||
) |
SHA1Input.
[in,out] | context | The SHA context to update |
[in] | message_array | An array of characters representing the next portion of the message. |
[in] | length | 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 133 of file sha1.c.
References voicemailpwcheck::context, SHA1_Message_Block_Size, SHA1AddLength, SHA1ProcessMessageBlock(), shaNull, shaStateError, and shaSuccess.
|
static |
Pad message to be 512 bits.
[in,out] | context | The context to pad. |
[in] | Pad_Byte | Last padding byte. |
According to the standard, the message must be padded to the next even multiple of 512 bits. The first padding bit must be a '1'. The last 64 bits represent the length of the original message. All bits in between should be 0. This helper function will pad the message according to those rules by filling the Message_Block array accordingly. When it returns, it can be assumed that the message digest has been computed.
Definition at line 370 of file sha1.c.
References voicemailpwcheck::context, SHA1_Message_Block_Size, and SHA1ProcessMessageBlock().
Referenced by SHA1Finalize().
|
static |
Process the next 512 bits of the message stored in the Message_Block array.
[in,out] | context | The SHA context to update |
Definition at line 259 of file sha1.c.
References voicemailpwcheck::context, SHA1_ROTL, SHA_Ch, SHA_Maj, and SHA_Parity.
Referenced by SHA1Input(), and SHA1PadMessage().
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 101 of file sha1.c.
References voicemailpwcheck::context, shaNull, and shaSuccess.
Referenced by ast_sha1_hash(), and ast_sha1_hash_uint().
int SHA1Result | ( | SHA1Context * | context, |
uint8_t | Message_Digest[SHA1HashSize] | ||
) |
SHA1Result Returns the resulting 160-bit digest.
[in,out] | context | The SHA context to update. |
[out] | Message_Digest | 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 226 of file sha1.c.
References voicemailpwcheck::context, SHA1Finalize(), SHA1HashSize, shaNull, and shaSuccess.
Referenced by ast_sha1_hash(), and ast_sha1_hash_uint().