/build/ldns-00A0O8/ldns-1.8.4/sha2.c File Reference

Go to the source code of this file.

## Data Structures

union | _ldns_sha2_buffer_union

## Macros

#define | ldns_sha256_SHORT_BLOCK_LENGTH (LDNS_SHA256_BLOCK_LENGTH - 8)
#define | ldns_sha384_SHORT_BLOCK_LENGTH (LDNS_SHA384_BLOCK_LENGTH - 16)
#define | ldns_sha512_SHORT_BLOCK_LENGTH (LDNS_SHA512_BLOCK_LENGTH - 16)
#define | REVERSE32(w, x)
#define | REVERSE64(w, x)
#define | ADDINC128(w, n)
#define | SHA2_USE_MEMSET_MEMCPY 1
#define | MEMSET_BZERO(p, l)
#define | MEMCPY_BCOPY(d, s, l)
#define | R(b, x)
#define | S32(b, x)
#define | S64(b, x)
#define | Ch(x, y, z)
#define | Maj(x, y, z)
#define | Sigma0_256(x)
#define | Sigma1_256(x)
#define | sigma0_256(x)
#define | sigma1_256(x)
#define | Sigma0_512(x)
#define | Sigma1_512(x)
#define | sigma0_512(x)
#define | sigma1_512(x)

## Typedefs

typedef uint8_t | sha2_byte
typedef uint32_t | sha2_word32
typedef uint64_t | sha2_word64
typedef union _ldns_sha2_buffer_union | ldns_sha2_buffer_union

## Functions

void | ldns_sha256_init (ldns_sha256_CTX *context)
void | ldns_sha256_update (ldns_sha256_CTX *context, const sha2_byte *data, size_t len)
void | ldns_sha256_final (sha2_byte digest[32], ldns_sha256_CTX *context)
unsigned char * | ldns_sha256 (const unsigned char *data, unsigned int data_len, unsigned char *digest)
| Convenience function to digest a fixed block of data at once.
void | ldns_sha512_init (ldns_sha512_CTX *context)
void | ldns_sha512_update (ldns_sha512_CTX *context, const sha2_byte *data, size_t len)
void | ldns_sha512_final (sha2_byte digest[64], ldns_sha512_CTX *context)
unsigned char * | ldns_sha512 (const unsigned char *data, unsigned int data_len, unsigned char *digest)
| Convenience function to digest a fixed block of data at once.
void | ldns_sha384_init (ldns_sha384_CTX *context)
void | ldns_sha384_update (ldns_sha384_CTX *context, const sha2_byte *data, size_t len)
void | ldns_sha384_final (sha2_byte digest[48], ldns_sha384_CTX *context)
unsigned char * | ldns_sha384 (const unsigned char *data, unsigned int data_len, unsigned char *digest)
| Convenience function to digest a fixed block of data at once.

## Macro Definition Documentation

## ldns_sha256_SHORT_BLOCK_LENGTH

#define ldns_sha256_SHORT_BLOCK_LENGTH (LDNS_SHA256_BLOCK_LENGTH - 8)

Definition at line 111 of file sha2.c.

## ldns_sha384_SHORT_BLOCK_LENGTH

#define ldns_sha384_SHORT_BLOCK_LENGTH (LDNS_SHA384_BLOCK_LENGTH - 16)

Definition at line 112 of file sha2.c.

## ldns_sha512_SHORT_BLOCK_LENGTH

#define ldns_sha512_SHORT_BLOCK_LENGTH (LDNS_SHA512_BLOCK_LENGTH - 16)

Definition at line 113 of file sha2.c.

## REVERSE32

#define REVERSE32 | ( |  | w,
|  |  | x )

Value:
{ \
sha2_word32 tmp = (w); \
tmp = (tmp >> 16) | (tmp << 16); \
(x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
}
sha2_word32
uint32_t sha2_word32
Definition sha2.c:102

Definition at line 118 of file sha2.c.

## REVERSE64

#define REVERSE64 | ( |  | w,
|  |  | x )

Value:
{ \
sha2_word64 tmp = (w); \
tmp = (tmp >> 32) | (tmp << 32); \
tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
((tmp & 0x00ff00ff00ff00ffULL) << 8); \
(x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
((tmp & 0x0000ffff0000ffffULL) << 16); \
}
sha2_word64
uint64_t sha2_word64
Definition sha2.c:106

Definition at line 124 of file sha2.c.

## ADDINC128

#define ADDINC128 | ( |  | w,
|  |  | n )

