iPXE
Data Structures | Macros | Functions | Variables
sha512.h File Reference

SHA-512 algorithm. More...

#include <stdint.h>
#include <ipxe/crypto.h>

Go to the source code of this file.

Data Structures

struct  sha512_digest
 An SHA-512 digest. More...
 
union  sha512_block
 An SHA-512 data block. More...
 
struct  sha512_digest_data
 SHA-512 digest and data block. More...
 
union  sha512_digest_data_qwords
 SHA-512 digest and data block. More...
 
struct  sha512_context
 An SHA-512 context. More...
 

Macros

#define SHA512_ROUNDS   80
 SHA-512 number of rounds. More...
 
#define SHA512_CTX_SIZE   sizeof ( struct sha512_context )
 SHA-512 context size. More...
 
#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )
 SHA-512 block size. More...
 
#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )
 SHA-512 digest size. More...
 
#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )
 SHA-384 digest size. More...
 
#define SHA512_256_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 256 / 512 )
 SHA-512/256 digest size. More...
 
#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )
 SHA-512/224 digest size. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct sha512_digest_data __attribute__ ((packed))
 
void sha512_family_init (struct sha512_context *context, const struct sha512_digest *init, size_t digestsize)
 Initialise SHA-512 family algorithm. More...
 
void sha512_update (void *ctx, const void *data, size_t len)
 Accumulate data with SHA-512 algorithm. More...
 
void sha512_final (void *ctx, void *out)
 Generate SHA-512 digest. More...
 

Variables

struct sha512_digest digest
 Digest of data already processed. More...
 
union sha512_block data
 Accumulated data. More...
 
union sha512_digest_data_qwords __attribute__
 
size_t len
 Amount of accumulated data. More...
 
size_t digestsize
 Digest size. More...
 
union sha512_digest_data_qwords ddq
 Digest and accumulated data. More...
 
struct digest_algorithm sha512_algorithm
 SHA-512 algorithm. More...
 
struct digest_algorithm sha384_algorithm
 SHA-384 algorithm. More...
 
struct digest_algorithm sha512_256_algorithm
 SHA-512/256 algorithm. More...
 
struct digest_algorithm sha512_224_algorithm
 SHA-512/224 algorithm. More...
 

Detailed Description

SHA-512 algorithm.

Definition in file sha512.h.

Macro Definition Documentation

◆ SHA512_ROUNDS

#define SHA512_ROUNDS   80

SHA-512 number of rounds.

Definition at line 16 of file sha512.h.

◆ SHA512_CTX_SIZE

#define SHA512_CTX_SIZE   sizeof ( struct sha512_context )

SHA-512 context size.

Definition at line 73 of file sha512.h.

◆ SHA512_BLOCK_SIZE

#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )

SHA-512 block size.

Definition at line 76 of file sha512.h.

◆ SHA512_DIGEST_SIZE

#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )

SHA-512 digest size.

Definition at line 79 of file sha512.h.

◆ SHA384_DIGEST_SIZE

#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )

SHA-384 digest size.

Definition at line 82 of file sha512.h.

◆ SHA512_256_DIGEST_SIZE

#define SHA512_256_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 256 / 512 )

SHA-512/256 digest size.

Definition at line 85 of file sha512.h.

◆ SHA512_224_DIGEST_SIZE

#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )

SHA-512/224 digest size.

Definition at line 88 of file sha512.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

struct sha512_digest_data __attribute__ ( (packed)  )

◆ sha512_family_init()

void sha512_family_init ( struct sha512_context context,
const struct sha512_digest init,
size_t  digestsize 
)

Initialise SHA-512 family algorithm.

Parameters
contextSHA-512 context
initInitial digest values
digestsizeDigest size

Definition at line 108 of file sha512.c.

110  {
111 
112  context->len = 0;
113  context->digestsize = digestsize;
114  memcpy ( &context->ddq.dd.digest, init,
115  sizeof ( context->ddq.dd.digest ) );
116 }
struct sha512_digest digest
Digest of data already processed.
Definition: sha512.h:48
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct sha512_digest_data dd
Digest and data block.
Definition: sha512.h:56
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition: sha512.h:69
size_t len
Amount of accumulated data.
Definition: sha512.h:65
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
size_t digestsize
Digest size.
Definition: sha512.h:67

References sha512_digest_data_qwords::dd, sha512_context::ddq, sha512_digest_data::digest, digestsize, sha512_context::digestsize, sha512_context::len, and memcpy().

Referenced by sha384_init(), sha512_224_init(), sha512_256_init(), and sha512_init().

◆ sha512_update()

void sha512_update ( void *  ctx,
const void *  data,
size_t  len 
)

Accumulate data with SHA-512 algorithm.

Parameters
ctxSHA-512 context
dataData
lenLength of data

Definition at line 233 of file sha512.c.

