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 
12 #include <stdint.h>
13 #include <ipxe/crypto.h>
14 
15 /** SHA-512 number of rounds */
16 #define SHA512_ROUNDS 80
17 
18 /** An SHA-512 digest */
19 struct sha512_digest {
20  /** Hash output */
21  uint64_t h[8];
22 };
23 
24 /** An SHA-512 data block */
25 union sha512_block {
26  /** Raw bytes */
27  uint8_t byte[128];
28  /** Raw qwords */
30  /** Final block structure */
31  struct {
32  /** Padding */
33  uint8_t pad[112];
34  /** High 64 bits of length in bits */
36  /** Low 64 bits of length in bits */
38  } final;
39 };
40 
41 /** SHA-512 digest and data block
42  *
43  * The order of fields within this structure is designed to minimise
44  * code size.
45  */
47  /** Digest of data already processed */
49  /** Accumulated data */
51 } __attribute__ (( packed ));
52 
53 /** SHA-512 digest and data block */
55  /** Digest and data block */
57  /** Raw qwords */
58  uint64_t qword[ sizeof ( struct sha512_digest_data ) /
59  sizeof ( uint64_t ) ];
60 };
61 
62 /** An SHA-512 context */
64  /** Amount of accumulated data */
65  size_t len;
66  /** Digest size */
67  size_t digestsize;
68  /** Digest and accumulated data */
70 } __attribute__ (( packed ));
71 
72 /** SHA-512 context size */
73 #define SHA512_CTX_SIZE sizeof ( struct sha512_context )
74 
75 /** SHA-512 digest size */
76 #define SHA512_DIGEST_SIZE sizeof ( struct sha512_digest )
77 
78 /** SHA-384 digest size */
79 #define SHA384_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 384 / 512 )
80 
81 /** SHA-512/256 digest size */
82 #define SHA512_256_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 256 / 512 )
83 
84 /** SHA-512/224 digest size */
85 #define SHA512_224_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 224 / 512 )
86 
87 extern void sha512_family_init ( struct sha512_context *context,
88  const struct sha512_digest *init,
89  size_t digestsize );
90 extern void sha512_update ( void *ctx, const void *data, size_t len );
91 extern void sha512_final ( void *ctx, void *out );
92 
97 
98 #endif /* IPXE_SHA512_H */
struct sha512_digest digest
Digest of data already processed.
Definition: sha512.h:48
SHA-512 digest and data block.
Definition: sha512.h:54
size_t digestsize
Digest size.
Definition: sha512.h:14
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:37
Cryptographic API.
uint64_t qword[16]
Raw qwords.
Definition: sha512.h:29
union sha512_block data
Accumulated data.
Definition: sha512.h:14
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
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
struct sha512_digest_data dd
Digest and data block.
Definition: sha512.h:56
union sha512_digest_data_qwords __attribute__
void sha512_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-512 algorithm.
Definition: sha512.c:234
__be32 out[4]
Definition: CIB_PRM.h:36
uint64_t qword[sizeof(struct sha512_digest_data)/sizeof(uint64_t)]
Raw qwords.
Definition: sha512.h:59
An SHA-512 context.
Definition: sha512.h:63
size_t len
Amount of accumulated data.
Definition: sha512.h:12
struct digest_algorithm sha512_256_algorithm
SHA-512/256 algorithm.
Definition: sha512_256.c:65
An SHA-512 digest.
Definition: sha512.h:19
unsigned char uint8_t
Definition: stdint.h:10
An SHA-512 data block.
Definition: sha512.h:25
union sha512_digest_data_qwords ddq
Digest and accumulated data.
Definition: sha512.h:69
uint8_t pad[112]
Padding.
Definition: sha512.h:33
uint64_t h[8]
Hash output.
Definition: sha512.h:21
size_t len
Amount of accumulated data.
Definition: sha512.h:65
SHA-512 digest and data block.
Definition: sha512.h:46
union sha512_block data
Accumulated data.
Definition: sha512.h:50
void sha512_final(void *ctx, void *out)
Generate SHA-512 digest.
Definition: sha512.c:257
A message digest algorithm.
Definition: crypto.h:16
uint64_t len_hi
High 64 bits of length in bits.
Definition: sha512.h:35
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:67