Value:
{ \
(w)[0] += (sha2_word64)(n); \
if ((w)[0] < (n)) { \
(w)[1]++; \
} \
}

Definition at line 142 of file sha2.c.

## SHA2_USE_MEMSET_MEMCPY

#define SHA2_USE_MEMSET_MEMCPY 1

Definition at line 164 of file sha2.c.

## MEMSET_BZERO

#define MEMSET_BZERO | ( |  | p,
|  |  | l )

Value:
memset((p), 0, (l))

Definition at line 172 of file sha2.c.

## MEMCPY_BCOPY

#define MEMCPY_BCOPY | ( |  | d,
|  |  | s,
|  |  | l )

Value:
memcpy((d), (s), (l))

Definition at line 173 of file sha2.c.

## R

#define R | ( |  | b,
|  |  | x )

Value:
((x) >> (b))

Definition at line 191 of file sha2.c.

## S32

#define S32 | ( |  | b,
|  |  | x )

Value:
(((x) >> (b)) | ((x) << (32 - (b))))

Definition at line 193 of file sha2.c.

## S64

#define S64 | ( |  | b,
|  |  | x )

Value:
(((x) >> (b)) | ((x) << (64 - (b))))

Definition at line 195 of file sha2.c.

## Ch

#define Ch | ( |  | x,
|  |  | y,
|  |  | z )

Value:
(((x) & (y)) ^ ((~(x)) & (z)))

Definition at line 198 of file sha2.c.

## Maj

#define Maj | ( |  | x,
|  |  | y,
|  |  | z )

Value:
(((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))

Definition at line 199 of file sha2.c.

## Sigma0_256

#define Sigma0_256 | ( |  | x | ) |

Value:
(S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x)))
S32
#define S32(b, x)
Definition sha2.c:193

Definition at line 202 of file sha2.c.

## Sigma1_256

#define Sigma1_256 | ( |  | x | ) |

Value:
(S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x)))

Definition at line 203 of file sha2.c.

## sigma0_256

#define sigma0_256 | ( |  | x | ) |

Value:
(S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x)))
R
#define R(b, x)
Definition sha2.c:191

Definition at line 204 of file sha2.c.

## sigma1_256

#define sigma1_256 | ( |  | x | ) |

Value:
(S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x)))

Definition at line 205 of file sha2.c.

## Sigma0_512

#define Sigma0_512 | ( |  | x | ) |

Value:
(S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x)))
S64
#define S64(b, x)
Definition sha2.c:195

Definition at line 208 of file sha2.c.

## Sigma1_512

#define Sigma1_512 | ( |  | x | ) |

Value:
(S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x)))

Definition at line 209 of file sha2.c.

## sigma0_512

#define sigma0_512 | ( |  | x | ) |

Value:
(S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x)))

Definition at line 210 of file sha2.c.

## sigma1_512

#define sigma1_512 | ( |  | x | ) |

Value:
(S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x)))

Definition at line 211 of file sha2.c.

## Typedef Documentation

## sha2_byte

typedef uint8_t sha2_byte

Definition at line 101 of file sha2.c.

## sha2_word32

typedef uint32_t sha2_word32

Definition at line 102 of file sha2.c.

## sha2_word64

typedef uint64_t sha2_word64

Definition at line 106 of file sha2.c.

## ldns_sha2_buffer_union

typedef union _ldns_sha2_buffer_union ldns_sha2_buffer_union

## Function Documentation

## ldns_sha256_init()

void ldns_sha256_init | ( | ldns_sha256_CTX * | context | ) |

Definition at line 315 of file sha2.c.

References _ldns_sha256_CTX::bitcount, _ldns_sha256_CTX::buffer, LDNS_SHA256_BLOCK_LENGTH, LDNS_SHA256_DIGEST_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, and _ldns_sha256_CTX::state.

## ldns_sha256_update()

void ldns_sha256_update | ( | ldns_sha256_CTX * | context,
|  | const sha2_byte * | data,
|  | size_t | len )

Definition at line 502 of file sha2.c.

References _ldns_sha256_CTX::bitcount, _ldns_sha256_CTX::buffer, LDNS_SHA256_BLOCK_LENGTH, and MEMCPY_BCOPY.

## ldns_sha256_final()

void ldns_sha256_final | ( | sha2_byte | digest[32],
|  | ldns_sha256_CTX * | context )

