iPXE
sha512.h
Go to the documentation of this file.
1 #ifndef _IPXE_SHA512_H
2 #define _IPXE_SHA512_H
3 
4 /** @file
5  *
6  * SHA-512 algorithm
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/crypto.h>
15 
16 /** SHA-512 number of rounds */
17 #define SHA512_ROUNDS 80
18 
19 /** An SHA-512 digest */
20 struct sha512_digest {
21  /** Hash output */
22  uint64_t h[8];
23 };
24 
25 /** An SHA-512 data block */
26 union sha512_block {
27  /** Raw bytes */
28  uint8_t byte[128];
29  /** Raw qwords */
31  /** Final block structure */
32  struct {
33  /** Padding */
34  uint8_t pad[112];
35  /** High 64 bits of length in bits */
37  /** Low 64 bits of length in bits */
39  } final;
40 };
41 
42 /** SHA-512 digest and data block
43  *
44  * The order of fields within this structure is designed to minimise
45  * code size.
46  */
48  /** Digest of data already processed */
50  /** Accumulated data */
52 } __attribute__ (( packed ));
53 
54 /** SHA-512 digest and data block */
56  /** Digest and data block */
58  /** Raw qwords */
59  uint64_t qword[ sizeof ( struct sha512_digest_data ) /
60  sizeof ( uint64_t ) ];
61 };
62 
63 /** An SHA-512 context */
65  /** Amount of accumulated data */
66  size_t len;
67  /** Digest size */
68  size_t digestsize;
69  /** Digest and accumulated data */
71 } __attribute__ (( packed ));
72 
73 /** SHA-512 context size */
74 #define SHA512_CTX_SIZE sizeof ( struct sha512_context )
75 
76 /** SHA-512 block size */
77 #define SHA512_BLOCK_SIZE sizeof ( union sha512_block )
78 
79 /** SHA-512 digest size */
80 #define SHA512_DIGEST_SIZE sizeof ( struct sha512_digest )
81 
82 /** SHA-384 digest size */
83 #define SHA384_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 384 / 512 )
84 
85 /** SHA-512/256 digest size */
86 #define SHA512_256_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 256 / 512 )
87 
88 /** SHA-512/224 digest size */
89 #define SHA512_224_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 224 / 512 )
90 
91 extern void sha512_family_init ( struct sha512_context *context,
92  const struct sha512_digest *init,
93  size_t digestsize );
94 extern void sha512_update ( void *ctx, const void *data, size_t len );
95 extern void sha512_final ( void *ctx, void *out );
96 
101 
102 #endif /* IPXE_SHA512_H */
#define __attribute__(x)
Definition: compiler.h:10
struct sha512_digest digest
Digest of data already processed.
Definition: sha512.h:49
SHA-512 digest and data block.
Definition: sha512.h:55
struct digest_algorithm sha384_algorithm
SHA-384 algorithm.
Definition: sha384.c:64
struct digest_algorithm sha512_algorithm
SHA-512 algorithm.
Definition: sha512.c:285
unsigned long long uint64_t
Definition: stdint.h:13
uint64_t len_lo
Low 64 bits of length in bits.
Definition: sha512.h:38
Cryptographic API.
uint64_t qword[16]
Raw qwords.
Definition: sha512.h:30
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
__be32 out[4]
Definition: CIB_PRM.h:36
void sha512_family_init(struct sha512_context *context, const struct sha512_digest *init, size_t digestsize)
Initialise SHA-512 family algorithm.
Definition: sha512.c:109
FILE_SECBOOT(PERMITTED)
struct sha512_digest_data dd
Digest and data block.
Definition: sha512.h:57
void sha512_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-512 algorithm.
Definition: sha512.c:234
ring len
Length.
Definition: dwmac.h:231
uint64_t qword[sizeof(struct sha512_digest_data)/sizeof(uint64_t)]
Raw qwords.
Definition: sha512.h:60
An SHA-512 context.
Definition: sha512.h:64
struct digest_algorithm sha512_256_algorithm
SHA-512/256 algorithm.
Definition: sha512_256.c:65
An SHA-512 digest.
Definition: sha512.h:20
unsigned char uint8_t
Definition: stdint.h:10
An SHA-512 data block.
Definition: sha512.h:26
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition: sha512.h:70
uint8_t pad[112]
Padding.
Definition: sha512.h:34
uint64_t h[8]
Hash output.
Definition: sha512.h:22
size_t len
Amount of accumulated data.
Definition: sha512.h:66
SHA-512 digest and data block.
Definition: sha512.h:47
union sha512_block data
Accumulated data.
Definition: sha512.h:51
void sha512_final(void *ctx, void *out)
Generate SHA-512 digest.
Definition: sha512.c:257
A message digest algorithm.
Definition: crypto.h:19
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15
uint64_t len_hi
High 64 bits of length in bits.
Definition: sha512.h:36
struct digest_algorithm sha512_224_algorithm
SHA-512/224 algorithm.
Definition: sha512_224.c:65
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
size_t digestsize
Digest size.
Definition: sha512.h:68