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_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_DIGEST_SIZE

#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )

SHA-512 digest size.

Definition at line 76 of file sha512.h.

◆ SHA384_DIGEST_SIZE

#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )

SHA-384 digest size.

Definition at line 79 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 82 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 85 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 109 of file sha512.c.

111  {
112 
113  context->len = 0;
114  context->digestsize = digestsize;
115  memcpy ( &context->ddq.dd.digest, init,
116  sizeof ( context->ddq.dd.digest ) );
117 }
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 234 of file sha512.c.

234  {
235  struct sha512_context *context = ctx;
236  const uint8_t *byte = data;
237  size_t offset;
238 
239  /* Accumulate data a byte at a time, performing the digest
240  * whenever we fill the data buffer
241  */
242  while ( len-- ) {
243  offset = ( context->len % sizeof ( context->ddq.dd.data ) );
244  context->ddq.dd.data.byte[offset] = *(byte++);
245  context->len++;
246  if ( ( context->len % sizeof ( context->ddq.dd.data ) ) == 0 )
247  sha512_digest ( context );
248  }
249 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
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
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
static void sha512_digest(struct sha512_context *context)
Calculate SHA-512 digest of accumulated data.
Definition: sha512.c:136
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
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 257 of file sha512.c.

257  {
258  struct sha512_context *context = ctx;
259  uint64_t len_bits_hi;
260  uint64_t len_bits_lo;
261  uint8_t pad;
262 
263  /* Record length before pre-processing */
264  len_bits_hi = 0;
265  len_bits_lo = cpu_to_be64 ( ( ( uint64_t ) context->len ) * 8 );
266 
267  /* Pad with a single "1" bit followed by as many "0" bits as required */
268  pad = 0x80;
269  do {
270  sha512_update ( ctx, &pad, sizeof ( pad ) );
271  pad = 0x00;
272  } while ( ( context->len % sizeof ( context->ddq.dd.data ) ) !=
273  offsetof ( typeof ( context->ddq.dd.data ), final.len_hi ) );
274 
275  /* Append length (in bits) */
276  sha512_update ( ctx, &len_bits_hi, sizeof ( len_bits_hi ) );
277  sha512_update ( ctx, &len_bits_lo, sizeof ( len_bits_lo ) );
278  assert ( ( context->len % sizeof ( context->ddq.dd.data ) ) == 0 );
279 
280  /* Copy out final digest */
281  memcpy ( out, &context->ddq.dd.digest, context->digestsize );
282 }
void sha512_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-512 algorithm.
Definition: sha512.c:234
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
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
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)
__be32 out[4]
Definition: CIB_PRM.h:36
An SHA-512 context.
Definition: sha512.h:63
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
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, and sha512_update().

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 285 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 64 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 65 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 65 of file sha512_224.c.

Referenced by sha512_test_exec().