Definition at line 557 of file sha2.c.

References _ldns_sha256_CTX::bitcount, _ldns_sha256_CTX::buffer, LDNS_SHA256_BLOCK_LENGTH, LDNS_SHA256_DIGEST_LENGTH, ldns_sha256_SHORT_BLOCK_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, REVERSE32, REVERSE64, _ldns_sha256_CTX::state, _ldns_sha2_buffer_union::theChars, and _ldns_sha2_buffer_union::theLongs.

## ldns_sha256()

unsigned char * ldns_sha256 | ( | const unsigned char * | data,
|  | unsigned int | data_len,
|  | unsigned char * | digest )

Convenience function to digest a fixed block of data at once.

Parameters

  [in] | data | the data to digest
  [in] | data_len | the length of data in bytes
  [out] | digest | the length of data in bytes This pointer MUST have LDNS_SHA256_DIGEST_LENGTH bytes available

Returns
  the SHA1 digest of the given data

Definition at line 624 of file sha2.c.

References ldns_sha256_final(), ldns_sha256_init(), and ldns_sha256_update().

## ldns_sha512_init()

void ldns_sha512_init | ( | ldns_sha512_CTX * | context | ) |

Definition at line 634 of file sha2.c.

References _ldns_sha512_CTX::bitcount, _ldns_sha512_CTX::buffer, LDNS_SHA512_BLOCK_LENGTH, LDNS_SHA512_DIGEST_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, and _ldns_sha512_CTX::state.

## ldns_sha512_update()

void ldns_sha512_update | ( | ldns_sha512_CTX * | context,
|  | const sha2_byte * | data,
|  | size_t | len )

Definition at line 815 of file sha2.c.

References ADDINC128, _ldns_sha512_CTX::bitcount, _ldns_sha512_CTX::buffer, LDNS_SHA512_BLOCK_LENGTH, and MEMCPY_BCOPY.

## ldns_sha512_final()

void ldns_sha512_final | ( | sha2_byte | digest[64],
|  | ldns_sha512_CTX * | context )

Definition at line 908 of file sha2.c.

References LDNS_SHA512_DIGEST_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, REVERSE64, and _ldns_sha512_CTX::state.

## ldns_sha512()

unsigned char * ldns_sha512 | ( | const unsigned char * | data,
|  | unsigned int | data_len,
|  | unsigned char * | digest )

Convenience function to digest a fixed block of data at once.

Parameters

  [in] | data | the data to digest
  [in] | data_len | the length of data in bytes
  [out] | digest | the length of data in bytes This pointer MUST have LDNS_SHA512_DIGEST_LENGTH bytes available

Returns
  the SHA1 digest of the given data

Definition at line 938 of file sha2.c.

References ldns_sha512_final(), ldns_sha512_init(), and ldns_sha512_update().

## ldns_sha384_init()

void ldns_sha384_init | ( | ldns_sha384_CTX * | context | ) |

Definition at line 948 of file sha2.c.

References _ldns_sha512_CTX::bitcount, _ldns_sha512_CTX::buffer, LDNS_SHA384_BLOCK_LENGTH, LDNS_SHA512_DIGEST_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, and _ldns_sha512_CTX::state.

## ldns_sha384_update()

void ldns_sha384_update | ( | ldns_sha384_CTX * | context,
|  | const sha2_byte * | data,
|  | size_t | len )

Definition at line 957 of file sha2.c.

References ldns_sha512_update().

## ldns_sha384_final()

void ldns_sha384_final | ( | sha2_byte | digest[48],
|  | ldns_sha384_CTX * | context )

Definition at line 961 of file sha2.c.

References LDNS_SHA384_DIGEST_LENGTH, MEMCPY_BCOPY, MEMSET_BZERO, REVERSE64, and _ldns_sha512_CTX::state.

## ldns_sha384()

unsigned char * ldns_sha384 | ( | const unsigned char * | data,
|  | unsigned int | data_len,
|  | unsigned char * | digest )

Convenience function to digest a fixed block of data at once.

Parameters

  [in] | data | the data to digest
  [in] | data_len | the length of data in bytes
  [out] | digest | the length of data in bytes This pointer MUST have LDNS_SHA384_DIGEST_LENGTH bytes available

Returns
  the SHA1 digest of the given data

Definition at line 991 of file sha2.c.

References ldns_sha384_final(), ldns_sha384_init(), and ldns_sha384_update().