Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sha512.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. extern void sha512_family_init ( struct sha512_context *context,
  71. const struct sha512_digest *init,
  72. size_t digestsize );
  73. extern void sha512_update ( void *ctx, const void *data, size_t len );
  74. extern void sha512_final ( void *ctx, void *out );
  75. extern struct digest_algorithm sha512_algorithm;
  76. extern struct digest_algorithm sha384_algorithm;
  77. extern struct digest_algorithm sha512_256_algorithm;
  78. #endif /* IPXE_SHA512_H */