iPXE
include
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 */
30
uint32_t
dword
[16];
31
/** Final block structure */
32
struct
{
33
/** Padding */
34
uint8_t
pad
[56];
35
/** Length in bits */
36
uint64_t
len
;
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
*/
45
struct
sha256_digest_data
{
46
/** Digest of data already processed */
47
struct
sha256_digest
digest
;
48
/** Accumulated data */
49
union
sha256_block
data
;
50
}
__attribute__
(( packed ));
51
52
/** SHA-256 digest and data block */
53
union
sha256_digest_data_dwords
{
54
/** Digest and data block */
55
struct
sha256_digest_data
dd
;
56
/** Raw dwords */
57
uint32_t
dword
[
sizeof
(
struct
sha256_digest_data
) /
58
sizeof (
uint32_t
) ];
59
};
60
61
/** An SHA-256 context */
62
struct
sha256_context
{
63
/** Amount of accumulated data */
64
size_t
len
;
65
/** Digest size */
66
size_t
digestsize
;
67
/** Digest and accumulated data */
68
union
sha256_digest_data_dwords
ddd
;
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
89
extern
struct
digest_algorithm
sha256_algorithm
;
90
extern
struct
digest_algorithm
sha224_algorithm
;
91
92
#endif
/* _IPXE_SHA256_H */
__attribute__
#define __attribute__(x)
Definition:
compiler.h:10
sha256_digest_data
SHA-256 digest and data block.
Definition:
sha256.h:45
FILE_SECBOOT
FILE_SECBOOT(PERMITTED)
sha256_digest_data::digest
struct sha256_digest digest
Digest of data already processed.
Definition:
sha256.h:47
uint64_t
unsigned long long uint64_t
Definition:
stdint.h:13
crypto.h
Cryptographic API.
sha256_family_init
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
sha256_context::digestsize
size_t digestsize
Digest size.
Definition:
sha256.h:66
ctx
struct golan_eq_context ctx
Definition:
CIB_PRM.h:28
out
__be32 out[4]
Definition:
CIB_PRM.h:36
sha256_digest_data_dwords
SHA-256 digest and data block.
Definition:
sha256.h:53
sha256_digest::h
uint32_t h[8]
Hash output.
Definition:
sha256.h:22
sha224_algorithm
struct digest_algorithm sha224_algorithm
SHA-224 algorithm.
Definition:
sha224.c:64
sha256_final
void sha256_final(void *ctx, void *out)
Generate SHA-256 digest.
Definition:
sha256.c:240
len
ring len
Length.
Definition:
dwmac.h:231
sha256_block::pad
uint8_t pad[56]
Padding.
Definition:
sha256.h:34
sha256_block
An SHA-256 data block.
Definition:
sha256.h:26
sha256_digest_data_dwords::dd
struct sha256_digest_data dd
Digest and data block.
Definition:
sha256.h:55
sha256_context::len
size_t len
Amount of accumulated data.
Definition:
sha256.h:64
sha256_block::len
uint64_t len
Length in bits.
Definition:
sha256.h:36
sha256_algorithm
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition:
sha256.c:265
uint8_t
unsigned char uint8_t
Definition:
stdint.h:10
uint32_t
unsigned int uint32_t
Definition:
stdint.h:12
sha256_update
void sha256_update(void *ctx, const void *data, size_t len)
Accumulate data with SHA-256 algorithm.
Definition:
sha256.c:217
sha256_digest_data::data
union sha256_block data
Accumulated data.
Definition:
sha256.h:49
digest_algorithm
A message digest algorithm.
Definition:
crypto.h:19
data
uint8_t data[48]
Additional event data.
Definition:
ena.h:22
stdint.h
sha256_context::ddd
union sha256_digest_data_dwords ddd
Digest and accumulated data.
Definition:
sha256.h:68
digestsize
uint32_t digestsize
Digest size (i.e.
Definition:
pccrr.h:15
sha256_context
An SHA-256 context.
Definition:
sha256.h:62
FILE_LICENCE
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
sha256_digest
An SHA-256 digest.
Definition:
sha256.h:20
dword
unsigned long int dword
Definition:
smc9000.h:40
Generated by
1.8.15