iPXE
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.
#define SHA512_CTX_SIZE   sizeof ( struct sha512_context )
 SHA-512 context size.
#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )
 SHA-512 block size.
#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )
 SHA-512 digest size.
#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )
 SHA-384 digest size.
#define SHA512_256_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 256 / 512 )
 SHA-512/256 digest size.
#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )
 SHA-512/224 digest size.

Functions

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

Variables

struct digest_algorithm sha512_algorithm
 SHA-512 algorithm.
struct digest_algorithm sha384_algorithm
 SHA-384 algorithm.
struct digest_algorithm sha512_256_algorithm
 SHA-512/256 algorithm.
struct digest_algorithm sha512_224_algorithm
 SHA-512/224 algorithm.

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 17 of file sha512.h.

Referenced by sha512_digest().

◆ SHA512_CTX_SIZE

#define SHA512_CTX_SIZE   sizeof ( struct sha512_context )

SHA-512 context size.

Definition at line 74 of file sha512.h.

◆ SHA512_BLOCK_SIZE

#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )

SHA-512 block size.

Definition at line 77 of file sha512.h.

◆ SHA512_DIGEST_SIZE

#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )

SHA-512 digest size.

Definition at line 80 of file sha512.h.

◆ SHA384_DIGEST_SIZE

#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )

SHA-384 digest size.

Definition at line 83 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 86 of file sha512.h.

Referenced by sha512_256_init().

◆ SHA512_224_DIGEST_SIZE

#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )

SHA-512/224 digest size.

Definition at line 89 of file sha512.h.

Referenced by sha512_224_init().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ sha512_family_init()

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

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}
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t digestsize
Digest size (i.e.
Definition pccrr.h:1
size_t digestsize
Digest size.
Definition sha512.h:68
size_t len
Amount of accumulated data.
Definition sha512.h:66
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition sha512.h:70
struct sha512_digest digest
Digest of data already processed.
Definition sha512.h:49
struct sha512_digest_data dd
Digest and data block.
Definition sha512.h:57

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 )
extern

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:0
unsigned char uint8_t
Definition stdint.h:10
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
static void sha512_digest(struct sha512_context *context)
Calculate SHA-512 digest of accumulated data.
Definition sha512.c:136
An SHA-512 context.
Definition sha512.h:64
union sha512_block data
Accumulated data.
Definition sha512.h:51
uint8_t byte[128]
Raw bytes.
Definition sha512.h:28

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 )
extern

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}
__be32 out[4]
Definition CIB_PRM.h:8
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
u32 pad[9]
Padding.
Definition ar9003_mac.h:23
unsigned long long uint64_t
Definition stdint.h:13
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define cpu_to_be64(value)
Definition byteswap.h:112
void sha512_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-512 algorithm.
Definition sha512.c:234
#define offsetof(type, field)
Get offset of a field within a structure.
Definition stddef.h:25

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

◆ sha512_algorithm

struct digest_algorithm sha512_algorithm
extern

SHA-512 algorithm.

Definition at line 285 of file sha512.c.

285 {
286 .name = "sha512",
287 .ctxsize = sizeof ( struct sha512_context ),
288 .blocksize = sizeof ( union sha512_block ),
289 .digestsize = sizeof ( struct sha512_digest ),
290 .init = sha512_init,
291 .update = sha512_update,
292 .final = sha512_final,
293};
void sha512_final(void *ctx, void *out)
Generate SHA-512 digest.
Definition sha512.c:257
static void sha512_init(void *ctx)
Initialise SHA-512 algorithm.
Definition sha512.c:124
An SHA-512 digest.
Definition sha512.h:20
An SHA-512 data block.
Definition sha512.h:26

Referenced by DIGEST_TEST(), DIGEST_TEST(), DIGEST_TEST(), PEERDIST_INFO_TEST(), peerdist_info_v1(), peerdist_info_v2(), PUBKEY_SIGN_TEST(), PUBKEY_SIGN_TEST(), sha512_test_exec(), and sha512sum_exec().

◆ sha384_algorithm

struct digest_algorithm sha384_algorithm
extern

SHA-384 algorithm.

Definition at line 64 of file sha384.c.

64 {
65 .name = "sha384",
66 .ctxsize = sizeof ( struct sha512_context ),
67 .blocksize = sizeof ( union sha512_block ),
69 .init = sha384_init,
70 .update = sha512_update,
71 .final = sha512_final,
72};
#define SHA384_DIGEST_SIZE
Definition Tpm20.h:34
static void sha384_init(void *ctx)
Initialise SHA-384 algorithm.
Definition sha384.c:57

Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), DIGEST_TEST(), DIGEST_TEST(), DIGEST_TEST(), peerdist_info_v1(), sha384sum_exec(), and sha512_test_exec().

◆ sha512_256_algorithm

struct digest_algorithm sha512_256_algorithm
extern

SHA-512/256 algorithm.

Definition at line 65 of file sha512_256.c.

65 {
66 .name = "sha512/256",
67 .ctxsize = sizeof ( struct sha512_context ),
68 .blocksize = sizeof ( union sha512_block ),
70 .init = sha512_256_init,
71 .update = sha512_update,
72 .final = sha512_final,
73};
#define SHA512_256_DIGEST_SIZE
SHA-512/256 digest size.
Definition sha512.h:86
static void sha512_256_init(void *ctx)
Initialise SHA-512/256 algorithm.
Definition sha512_256.c:57

Referenced by DIGEST_TEST(), DIGEST_TEST(), DIGEST_TEST(), and sha512_test_exec().

◆ sha512_224_algorithm

struct digest_algorithm sha512_224_algorithm
extern

SHA-512/224 algorithm.

Definition at line 65 of file sha512_224.c.

65 {
66 .name = "sha512/224",
67 .ctxsize = sizeof ( struct sha512_context ),
68 .blocksize = sizeof ( union sha512_block ),
70 .init = sha512_224_init,
71 .update = sha512_update,
72 .final = sha512_final,
73};
#define SHA512_224_DIGEST_SIZE
SHA-512/224 digest size.
Definition sha512.h:89
static void sha512_224_init(void *ctx)
Initialise SHA-512/224 algorithm.
Definition sha512_224.c:57

Referenced by DIGEST_TEST(), DIGEST_TEST(), DIGEST_TEST(), and sha512_test_exec().