Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Macros | Typedefs | Enumerations | Functions
sha1.h File Reference
#include <stdint.h>
Include dependency graph for sha1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  HKDFContext
 
struct  HMACContext
 
struct  SHA1Context
 
struct  SHA256Context
 
struct  SHA512Context
 
struct  USHAContext
 

Macros

#define _SHA_enum_
 
#define SHA_Ch(x, y, z)   (((x) & (y)) ^ ((~(x)) & (z)))
 
#define SHA_Maj(x, y, z)   (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
 
#define SHA_Parity(x, y, z)   ((x) ^ (y) ^ (z))
 

Typedefs

typedef struct HKDFContext HKDFContext
 
typedef struct HMACContext HMACContext
 
typedef struct SHA1Context SHA1Context
 
typedef struct SHA256Context SHA224Context
 
typedef struct SHA256Context SHA256Context
 
typedef struct SHA512Context SHA384Context
 
typedef struct SHA512Context SHA512Context
 
typedef enum SHAversion SHAversion
 
typedef struct USHAContext USHAContext
 

Enumerations

enum  {
  shaSuccess = 0 , shaNull , shaInputTooLong , shaStateError ,
  shaBadParam
}
 
enum  {
  SHA1_Message_Block_Size = 64 , SHA224_Message_Block_Size = 64 , SHA256_Message_Block_Size = 64 , SHA384_Message_Block_Size = 128 ,
  SHA512_Message_Block_Size = 128 , USHA_Max_Message_Block_Size = SHA512_Message_Block_Size , SHA1HashSize = 20 , SHA224HashSize = 28 ,
  SHA256HashSize = 32 , SHA384HashSize = 48 , SHA512HashSize = 64 , USHAMaxHashSize = SHA512HashSize ,
  SHA1HashSizeBits = 160 , SHA224HashSizeBits = 224 , SHA256HashSizeBits = 256 , SHA384HashSizeBits = 384 ,
  SHA512HashSizeBits = 512 , USHAMaxHashSizeBits = SHA512HashSizeBits
}
 
enum  SHAversion {
  SHA1 , SHA224 , SHA256 , SHA384 ,
  SHA512
}
 

Functions

int SHA1FinalBits (SHA1Context *, uint8_t bits, unsigned int bit_count)
 SHA1FinalBits Add in any final bits of the message. More...
 
int SHA1Input (SHA1Context *, const uint8_t *bytes, unsigned int bytecount)
 
int SHA1Reset (SHA1Context *)
 SHA1Reset. More...
 
int SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize])
 SHA1Result Returns the resulting 160-bit digest. More...
 
int SHA224FinalBits (SHA224Context *, uint8_t bits, unsigned int bit_count)
 
int SHA224Input (SHA224Context *, const uint8_t *bytes, unsigned int bytecount)
 
int SHA224Reset (SHA224Context *)
 
int SHA224Result (SHA224Context *, uint8_t Message_Digest[SHA224HashSize])
 
int SHA256FinalBits (SHA256Context *, uint8_t bits, unsigned int bit_count)
 
int SHA256Input (SHA256Context *, const uint8_t *bytes, unsigned int bytecount)
 
int SHA256Reset (SHA256Context *)
 
int SHA256Result (SHA256Context *, uint8_t Message_Digest[SHA256HashSize])
 
int SHA384FinalBits (SHA384Context *, uint8_t bits, unsigned int bit_count)
 
int SHA384Input (SHA384Context *, const uint8_t *bytes, unsigned int bytecount)
 
int SHA384Reset (SHA384Context *)
 
int SHA384Result (SHA384Context *, uint8_t Message_Digest[SHA384HashSize])
 
int SHA512FinalBits (SHA512Context *, uint8_t bits, unsigned int bit_count)
 
int SHA512Input (SHA512Context *, const uint8_t *bytes, unsigned int bytecount)
 