233  {
234  struct sha512_context *context = ctx;
235  const uint8_t *byte = data;
236  size_t offset;
237 
238  /* Accumulate data a byte at a time, performing the digest
239  * whenever we fill the data buffer
240  */
241  while ( len-- ) {
242  offset = ( context->len % sizeof ( context->ddq.dd.data ) );
243  context->ddq.dd.data.byte[offset] = *(byte++);
244  context->len++;
245  if ( ( context->len % sizeof ( context->ddq.dd.data ) ) == 0 )
246  sha512_digest ( context );
247  }
248 }
struct sha512_digest_data dd
Digest and data block.
Definition: sha512.h:56
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
An SHA-512 context.
Definition: sha512.h:63
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned char uint8_t
Definition: stdint.h:10
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition: sha512.h:69
size_t len
Amount of accumulated data.
Definition: sha512.h:65
union sha512_block data
Accumulated data.
Definition: sha512.h:50
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static void sha512_digest(struct sha512_context *context)
Calculate SHA-512 digest of accumulated data.
Definition: sha512.c:135
uint8_t byte[128]
Raw bytes.
Definition: sha512.h:27

References sha512_block::byte, ctx, data, sha512_digest_data::data, sha512_digest_data_qwords::dd, sha512_context::ddq, len, sha512_context::len, offset, and sha512_digest().

Referenced by sha512_final().

◆ sha512_final()

void sha512_final ( void *  ctx,
void *  out 
)

Generate SHA-512 digest.

Parameters
ctxSHA-512 context
outOutput buffer

Definition at line 256 of file sha512.c.

256  {
257  struct sha512_context *context = ctx;
258  uint64_t len_bits_hi;
259  uint64_t len_bits_lo;
260  uint8_t pad;
261 
262  /* Record length before pre-processing */
263  len_bits_hi = 0;
264  len_bits_lo = cpu_to_be64 ( ( ( uint64_t ) context->len ) * 8 );
265 
266  /* Pad with a single "1" bit followed by as many "0" bits as required */
267  pad = 0x80;
268  do {
269  sha512_update ( ctx, &pad, sizeof ( pad ) );
270  pad = 0x00;
271  } while ( ( context->len % sizeof ( context->ddq.dd.data ) ) !=
272  offsetof ( typeof ( context->ddq.dd.data ), final.len_hi ) );
273 
274  /* Append length (in bits) */
275  sha512_update ( ctx, &len_bits_hi, sizeof ( len_bits_hi ) );
276  sha512_update ( ctx, &len_bits_lo, sizeof ( len_bits_lo ) );
277  assert ( ( context->len % sizeof ( context->ddq.dd.data ) ) == 0 );
278 
279  /* Copy out final digest */
280  memcpy ( out, &context->ddq.dd.digest, context->digestsize );
281 }
void sha512_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-512 algorithm.
Definition: sha512.c:233
struct sha512_digest digest
Digest of data already processed.
Definition: sha512.h:48
unsigned long long uint64_t
Definition: stdint.h:13
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
u32 pad[9]
Padding.
Definition: ar9003_mac.h:90
__be32 out[4]
Definition: CIB_PRM.h:36
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct sha512_digest_data dd
Digest and data block.
Definition: sha512.h:56
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An SHA-512 context.
Definition: sha512.h:63
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned char uint8_t
Definition: stdint.h:10
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition: sha512.h:69
size_t len
Amount of accumulated data.
Definition: sha512.h:65
union sha512_block data
Accumulated data.
Definition: sha512.h:50
#define cpu_to_be64(value)
Definition: byteswap.h:111
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
size_t digestsize
Digest size.
Definition: sha512.h:67

References assert(), cpu_to_be64, ctx, sha512_digest_data::data, sha512_digest_data_qwords::dd, sha512_context::ddq, sha512_digest_data::digest, sha512_context::digestsize, sha512_context::len, memcpy(), offsetof, out, pad, sha512_update(), and typeof().

Variable Documentation

◆ digest

struct sha512_digest digest

Digest of data already processed.

Definition at line 12 of file sha512.h.

◆ data

union sha512_block data

Accumulated data.

Definition at line 14 of file sha512.h.

◆ __attribute__

◆ len

size_t len

Amount of accumulated data.

Definition at line 12 of file sha512.h.

◆ digestsize

size_t digestsize

Digest size.

Definition at line 14 of file sha512.h.

◆ ddq

Digest and accumulated data.

Definition at line 16 of file sha512.h.

◆ sha512_algorithm

struct digest_algorithm sha512_algorithm

SHA-512 algorithm.

Definition at line 284 of file sha512.c.

Referenced by peerdist_info_v1(), peerdist_info_v2(), and sha512_test_exec().

◆ sha384_algorithm

struct digest_algorithm sha384_algorithm

SHA-384 algorithm.

Definition at line 63 of file sha384.c.

Referenced by peerdist_info_v1(), and sha512_test_exec().

◆ sha512_256_algorithm

struct digest_algorithm sha512_256_algorithm

SHA-512/256 algorithm.

Definition at line 64 of file sha512_256.c.

Referenced by sha512_test_exec().

◆ sha512_224_algorithm

struct digest_algorithm sha512_224_algorithm

SHA-512/224 algorithm.

Definition at line 64 of file sha512_224.c.

Referenced by sha512_test_exec().