iPXE
sha256.h
Go to the documentation of this file.
1 #ifndef _IPXE_SHA256_H
2 #define _IPXE_SHA256_H
3 
4 /** @file
5  *
6  * SHA-256 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-256 number of rounds */
17 #define SHA256_ROUNDS 64
18 
19 /** An SHA-256 digest */
20 struct sha256_digest {
21  /** Hash output */
22  uint32_t h[8];
23 };
24 
25 /** An SHA-256 data block */
26 union sha256_block {
27  /** Raw bytes */
28  uint8_t byte[64];
29  /** Raw dwords */
31  /** Final block structure */
32  struct {
33  /** Padding */
34  uint8_t pad[56];
35  /** Length in bits */
37  } final;
38 };
39 
40 /** SHA-256 digest and data block
41  *
42  * The order of fields within this structure is designed to minimise
43  * code size.
44  */
46  /** Digest of data already processed */
48  /** Accumulated data */
50 } __attribute__ (( packed ));
51 
52 /** SHA-256 digest and data block */
54  /** Digest and data block */
56  /** Raw dwords */
57  uint32_t dword[ sizeof ( struct sha256_digest_data ) /
58  sizeof ( uint32_t ) ];
59 };
60 
61 /** An SHA-256 context */
63  /** Amount of accumulated data */
64  size_t len;
65  /** Digest size */
66  size_t digestsize;
67  /** Digest and accumulated data */
69 } __attribute__ (( packed ));
70 
71 /** SHA-256 context size */
72 #define SHA256_CTX_SIZE sizeof ( struct sha256_context )
73 
74 /** SHA-256 block size */
75 #define SHA256_BLOCK_SIZE sizeof ( union sha256_block )
76 
77 /** SHA-256 digest size */
78 #define SHA256_DIGEST_SIZE sizeof ( struct sha256_digest )
79 
80 /** SHA-224 digest size */
81 #define SHA224_DIGEST_SIZE ( SHA256_DIGEST_SIZE * 224 / 256 )
82 
83 extern void sha256_family_init ( struct sha256_context *context,
84  const struct sha256_digest *init,
85  size_t digestsize );
86 extern void sha256_update ( void *ctx, const void *data, size_t len );
87 extern void sha256_final ( void *ctx, void *out );
88 
91 
92 #endif /* _IPXE_SHA256_H */
#define __attribute__(x)
Definition: compiler.h:10
SHA-256 digest and data block.
Definition: sha256.h:45
FILE_SECBOOT(PERMITTED)
struct sha256_digest digest
Digest of data already processed.
Definition: sha256.h:47
unsigned long long uint64_t
Definition: stdint.h:13
Cryptographic API.
void sha256_family_init(struct sha256_context *context, const struct sha256_digest *init, size_t digestsize)
Initialise SHA-256 family algorithm.
Definition: sha256.c:93
size_t digestsize
Digest size.
Definition: sha256.h:66
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
__be32 out[4]
Definition: CIB_PRM.h:36
SHA-256 digest and data block.
Definition: sha256.h:53
uint32_t h[8]
Hash output.
Definition: sha256.h:22
struct digest_algorithm sha224_algorithm
SHA-224 algorithm.
Definition: sha224.c:64
void sha256_final(void *ctx, void *out)
Generate SHA-256 digest.
Definition: sha256.c:240
ring len
Length.
Definition: dwmac.h:231
uint8_t pad[56]
Padding.
Definition: sha256.h:34
An SHA-256 data block.
Definition: sha256.h:26
struct sha256_digest_data dd
Digest and data block.
Definition: sha256.h:55
size_t len
Amount of accumulated data.
Definition: sha256.h:64
uint64_t len
Length in bits.
Definition: sha256.h:36
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition: sha256.c:265
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
void sha256_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-256 algorithm.
Definition: sha256.c:217
union sha256_block data
Accumulated data.
Definition: sha256.h:49
A message digest algorithm.
Definition: crypto.h:19
uint8_t data[48]
Additional event data.
Definition: ena.h:22
union sha256_digest_data_dwords ddd
Digest and accumulated data.
Definition: sha256.h:68
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15
An SHA-256 context.
Definition: sha256.h:62
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An SHA-256 digest.
Definition: sha256.h:20
unsigned long int dword
Definition: smc9000.h:40