int SHA512Reset (SHA512Context *)
 
int SHA512Result (SHA512Context *, uint8_t Message_Digest[SHA512HashSize])
 
int USHABlockSize (enum SHAversion whichSha)
 
int USHAFinalBits (USHAContext *context, uint8_t bits, unsigned int bit_count)
 
const char * USHAHashName (enum SHAversion whichSha)
 
int USHAHashSize (enum SHAversion whichSha)
 
int USHAHashSizeBits (enum SHAversion whichSha)
 
int USHAInput (USHAContext *context, const uint8_t *bytes, unsigned int bytecount)
 
int USHAReset (USHAContext *context, SHAversion whichSha)
 
int USHAResult (USHAContext *context, uint8_t Message_Digest[USHAMaxHashSize])
 

Macro Definition Documentation

◆ _SHA_enum_

#define _SHA_enum_

Definition at line 87 of file sha1.h.

◆ SHA_Ch

#define SHA_Ch (   x,
  y,
 
)    (((x) & (y)) ^ ((~(x)) & (z)))

Definition at line 308 of file sha1.h.

◆ SHA_Maj

#define SHA_Maj (   x,
  y,
 
)    (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))

Definition at line 309 of file sha1.h.

◆ SHA_Parity

#define SHA_Parity (   x,
  y,
 
)    ((x) ^ (y) ^ (z))

Definition at line 320 of file sha1.h.

Typedef Documentation

◆ HKDFContext

typedef struct HKDFContext HKDFContext

◆ HMACContext

typedef struct HMACContext HMACContext

◆ SHA1Context

typedef struct SHA1Context SHA1Context

◆ SHA224Context

typedef struct SHA256Context SHA224Context

Definition at line 185 of file sha1.h.

◆ SHA256Context

typedef struct SHA256Context SHA256Context

◆ SHA384Context

typedef struct SHA512Context SHA384Context

Definition at line 191 of file sha1.h.

◆ SHA512Context

typedef struct SHA512Context SHA512Context

◆ SHAversion

typedef enum SHAversion SHAversion

◆ USHAContext

typedef struct USHAContext USHAContext

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
shaSuccess 
shaNull 
shaInputTooLong 
shaStateError 
shaBadParam 

Definition at line 91 of file sha1.h.

91 {
92 shaSuccess = 0,
93 shaNull, /* Null pointer parameter */
94 shaInputTooLong, /* input data too long */
95 shaStateError, /* called Input after FinalBits or Result */
96 shaBadParam /* passed a bad parameter */
97};
@ shaInputTooLong
Definition: sha1.h:94
@ shaSuccess
Definition: sha1.h:92
@ shaBadParam
Definition: sha1.h:96
@ shaNull
Definition: sha1.h:93
@ shaStateError
Definition: sha1.h:95

◆ anonymous enum

anonymous enum
Enumerator
SHA1_Message_Block_Size 
SHA224_Message_Block_Size 
SHA256_Message_Block_Size 
SHA384_Message_Block_Size 
SHA512_Message_Block_Size 
USHA_Max_Message_Block_Size 
SHA1HashSize 
SHA224HashSize 
SHA256HashSize 
SHA384HashSize 
SHA512HashSize 
USHAMaxHashSize 
SHA1HashSizeBits 
SHA224HashSizeBits 
SHA256HashSizeBits 
SHA384HashSizeBits 
SHA512HashSizeBits 
USHAMaxHashSizeBits 

Definition at line 104 of file sha1.h.

