#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | HKDFContext |
struct | HMACContext |
struct | SHA1Context |
struct | SHA256Context |
struct | SHA512Context |
struct | USHAContext |
Defines | |
#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 SHA256Context | SHA224Context |
typedef struct SHA512Context | SHA384Context |
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 | hkdf (SHAversion whichSha, const unsigned char *salt, int salt_len, const unsigned char *ikm, int ikm_len, const unsigned char *info, int info_len, uint8_t okm[], int okm_len) |
int | hkdfExpand (SHAversion whichSha, const uint8_t prk[], int prk_len, const unsigned char *info, int info_len, uint8_t okm[], int okm_len) |
int | hkdfExtract (SHAversion whichSha, const unsigned char *salt, int salt_len, const unsigned char *ikm, int ikm_len, uint8_t prk[USHAMaxHashSize]) |
int | hkdfFinalBits (HKDFContext *context, uint8_t ikm_bits, unsigned int ikm_bit_count) |
int | hkdfInput (HKDFContext *context, const unsigned char *ikm, int ikm_len) |
int | hkdfReset (HKDFContext *context, enum SHAversion whichSha, const unsigned char *salt, int salt_len) |
int | hkdfResult (HKDFContext *context, uint8_t prk[USHAMaxHashSize], const unsigned char *info, int info_len, uint8_t okm[USHAMaxHashSize], int okm_len) |
int | hmac (SHAversion whichSha, const unsigned char *text, int text_len, const unsigned char *key, int key_len, uint8_t digest[USHAMaxHashSize]) |
int | hmacFinalBits (HMACContext *context, uint8_t bits, unsigned int bit_count) |
int | hmacInput (HMACContext *context, const unsigned char *text, int text_len) |
int | hmacReset (HMACContext *context, enum SHAversion whichSha, const unsigned char *key, int key_len) |
int | hmacResult (HMACContext *context, uint8_t digest[USHAMaxHashSize]) |
int | SHA1FinalBits (SHA1Context *, uint8_t bits, unsigned int bit_count) |
SHA1FinalBits Add in any final bits of the message. | |
int | SHA1Input (SHA1Context *, const uint8_t *bytes, unsigned int bytecount) |
int | SHA1Reset (SHA1Context *) |
SHA1Reset. | |
int | SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize]) |
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]) |
#define SHA_Ch | ( | x, | |||
y, | |||||
z | ) | (((x) & (y)) ^ ((~(x)) & (z))) |
Definition at line 365 of file sha1.h.
Referenced by SHA1ProcessMessageBlock().
#define SHA_Maj | ( | x, | |||
y, | |||||
z | ) | (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
Definition at line 366 of file sha1.h.
Referenced by SHA1ProcessMessageBlock().
#define SHA_Parity | ( | x, | |||
y, | |||||
z | ) | ((x) ^ (y) ^ (z)) |
Definition at line 377 of file sha1.h.
Referenced by SHA1ProcessMessageBlock().
typedef struct SHA256Context SHA224Context |
typedef struct SHA512Context SHA384Context |
anonymous enum |
Definition at line 91 of file sha1.h.
00091 { 00092 shaSuccess = 0, 00093 shaNull, /* Null pointer parameter */ 00094 shaInputTooLong, /* input data too long */ 00095 shaStateError, /* called Input after FinalBits or Result */ 00096 shaBadParam /* passed a bad parameter */ 00097 };
anonymous enum |
Definition at line 104 of file sha1.h.
00104 { 00105 SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64, 00106 SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128, 00107 SHA512_Message_Block_Size = 128, 00108 USHA_Max_Message_Block_Size = SHA512_Message_Block_Size, 00109 SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32, 00110 SHA384HashSize = 48, SHA512HashSize = 64, 00111 USHAMaxHashSize = SHA512HashSize, 00112 00113 SHA1HashSizeBits = 160, SHA224HashSizeBits = 224, 00114 SHA256HashSizeBits = 256, SHA384HashSizeBits = 384, 00115 SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits 00116 };
enum SHAversion |
int hkdf | ( | SHAversion | whichSha, | |
const unsigned char * | salt, | |||
int | salt_len, | |||
const unsigned char * | ikm, | |||
int | ikm_len, | |||
const unsigned char * | info, | |||
int | info_len, | |||
uint8_t | okm[], | |||
int | okm_len | |||
) |
int hkdfExpand | ( | SHAversion | whichSha, | |
const uint8_t | prk[], | |||
int | prk_len, | |||
const unsigned char * | info, | |||
int | info_len, | |||
uint8_t | okm[], | |||
int | okm_len | |||
) |
int hkdfExtract | ( | SHAversion | whichSha, | |
const unsigned char * | salt, | |||
int | salt_len, | |||
const unsigned char * | ikm, | |||
int | ikm_len, | |||
uint8_t | prk[USHAMaxHashSize] | |||
) |
int hkdfFinalBits | ( | HKDFContext * | context, | |
uint8_t | ikm_bits, | |||
unsigned int | ikm_bit_count | |||
) |
int hkdfInput | ( | HKDFContext * | context, | |
const unsigned char * | ikm, | |||
int | ikm_len | |||
) |
int hkdfReset | ( | HKDFContext * | context, | |
enum SHAversion | whichSha, | |||
const unsigned char * | salt, | |||
int | salt_len | |||
) |
int hkdfResult | ( | HKDFContext * | context, | |
uint8_t | prk[USHAMaxHashSize], | |||
const unsigned char * | info, | |||
int | info_len, | |||
uint8_t | okm[USHAMaxHashSize], | |||
int | okm_len | |||
) |
int hmac | ( | SHAversion | whichSha, | |
const unsigned char * | text, | |||
int | text_len, | |||
const unsigned char * | key, | |||
int | key_len, | |||
uint8_t | digest[USHAMaxHashSize] | |||
) |
int hmacFinalBits | ( | HMACContext * | context, | |
uint8_t | bits, | |||
unsigned int | bit_count | |||
) |
int hmacInput | ( | HMACContext * | context, | |
const unsigned char * | text, | |||
int | text_len | |||
) |
int hmacReset | ( | HMACContext * | context, | |
enum SHAversion | whichSha, | |||
const unsigned char * | key, | |||
int | key_len | |||
) |
int hmacResult | ( | HMACContext * | context, | |
uint8_t | digest[USHAMaxHashSize] | |||
) |
int SHA1FinalBits | ( | SHA1Context * | context, | |
uint8_t | message_bits, | |||
unsigned int | length | |||
) |
SHA1FinalBits Add in any final bits of the message.
context | [in/out] The SHA context to update. | |
message_bits | [in] The final bits of the message, in the upper portion of the byte. (Use 0b###00000 instead of 0b00000### to input the three bits ###.) | |
length | [in] * The number of bits in message_bits, between 1 and 7. |
Definition at line 179 of file sha1.c.
References SHA1Context::Computed, SHA1Context::Corrupted, SHA1AddLength, SHA1Finalize(), shaBadParam, shaNull, shaStateError, and shaSuccess.
00181 { 00182 static uint8_t masks[8] = { 00183 /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80, 00184 /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0, 00185 /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8, 00186 /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE 00187 }; 00188 00189 static uint8_t markbit[8] = { 00190 /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40, 00191 /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10, 00192 /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04, 00193 /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01 00194 }; 00195 00196 if (!context) 00197 return shaNull; 00198 if (!length) 00199 return shaSuccess; 00200 if (context->Corrupted) 00201 return context->Corrupted; 00202 if (context->Computed) 00203 return context->Corrupted = shaStateError; 00204 if (length >= 8) 00205 return context->Corrupted = shaBadParam; 00206 00207 SHA1AddLength(context, length); 00208 SHA1Finalize(context, 00209 (uint8_t) ((message_bits & masks[length]) | 00210 markbit[length])); 00211 00212 return context->Corrupted; 00213 }
int SHA1Input | ( | SHA1Context * | , | |
const uint8_t * | bytes, | |||
unsigned int | bytecount | |||
) |
Referenced by ast_sha1_hash().
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 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().
00102 { 00103 if (!context) { 00104 return shaNull; 00105 } 00106 00107 context->Length_High = context->Length_Low = 0; 00108 context->Message_Block_Index = 0; 00109 00110 /* Initial Hash Values: FIPS 180-3 section 5.3.1 */ 00111 context->Intermediate_Hash[0] = 0x67452301; 00112 context->Intermediate_Hash[1] = 0xEFCDAB89; 00113 context->Intermediate_Hash[2] = 0x98BADCFE; 00114 context->Intermediate_Hash[3] = 0x10325476; 00115 context->Intermediate_Hash[4] = 0xC3D2E1F0; 00116 00117 context->Computed = 0; 00118 context->Corrupted = shaSuccess; 00119 00120 return shaSuccess; 00121 }
int SHA1Result | ( | SHA1Context * | , | |
uint8_t | Message_Digest[SHA1HashSize] | |||
) |
Definition at line 226 of file sha1.c.
References SHA1Context::Computed, SHA1Context::Corrupted, SHA1Context::Intermediate_Hash, SHA1Finalize(), shaNull, and shaSuccess.
Referenced by ast_sha1_hash().
00227 { 00228 int i; 00229 00230 if (!context) { 00231 return shaNull; 00232 } 00233 if (!Message_Digest) { 00234 return shaNull; 00235 } 00236 if (context->Corrupted) { 00237 return context->Corrupted; 00238 } 00239 00240 if (!context->Computed) { 00241 SHA1Finalize(context, 0x80); 00242 } 00243 00244 for (i = 0; i < SHA1HashSize; ++i) { 00245 Message_Digest[i] = (uint8_t) (context->Intermediate_Hash[i >> 2] 00246 >> (8 * (3 - (i & 0x03)))); 00247 } 00248 00249 return shaSuccess; 00250 }
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] | |||
) |