diff options
| author | Michael Brown | 2012-03-05 01:18:49 +0100 |
|---|---|---|
| committer | Michael Brown | 2012-03-05 01:18:49 +0100 |
| commit | 657ab17338c28046f9cb085cbd93ed3818408c14 (patch) | |
| tree | 0101c013ebff5b0081e023bc406cbfce08dfc012 /src/include/ipxe | |
| parent | [x86_64] Use memory address constraint in __bswap_16s() (diff) | |
| download | ipxe-657ab17338c28046f9cb085cbd93ed3818408c14.tar.gz ipxe-657ab17338c28046f9cb085cbd93ed3818408c14.tar.xz ipxe-657ab17338c28046f9cb085cbd93ed3818408c14.zip | |
[crypto] Add SHA-256 algorithm
This implementation has been verified using the NIST SHA-256 test vectors.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
| -rw-r--r-- | src/include/ipxe/sha256.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/include/ipxe/sha256.h b/src/include/ipxe/sha256.h new file mode 100644 index 000000000..9aa9f3e57 --- /dev/null +++ b/src/include/ipxe/sha256.h @@ -0,0 +1,73 @@ +#ifndef _IPXE_SHA256_H +#define _IPXE_SHA256_H + +/** @file + * + * SHA-256 algorithm + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <stdint.h> +#include <ipxe/crypto.h> + +/** An SHA-256 digest */ +struct sha256_digest { + /** Hash output */ + uint32_t h[8]; +}; + +/** An SHA-256 data block */ +union sha256_block { + /** Raw bytes */ + uint8_t byte[64]; + /** Raw dwords */ + uint32_t dword[16]; + /** Final block structure */ + struct { + /** Padding */ + uint8_t pad[56]; + /** Length in bits */ + uint64_t len; + } final; +}; + +/** SHA-256 digest and data block + * + * The order of fields within this structure is designed to minimise + * code size. + */ +struct sha256_digest_data { + /** Digest of data already processed */ + struct sha256_digest digest; + /** Accumulated data */ + union sha256_block data; +} __attribute__ (( packed )); + +/** SHA-256 digest and data block */ +union sha256_digest_data_dwords { + /** Digest and data block */ + struct sha256_digest_data dd; + /** Raw dwords */ + uint32_t dword[ sizeof ( struct sha256_digest_data ) / + sizeof ( uint32_t ) ]; +}; + +/** An SHA-256 context */ +struct sha256_context { + /** Amount of accumulated data */ + size_t len; + /** Digest and accumulated data */ + union sha256_digest_data_dwords ddd; +} __attribute__ (( packed )); + +/** SHA-256 context size */ +#define SHA256_CTX_SIZE sizeof ( struct sha256_context ) + +/** SHA-256 digest size */ +#define SHA256_DIGEST_SIZE sizeof ( struct sha256_digest ) + +extern struct digest_algorithm sha256_algorithm; + +#endif /* _IPXE_SHA256_H */ |