104 {
112
116};
@ USHA_Max_Message_Block_Size
Definition: sha1.h:108
@ SHA224HashSizeBits
Definition: sha1.h:113
@ SHA384HashSize
Definition: sha1.h:110
@ SHA384HashSizeBits
Definition: sha1.h:114
@ SHA1_Message_Block_Size
Definition: sha1.h:105
@ SHA256HashSize
Definition: sha1.h:109
@ SHA1HashSizeBits
Definition: sha1.h:113
@ SHA512HashSizeBits
Definition: sha1.h:115
@ SHA384_Message_Block_Size
Definition: sha1.h:106
@ SHA224HashSize
Definition: sha1.h:109
@ SHA512HashSize
Definition: sha1.h:110
@ USHAMaxHashSize
Definition: sha1.h:111
@ SHA512_Message_Block_Size
Definition: sha1.h:107
@ SHA1HashSize
Definition: sha1.h:109
@ USHAMaxHashSizeBits
Definition: sha1.h:115
@ SHA256_Message_Block_Size
Definition: sha1.h:106
@ SHA256HashSizeBits
Definition: sha1.h:114
@ SHA224_Message_Block_Size
Definition: sha1.h:105

◆ SHAversion

enum SHAversion
Enumerator
SHA1 
SHA224 
SHA256 
SHA384 
SHA512 

Definition at line 121 of file sha1.h.

121 {
123} SHAversion;
SHAversion
Definition: sha1.h:121
@ SHA512
Definition: sha1.h:122
@ SHA1
Definition: sha1.h:122
@ SHA384
Definition: sha1.h:122
@ SHA224
Definition: sha1.h:122
@ SHA256
Definition: sha1.h:122

Function Documentation

◆ SHA1FinalBits()

int SHA1FinalBits ( SHA1Context context,
uint8_t  message_bits,
unsigned int  length 
)

SHA1FinalBits Add in any final bits of the message.

Parameters
[in,out]contextThe SHA context to update.
[in]message_bitsThe final bits of the message, in the upper portion of the byte. (Use 0b###00000 instead of 0b00000### to input the three bits ###.)
[in]lengthThe number of bits in message_bits, between 1 and 7.
Returns
sha Error Code.

Definition at line 179 of file sha1.c.

181{
182 static uint8_t masks[8] = {
183 /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80,
184 /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0,
185 /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8,
186 /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE
187 };
188
189 static uint8_t markbit[8] = {
190 /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40,
191 /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10,
192 /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04,
193 /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01
194 };
195
196 if (!context)
197 return shaNull;
198 if (!length)
199 return shaSuccess;
200 if (context->Corrupted)
201 return context->Corrupted;
202 if (context->Computed)
203 return context->Corrupted = shaStateError;
204 if (length >= 8)
205 return context->Corrupted = shaBadParam;
206
207 SHA1AddLength(context, length);
209 (uint8_t) ((message_bits & masks[length]) |
210 markbit[length]));
211
212 return context->Corrupted;
213}
#define SHA1AddLength(context, length)
Definition: sha1.c:82
static void SHA1Finalize(SHA1Context *context, uint8_t Pad_Byte)
This helper function finishes off the digest calculations.
Definition: sha1.c:344

References voicemailpwcheck::context, SHA1AddLength, SHA1Finalize(), shaBadParam, shaNull, shaStateError, and shaSuccess.

◆ SHA1Input()

