sha256.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * SHA256 hash implementation and interface functions
  3. * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef SHA256_H
  15. #define SHA256_H
  16. #include "common.h"
  17. #include "os.h"
  18. #define SHA256_MAC_LEN 32
  19. #define SHA256_BLOCK_SIZE 64
  20. struct sha256_state {
  21. u64 length;
  22. u32 state[8], curlen;
  23. u8 buf[SHA256_BLOCK_SIZE];
  24. };
  25. void sha256_init(struct sha256_state *md);
  26. int sha256_process(struct sha256_state *md, const unsigned char *in,
  27. unsigned long inlen);
  28. int sha256_done(struct sha256_state *md, unsigned char *out);
  29. /**
  30. * sha256_vector - SHA256 hash for data vector
  31. * @num_elem: Number of elements in the data vector
  32. * @addr: Pointers to the data areas
  33. * @len: Lengths of the data blocks
  34. * @mac: Buffer for the hash
  35. * Returns: 0 on success, -1 on failure
  36. */
  37. int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
  38. u8 *mac);
  39. void hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
  40. const u8 *addr[], const size_t *len, u8 *mac);
  41. void hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
  42. size_t data_len, u8 *mac);
  43. void sha256_prf(const u8 *key, size_t key_len, const char *label,
  44. const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
  45. #endif /* SHA256_H */