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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _IPXE_SHA1_H
  2. #define _IPXE_SHA1_H
  3. /** @file
  4. *
  5. * SHA-1 algorithm
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <ipxe/crypto.h>
  11. /** An SHA-1 digest */
  12. struct sha1_digest {
  13. /** Hash output */
  14. uint32_t h[5];
  15. };
  16. /** An SHA-1 data block */
  17. union sha1_block {
  18. /** Raw bytes */
  19. uint8_t byte[64];
  20. /** Raw dwords */
  21. uint32_t dword[16];
  22. /** Final block structure */
  23. struct {
  24. /** Padding */
  25. uint8_t pad[56];
  26. /** Length in bits */
  27. uint64_t len;
  28. } final;
  29. };
  30. /** SHA-1 digest and data block
  31. *
  32. * The order of fields within this structure is designed to minimise
  33. * code size.
  34. */
  35. struct sha1_digest_data {
  36. /** Digest of data already processed */
  37. struct sha1_digest digest;
  38. /** Accumulated data */
  39. union sha1_block data;
  40. } __attribute__ (( packed ));
  41. /** SHA-1 digest and data block */
  42. union sha1_digest_data_dwords {
  43. /** Digest and data block */
  44. struct sha1_digest_data dd;
  45. /** Raw dwords */
  46. uint32_t dword[ sizeof ( struct sha1_digest_data ) /
  47. sizeof ( uint32_t ) ];
  48. };
  49. /** An SHA-1 context */
  50. struct sha1_context {
  51. /** Amount of accumulated data */
  52. size_t len;
  53. /** Digest and accumulated data */
  54. union sha1_digest_data_dwords ddd;
  55. } __attribute__ (( packed ));
  56. /** SHA-1 context size */
  57. #define SHA1_CTX_SIZE sizeof ( struct sha1_context )
  58. /** SHA-1 digest size */
  59. #define SHA1_DIGEST_SIZE sizeof ( struct sha1_digest )
  60. extern struct digest_algorithm sha1_algorithm;
  61. extern void prf_sha1 ( const void *key, size_t key_len, const char *label,
  62. const void *data, size_t data_len, void *prf,
  63. size_t prf_len );
  64. extern void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
  65. const void *salt, size_t salt_len,
  66. int iterations, void *key, size_t key_len );
  67. #endif /* _IPXE_SHA1_H */