int SHA1Input ( SHA1Context ,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ SHA1Reset()

int SHA1Reset ( SHA1Context context)

SHA1Reset.

Parameters
contextthe 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 101 of file sha1.c.

102{
103 if (!context) {
104 return shaNull;
105 }
106
107 context->Length_High = context->Length_Low = 0;
108 context->Message_Block_Index = 0;
109
110 /* Initial Hash Values: FIPS 180-3 section 5.3.1 */
111 context->Intermediate_Hash[0] = 0x67452301;
112 context->Intermediate_Hash[1] = 0xEFCDAB89;
113 context->Intermediate_Hash[2] = 0x98BADCFE;
114 context->Intermediate_Hash[3] = 0x10325476;
115 context->Intermediate_Hash[4] = 0xC3D2E1F0;
116
117 context->Computed = 0;
118 context->Corrupted = shaSuccess;
119
120 return shaSuccess;
121}

References voicemailpwcheck::context, shaNull, and shaSuccess.

Referenced by ast_sha1_hash(), and ast_sha1_hash_uint().

◆ SHA1Result()

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

SHA1Result Returns the resulting 160-bit digest.

Parameters
[in,out]contextThe SHA context to update.
[out]Message_DigestWhere 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 element with index 0, the last octet of hash in the element with index 19.
Returns
sha Error Code.

Definition at line 226 of file sha1.c.

227{
228 int i;
229
230 if (!context) {
231 return shaNull;
232 }
233 if (!Message_Digest) {
234 return shaNull;
235 }
236 if (context->Corrupted) {
237 return context->Corrupted;
238 }
239
240 if (!context->Computed) {
241 SHA1Finalize(context, 0x80);
242 }
243
244 for (i = 0; i < SHA1HashSize; ++i) {
245 Message_Digest[i] = (uint8_t) (context->Intermediate_Hash[i >> 2]
246 >> (8 * (3 - (i & 0x03))));
247 }
248
249 return shaSuccess;
250}

References voicemailpwcheck::context, SHA1Finalize(), SHA1HashSize, shaNull, and shaSuccess.

Referenced by ast_sha1_hash(), and ast_sha1_hash_uint().

◆ SHA224FinalBits()

int SHA224FinalBits ( SHA224Context ,
uint8_t  bits,
unsigned int  bit_count 
)

◆ SHA224Input()

int SHA224Input ( SHA224Context ,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ SHA224Reset()

int SHA224Reset ( SHA224Context )

◆ SHA224Result()

int SHA224Result ( SHA224Context ,
uint8_t  Message_Digest[SHA224HashSize] 
)

◆ SHA256FinalBits()

int SHA256FinalBits ( SHA256Context ,
uint8_t  bits,
unsigned int  bit_count 
)

◆ SHA256Input()

int SHA256Input ( SHA256Context ,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ SHA256Reset()

int SHA256Reset ( SHA256Context )

◆ SHA256Result()

int SHA256Result ( SHA256Context ,
uint8_t  Message_Digest[SHA256HashSize] 
)

◆ SHA384FinalBits()

int SHA384FinalBits ( SHA384Context ,
uint8_t  bits,
unsigned int  bit_count 
)

◆ SHA384Input()

int SHA384Input ( SHA384Context ,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ SHA384Reset()

int SHA384Reset ( SHA384Context )

◆ SHA384Result()

int SHA384Result ( SHA384Context ,
uint8_t  Message_Digest[SHA384HashSize] 
)

◆ SHA512FinalBits()

int SHA512FinalBits ( SHA512Context ,
uint8_t  bits,
unsigned int  bit_count 
)

◆ SHA512Input()

int SHA512Input ( SHA512Context ,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ SHA512Reset()

int SHA512Reset ( SHA512Context )

◆ SHA512Result()

int SHA512Result ( SHA512Context ,
uint8_t  Message_Digest[SHA512HashSize] 
)

◆ USHABlockSize()

int USHABlockSize ( enum SHAversion  whichSha)

◆ USHAFinalBits()

int USHAFinalBits ( USHAContext context,
uint8_t  bits,
unsigned int  bit_count 
)

◆ USHAHashName()

const char * USHAHashName ( enum SHAversion  whichSha)

◆ USHAHashSize()

int USHAHashSize ( enum SHAversion  whichSha)

◆ USHAHashSizeBits()

int USHAHashSizeBits ( enum SHAversion  whichSha)

◆ USHAInput()

int USHAInput ( USHAContext context,
const uint8_t *  bytes,
unsigned int  bytecount 
)

◆ USHAReset()

int USHAReset ( USHAContext context,
SHAversion  whichSha 
)

◆ USHAResult()

int USHAResult ( USHAContext context,
uint8_t  Message_Digest[USHAMaxHashSize] 
)