iPXE
sha512.h File Reference

SHA-512 algorithm. More...

#include <stdint.h>
#include <endian.h>
#include <ipxe/crypto.h>
#include <ipxe/mdhash.h>

Go to the source code of this file.

Data Structures

struct  sha512_digest
 An SHA-512 digest. More...
union  sha512_block
 An SHA-512 data block. More...
struct  sha512_digest_data
 SHA-512 digest and data block. More...

Macros

#define SHA512_ROUNDS   80
 SHA-512 number of rounds.
#define SHA512_CTX_SIZE   MDHASH_CTX_SIZE ( struct sha512_digest_data )
 SHA-512 context size.
#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )
 SHA-512 block size.
#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )
 SHA-512 digest size.
#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )
 SHA-384 digest size.
#define SHA512_256_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 256 / 512 )
 SHA-512/256 digest size.
#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )
 SHA-512/224 digest size.
#define SHA512_ALGORITHM(_name, _digest, _init, _digestsize)
 Define a SHA-512 family digest algorithm.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void sha512_compress (struct sha512_digest_data *dd, const struct sha512_digest *digest)
 Calculate SHA-512 digest of accumulated data.

Variables

struct digest_algorithm sha512_algorithm
struct digest_algorithm sha384_algorithm
struct digest_algorithm sha512_256_algorithm
struct digest_algorithm sha512_224_algorithm

Detailed Description

SHA-512 algorithm.

Definition in file sha512.h.

Macro Definition Documentation

◆ SHA512_ROUNDS

#define SHA512_ROUNDS   80

SHA-512 number of rounds.

Definition at line 19 of file sha512.h.

Referenced by sha512_compress().

◆ SHA512_CTX_SIZE

#define SHA512_CTX_SIZE   MDHASH_CTX_SIZE ( struct sha512_digest_data )

SHA-512 context size.

Definition at line 60 of file sha512.h.

◆ SHA512_BLOCK_SIZE

#define SHA512_BLOCK_SIZE   sizeof ( union sha512_block )

SHA-512 block size.

Definition at line 63 of file sha512.h.

◆ SHA512_DIGEST_SIZE

#define SHA512_DIGEST_SIZE   sizeof ( struct sha512_digest )

SHA-512 digest size.

Definition at line 66 of file sha512.h.

◆ SHA384_DIGEST_SIZE

#define SHA384_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 384 / 512 )

SHA-384 digest size.

Definition at line 69 of file sha512.h.

◆ SHA512_256_DIGEST_SIZE

#define SHA512_256_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 256 / 512 )

SHA-512/256 digest size.

Definition at line 72 of file sha512.h.

Referenced by SHA512_ALGORITHM().

◆ SHA512_224_DIGEST_SIZE

#define SHA512_224_DIGEST_SIZE   ( SHA512_DIGEST_SIZE * 224 / 512 )

SHA-512/224 digest size.

Definition at line 75 of file sha512.h.

Referenced by SHA512_ALGORITHM().

◆ SHA512_ALGORITHM

#define SHA512_ALGORITHM ( _name,
_digest,
_init,
_digestsize )
Value:
MDHASH_ALGORITHM( _name, _digest, sha512_compress, \
_init, _digestsize )
#define __BIG_ENDIAN
Constant representing big-endian byte order.
Definition endian.h:22
#define MDHASH_ALGORITHM(_name, _digest, _compress, _byteorder, _dd, _init, _digestsize)
Define a Merkle-Damgård hash algorithm.
Definition mdhash.h:137
void sha512_compress(struct sha512_digest_data *dd, const struct sha512_digest *digest)
Calculate SHA-512 digest of accumulated data.
Definition sha512.c:101
SHA-512 digest and data block.
Definition sha512.h:52

Define a SHA-512 family digest algorithm.

Definition at line 81 of file sha512.h.

81#define SHA512_ALGORITHM( _name, _digest, _init, _digestsize ) \
82 MDHASH_ALGORITHM( _name, _digest, sha512_compress, \
83 __BIG_ENDIAN, struct sha512_digest_data, \
84 _init, _digestsize )

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ sha512_compress()

void sha512_compress ( struct sha512_digest_data * dd,
const struct sha512_digest * digest )
extern

Calculate SHA-512 digest of accumulated data.

Parameters
ddDigest and data block
digestCopy of current digest value

Definition at line 101 of file sha512.c.

