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 
12 #include <stdint.h>
13 #include <ipxe/crypto.h>
14 
15 /** SHA-256 number of rounds */
16 #define SHA256_ROUNDS 64
17 
18 /** An SHA-256 digest */
19 struct sha256_digest {
20  /** Hash output */
21  uint32_t h[8];
22 };
23 
24 /** An SHA-256 data block */
25 union sha256_block {
26  /** Raw bytes */
27  uint8_t byte[64];
28  /** Raw dwords */
30  /** Final block structure */
31  struct {
32  /** Padding */
33  uint8_t pad[56];
34  /** Length in bits */
36  } final;
37 };
38 
39 /** SHA-256 digest and data block
40  *
41  * The order of fields within this structure is designed to minimise
42  * code size.
43  */
45  /** Digest of data already processed */
47  /** Accumulated data */
49 } __attribute__ (( packed ));
50 
51 /** SHA-256 digest and data block */
53  /** Digest and data block */
55  /** Raw dwords */
56  uint32_t dword[ sizeof ( struct sha256_digest_data ) /
57  sizeof ( uint32_t ) ];
58 };
59 
60 /** An SHA-256 context */
62  /** Amount of accumulated data */
63  size_t len;
64  /** Digest size */
65  size_t digestsize;
66  /** Digest and accumulated data */
68 } __attribute__ (( packed ));
69 
70 /** SHA-256 context size */
71 #define SHA256_CTX_SIZE sizeof ( struct sha256_context )
72 
73 /** SHA-256 digest size */
74 #define SHA256_DIGEST_SIZE sizeof ( struct sha256_digest )
75 
76 /** SHA-224 digest size */
77 #define SHA224_DIGEST_SIZE ( SHA256_DIGEST_SIZE * 224 / 256 )
78 
79 extern void sha256_family_init ( struct sha256_context *context,
80  const struct sha256_digest *init,
81  size_t digestsize );
82 extern void sha256_update ( void *ctx, const void *data, size_t len );
83 extern void sha256_final ( void *ctx, void *out );
84 
87 
88 #endif /* _IPXE_SHA256_H */
union sha256_block data
Accumulated data.
Definition: sha256.h:14
SHA-256 digest and data block.
Definition: sha256.h:44
struct sha256_digest digest
Digest of data already processed.
Definition: sha256.h:46
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:92
union sha256_digest_data_dwords __attribute__
size_t digestsize
Digest size.
Definition: sha256.h:65
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
SHA-256 digest and data block.
Definition: sha256.h:52
uint32_t h[8]
Hash output.
Definition: sha256.h:21
struct digest_algorithm sha224_algorithm
SHA-224 algorithm.
Definition: sha224.c:63
void sha256_final(void *ctx, void *out)
Generate SHA-256 digest.
Definition: sha256.c:239
size_t len
Amount of accumulated data.
Definition: sha256.h:12
uint8_t pad[56]
Padding.
Definition: sha256.h:33
__be32 out[4]
Definition: CIB_PRM.h:36
An SHA-256 data block.
Definition: sha256.h:25
struct sha256_digest_data dd
Digest and data block.
Definition: sha256.h:54
size_t len
Amount of accumulated data.
Definition: sha256.h:63
uint64_t len
Length in bits.
Definition: sha256.h:35
size_t digestsize
Digest size.
Definition: sha256.h:14
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition: sha256.c:264
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:216
union sha256_block data
Accumulated data.
Definition: sha256.h:48
A message digest algorithm.
Definition: crypto.h:16
union sha256_digest_data_dwords ddd
Digest and accumulated data.
Definition: sha256.h:67
An SHA-256 context.
Definition: sha256.h:61
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An SHA-256 digest.
Definition: sha256.h:19
unsigned long int dword
Definition: smc9000.h:40