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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <endian.h>
15#include <ipxe/crypto.h>
16#include <ipxe/mdhash.h>
17
18/** SHA-256 number of rounds */
19#define SHA256_ROUNDS 64
20
21/** An SHA-256 digest */
23 /** Hash output */
25};
26
27/** An SHA-256 data block */
29 /** Raw bytes */
30 uint8_t byte[64];
31 /** Raw dwords */
33 /** Final block structure */
34 struct {
35 /** Padding */
37 /** Length in bits */
39 } final;
40};
41
42/** SHA-256 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-256 context size */
55#define SHA256_CTX_SIZE MDHASH_CTX_SIZE ( struct sha256_digest_data )
56
57/** SHA-256 block size */
58#define SHA256_BLOCK_SIZE sizeof ( union sha256_block )
59
60/** SHA-256 digest size */
61#define SHA256_DIGEST_SIZE sizeof ( struct sha256_digest )
62
63/** SHA-224 digest size */
64#define SHA224_DIGEST_SIZE ( SHA256_DIGEST_SIZE * 224 / 256 )
65
66extern void sha256_compress ( struct sha256_digest_data *dd,
67 const struct sha256_digest *digest );
68
69/** Define a SHA-256 family digest algorithm */
70#define SHA256_ALGORITHM( _name, _digest, _init, _digestsize ) \
71 MDHASH_ALGORITHM( _name, _digest, sha256_compress, \
72 __BIG_ENDIAN, struct sha256_digest_data, \
73 _init, _digestsize )
74
77
78#endif /* _IPXE_SHA256_H */
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
Merkle-Damgård hash algorithms.
struct digest_algorithm sha224_algorithm
void sha256_compress(struct sha256_digest_data *dd, const struct sha256_digest *digest)
Calculate SHA-256 digest of accumulated data.
Definition sha256.c:83
struct digest_algorithm sha256_algorithm
A message digest algorithm.
Definition crypto.h:19
SHA-256 digest and data block.
Definition sha256.h:47
struct sha256_digest digest
Digest of data already processed.
Definition sha256.h:49
union sha256_block data
Accumulated data.
Definition sha256.h:51
An SHA-256 digest.
Definition sha256.h:22
uint32_t h[8]
Hash output.
Definition sha256.h:24
An SHA-256 data block.
Definition sha256.h:28
uint64_t len
Length in bits.
Definition sha256.h:38
uint8_t pad[56]
Padding.
Definition sha256.h:36
uint32_t dword[16]
Raw dwords.
Definition sha256.h:32