libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
sha256.c File Reference
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "decls.h"`
`#include "sha256.h"`

Go to the source code of this file.

## Macros
#define | AARU_LOCAL static
#define | ROTR32(x, n)
#define | Ch(x, y, z)
#define | Maj(x, y, z)
#define | SIGMA0(x)
#define | SIGMA1(x)
#define | sigma0(x)
#define | sigma1(x)

## Functions
static void | sha256_transform (uint32_t state[8], const uint8_t block[64])
void | aaruf_sha256_init (sha256_ctx *ctx)
void | aaruf_sha256_update (sha256_ctx *ctx, const void *data_ptr, unsigned long len)
void | aaruf_sha256_final (sha256_ctx *ctx, unsigned char *out)
void | aaruf_sha256_buffer (const void *data, unsigned long size, unsigned char *result)

## Variables
static const uint32_t | K [64]

## Macro Definition Documentation

## ◆ AARU_LOCAL

#define AARU_LOCAL static

Definition at line 15 of file sha256.c.

## ◆ Ch

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

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

Definition at line 24 of file sha256.c.

Referenced by sha256_transform().

## ◆ Maj

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

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

Definition at line 25 of file sha256.c.

Referenced by sha256_transform().

## ◆ ROTR32

#define ROTR32 | ( |  | x,
|  |  | n )

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

Definition at line 21 of file sha256.c.

## ◆ SIGMA0

#define SIGMA0 | ( |  | x | ) |

Value:
(ROTR32((x), 2) ^ ROTR32((x), 13) ^ ROTR32((x), 22))
ROTR32
#define ROTR32(x, n)
Definition sha256.c:21

Definition at line 26 of file sha256.c.

Referenced by sha256_transform().

## ◆ sigma0

#define sigma0 | ( |  | x | ) |

Value:
(ROTR32((x), 7) ^ ROTR32((x), 18) ^ ((x) >> 3))

Definition at line 28 of file sha256.c.

Referenced by sha256_transform().

## ◆ SIGMA1

#define SIGMA1 | ( |  | x | ) |

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

Definition at line 27 of file sha256.c.

Referenced by sha256_transform().

## ◆ sigma1

#define sigma1 | ( |  | x | ) |

Value:
(ROTR32((x), 17) ^ ROTR32((x), 19) ^ ((x) >> 10))

Definition at line 29 of file sha256.c.

Referenced by sha256_transform().

## Function Documentation

## ◆ aaruf_sha256_buffer()

void aaruf_sha256_buffer | ( | const void * | data,
|  | unsigned long | size,
|  | unsigned char * | result )

Definition at line 141 of file sha256.c.

References AARU_CALL, AARU_EXPORT, aaruf_sha256_final(), aaruf_sha256_init(), and aaruf_sha256_update().

## ◆ aaruf_sha256_final()

void aaruf_sha256_final | ( | sha256_ctx * | ctx,
|  | unsigned char * | out )

Definition at line 115 of file sha256.c.

References AARU_CALL, AARU_EXPORT, aaruf_sha256_update(), sha256_ctx::bitcount, sha256_ctx::buffer, and sha256_ctx::state.

Referenced by aaruf_sha256_buffer(), and write_checksum_block().

## ◆ aaruf_sha256_init()

void aaruf_sha256_init | ( | sha256_ctx * | ctx | ) |

Definition at line 76 of file sha256.c.

References AARU_CALL, AARU_EXPORT, sha256_ctx::bitcount, sha256_ctx::buffer, and sha256_ctx::state.

Referenced by aaruf_create(), and aaruf_sha256_buffer().

## ◆ aaruf_sha256_update()

void aaruf_sha256_update | ( | sha256_ctx * | ctx,
|  | const void * | data_ptr,
|  | unsigned long | len )

Definition at line 90 of file sha256.c.

References AARU_CALL, AARU_EXPORT, sha256_ctx::bitcount, sha256_ctx::buffer, sha256_transform(), and sha256_ctx::state.

Referenced by aaruf_sha256_buffer(), aaruf_sha256_final(), aaruf_write_sector(), and aaruf_write_sector_long().

## ◆ sha256_transform()

void sha256_transform | ( | uint32_t | state[8],
|  | const uint8_t | block[64] )
| static

Definition at line 41 of file sha256.c.

References AARU_LOCAL, Ch, K, Maj, SIGMA0, sigma0, SIGMA1, and sigma1.

Referenced by aaruf_sha256_update().

## Variable Documentation

## ◆ K

const uint32_t K[64]
| static

Initial value:
= {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}

Definition at line 31 of file sha256.c.

Referenced by sha256_transform().