You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sha512.h 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef _IPXE_SHA512_H
  2. #define _IPXE_SHA512_H
  3. /** @file
  4. *
  5. * SHA-512 algorithm
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/crypto.h>
  11. /** SHA-512 number of rounds */
  12. #define SHA512_ROUNDS 80
  13. /** An SHA-512 digest */
  14. struct sha512_digest {
  15. /** Hash output */
  16. uint64_t h[8];
  17. };
  18. /** An SHA-512 data block */
  19. union sha512_block {
  20. /** Raw bytes */
  21. uint8_t byte[128];
  22. /** Raw qwords */
  23. uint64_t qword[16];
  24. /** Final block structure */
  25. struct {
  26. /** Padding */
  27. uint8_t pad[112];
  28. /** High 64 bits of length in bits */
  29. uint64_t len_hi;
  30. /** Low 64 bits of length in bits */
  31. uint64_t len_lo;
  32. } final;
  33. };
  34. /** SHA-512 digest and data block
  35. *
  36. * The order of fields within this structure is designed to minimise
  37. * code size.
  38. */
  39. struct sha512_digest_data {
  40. /** Digest of data already processed */
  41. struct sha512_digest digest;
  42. /** Accumulated data */
  43. union sha512_block data;
  44. } __attribute__ (( packed ));
  45. /** SHA-512 digest and data block */
  46. union sha512_digest_data_qwords {
  47. /** Digest and data block */
  48. struct sha512_digest_data dd;
  49. /** Raw qwords */
  50. uint64_t qword[ sizeof ( struct sha512_digest_data ) /
  51. sizeof ( uint64_t ) ];
  52. };
  53. /** An SHA-512 context */
  54. struct sha512_context {
  55. /** Amount of accumulated data */
  56. size_t len;
  57. /** Digest size */
  58. size_t digestsize;
  59. /** Digest and accumulated data */
  60. union sha512_digest_data_qwords ddq;
  61. } __attribute__ (( packed ));
  62. /** SHA-512 context size */
  63. #define SHA512_CTX_SIZE sizeof ( struct sha512_context )
  64. /** SHA-512 digest size */
  65. #define SHA512_DIGEST_SIZE sizeof ( struct sha512_digest )
  66. /** SHA-384 digest size */
  67. #define SHA384_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 384 / 512 )
  68. /** SHA-512/256 digest size */
  69. #define SHA512_256_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 256 / 512 )
  70. /** SHA-512/224 digest size */
  71. #define SHA512_224_DIGEST_SIZE ( SHA512_DIGEST_SIZE * 224 / 512 )
  72. extern void sha512_family_init ( struct sha512_context *context,
  73. const struct sha512_digest *init,
  74. size_t digestsize );
  75. extern void sha512_update ( void *ctx, const void *data, size_t len );
  76. extern void sha512_final ( void *ctx, void *out );
  77. extern struct digest_algorithm sha512_algorithm;
  78. extern struct digest_algorithm sha384_algorithm;
  79. extern struct digest_algorithm sha512_256_algorithm;
  80. extern struct digest_algorithm sha512_224_algorithm;
  81. #endif /* IPXE_SHA512_H */