iPXE
sha512.h
Go to the documentation of this file.
00001 #ifndef _IPXE_SHA512_H
00002 #define _IPXE_SHA512_H
00003 
00004 /** @file
00005  *
00006  * SHA-512 algorithm
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/crypto.h>
00014 
00015 /** SHA-512 number of rounds */
00016 #define SHA512_ROUNDS 80
00017 
00018 /** An SHA-512 digest */
00019 struct sha512_digest {
00020         /** Hash output */
00021         uint64_t h[8];
00022 };
00023 
00024 /** An SHA-512 data block */
00025 union sha512_block {
00026         /** Raw bytes */
00027         uint8_t byte[128];
00028         /** Raw qwords */
00029         uint64_t qword[16];
00030         /** Final block structure */
00031         struct {
00032                 /** Padding */
00033                 uint8_t pad[112];
00034                 /** High 64 bits of length in bits */
00035                 uint64_t len_hi;
00036                 /** Low 64 bits of length in bits */
00037                 uint64_t len_lo;
00038         } final;
00039 };
00040 
00041 /** SHA-512 digest and data block
00042  *
00043  * The order of fields within this structure is designed to minimise
00044  * code size.
00045  */
00046 struct sha512_digest_data {
00047         /** Digest of data already processed */
00048         struct sha512_digest digest;
00049         /** Accumulated data */
00050         union sha512_block data;
00051 } __attribute__ (( packed ));
00052 
00053 /** SHA-512 digest and data block */
00054 union sha512_digest_data_qwords {
00055         /** Digest and data block */
00056         struct sha512_digest_data dd;
00057         /** Raw qwords */
00058         uint64_t qword[ sizeof ( struct sha512_digest_data ) /
00059                         sizeof ( uint64_t ) ];
00060 };
00061 
00062 /** An SHA-512 context */
00063 struct sha512_context {
00064         /** Amount of accumulated data */
00065         size_t len;
00066         /** Digest size */
00067         size_t digestsize;
00068         /** Digest and accumulated data */
00069         union sha512_digest_data_qwords ddq;
00070 } __attribute__ (( packed ));
00071 
00072 /** SHA-512 context size */
00073 #define SHA512_CTX_SIZE sizeof ( struct sha512_context )
00074 
00075 /** SHA-512 digest size */
00076 #define SHA512_DIGEST_SIZE sizeof ( struct sha512_digest )
00077 
00078 /** SHA-384 digest size */
00079 #define SHA384_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 384 / 512 )
00080 
00081 /** SHA-512/256 digest size */
00082 #define SHA512_256_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 256 / 512 )
00083 
00084 /** SHA-512/224 digest size */
00085 #define SHA512_224_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 224 / 512 )
00086 
00087 extern void sha512_family_init ( struct sha512_context *context,
00088                                  const struct sha512_digest *init,
00089                                  size_t digestsize );
00090 extern void sha512_update ( void *ctx, const void *data, size_t len );
00091 extern void sha512_final ( void *ctx, void *out );
00092 
00093 extern struct digest_algorithm sha512_algorithm;
00094 extern struct digest_algorithm sha384_algorithm;
00095 extern struct digest_algorithm sha512_256_algorithm;
00096 extern struct digest_algorithm sha512_224_algorithm;
00097 
00098 #endif /* IPXE_SHA512_H */