102 {
103 union {
104 struct sha512_digest_data dd;
105 struct sha512_variables v;
106 } *u = container_of ( dd, typeof ( *u ), dd );
107 struct sha512_variables *v = &u->v;
108 uint64_t *a = &v->a;
109 uint64_t *b = &v->b;
110 uint64_t *c = &v->c;
111 uint64_t *d = &v->d;
112 uint64_t *e = &v->e;
113 uint64_t *f = &v->f;
114 uint64_t *g = &v->g;
115 uint64_t *h = &v->h;
116 uint64_t *w = v->w;
117 uint64_t s0;
118 uint64_t s1;
119 uint64_t maj;
120 uint64_t t1;
121 uint64_t t2;
122 uint64_t ch;
123 unsigned int i;
124
125 /* Sanity checks */
126 build_assert ( &u->dd.digest.h[0] == a );
127 build_assert ( &u->dd.digest.h[1] == b );
128 build_assert ( &u->dd.digest.h[2] == c );
129 build_assert ( &u->dd.digest.h[3] == d );
130 build_assert ( &u->dd.digest.h[4] == e );
131 build_assert ( &u->dd.digest.h[5] == f );
132 build_assert ( &u->dd.digest.h[6] == g );
133 build_assert ( &u->dd.digest.h[7] == h );
134 build_assert ( &u->dd.data.qword[0] == w );
135 build_assert ( sizeof ( u->dd ) == sizeof ( u->v ) );
136
137 /* Main loop */
138 for ( i = 0 ; i < SHA512_ROUNDS ; i++ ) {
139 s0 = ( ror64 ( *a, 28 ) ^ ror64 ( *a, 34 ) ^ ror64 ( *a, 39 ) );
140 maj = ( ( *a & *b ) ^ ( *a & *c ) ^ ( *b & *c ) );
141 t2 = ( s0 + maj );
142 s1 = ( ror64 ( *e, 14 ) ^ ror64 ( *e, 18 ) ^ ror64 ( *e, 41 ) );
143 ch = ( ( *e & *f ) ^ ( (~*e) & *g ) );
144 t1 = ( *h + s1 + ch + k[i] + w[ i % 16 ] );
145 *h = *g;
146 *g = *f;
147 *f = *e;
148 *e = ( *d + t1 );
149 *d = *c;
150 *c = *b;
151 *b = *a;
152 *a = ( t1 + t2 );
153 s0 = ( ror64 ( w[ ( i - 15 ) % 16 ], 1 ) ^
154 ror64 ( w[ ( i - 15 ) % 16 ], 8 ) ^
155 ( w[ ( i - 15 ) % 16 ] >> 7 ) );
156 s1 = ( ror64 ( w[ ( i - 2 ) % 16 ], 19 ) ^
157 ror64 ( w[ ( i - 2 ) % 16 ], 61 ) ^
158 ( w[ ( i - 2 ) % 16 ] >> 6 ) );
159 w[ i % 16 ] = ( w[ ( i - 16 ) % 16 ] + s0 +
160 w[ ( i - 7 ) % 16 ] + s1 );
161 DBGC2 ( &sha512_algorithm, "%2d : %016llx %016llx %016llx "
162 "%016llx %016llx %016llx %016llx %016llx\n",
163 i, *a, *b, *c, *d, *e, *f, *g, *h );
164 }
165
166 /* Add chunk to hash */
167 for ( i = 0 ; i < 8 ; i++ )
168 dd->digest.h[i] += digest->h[i];
169}
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
unsigned long long uint64_t
Definition stdint.h:13
#define build_assert(condition)
Assert a condition at build time (after dead code elimination).
Definition assert.h:77
union @104331263140136355135267063077374276003064103115 u
#define DBGC2(...)
Definition compiler.h:547
static const uint32_t k[64]
MD5 constants.
Definition md5.c:50
uint8_t h
Definition registers.h:4
uint8_t ch
Definition registers.h:1
struct digest_algorithm sha512_algorithm
#define SHA512_ROUNDS
SHA-512 number of rounds.
Definition sha512.h:19
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
struct sha512_digest digest
Digest of data already processed.
Definition sha512.h:54
uint64_t h[8]
Hash output.
Definition sha512.h:24
SHA-512 variables.
Definition sha512.c:40
uint64_t g
Definition sha512.c:48
uint64_t d
Definition sha512.c:45
uint64_t e
Definition sha512.c:46
uint64_t h
Definition sha512.c:49
uint64_t c
Definition sha512.c:44
uint64_t a
Definition sha512.c:42
uint64_t f
Definition sha512.c:47
uint64_t b
Definition sha512.c:43
uint64_t w[16]
Definition sha512.c:51

References sha512_variables::a, sha512_variables::b, build_assert, sha512_variables::c, ch, container_of, sha512_variables::d, DBGC2, sha512_digest_data::digest, sha512_variables::e, sha512_variables::f, sha512_variables::g, h, sha512_digest::h, sha512_variables::h, k, sha512_algorithm, SHA512_ROUNDS, typeof(), u, and sha512_variables::w.

Variable Documentation

◆ sha512_algorithm

◆ sha384_algorithm

◆ sha512_256_algorithm

struct digest_algorithm sha512_256_algorithm
extern

◆ sha512_224_algorithm

struct digest_algorithm sha512_224_algorithm
extern