Nessuna descrizione

hmac.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
  4. LICENSE TERMS
  5. The free distribution and use of this software in both source and binary
  6. form is allowed (with or without changes) provided that:
  7. 1. distributions of this source code include the above copyright
  8. notice, this list of conditions and the following disclaimer;
  9. 2. distributions in binary form include the above copyright
  10. notice, this list of conditions and the following disclaimer
  11. in the documentation and/or other associated materials;
  12. 3. the copyright holder's name is not used to endorse products
  13. built using this software without specific written permission.
  14. ALTERNATIVELY, provided that this notice is retained in full, this product
  15. may be distributed under the terms of the GNU General Public License (GPL),
  16. in which case the provisions of the GPL apply INSTEAD OF those given above.
  17. DISCLAIMER
  18. This software is provided 'as is' with no explicit or implied warranties
  19. in respect of its properties, including, but not limited to, correctness
  20. and/or fitness for purpose.
  21. ---------------------------------------------------------------------------
  22. Issue Date: 26/08/2003
  23. This is an implementation of HMAC, the FIPS standard keyed hash function
  24. */
  25. #ifndef _HMAC_H
  26. #define _HMAC_H
  27. #include <memory.h>
  28. #if defined(__cplusplus)
  29. extern "C"
  30. {
  31. #endif
  32. #define USE_SHA1
  33. #if !defined(USE_SHA1) && !defined(USE_SHA256)
  34. #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm
  35. #endif
  36. #ifdef USE_SHA1
  37. #include "sha1.h"
  38. #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE
  39. #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE
  40. #define sha_ctx sha1_ctx
  41. #define sha_begin sha1_begin
  42. #define sha_hash sha1_hash
  43. #define sha_end sha1_end
  44. #endif
  45. #ifdef USE_SHA256
  46. #include "sha2.h"
  47. #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE
  48. #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE
  49. #define sha_ctx sha256_ctx
  50. #define sha_begin sha256_begin
  51. #define sha_hash sha256_hash
  52. #define sha_end sha256_end
  53. #endif
  54. #define HMAC_OK 0
  55. #define HMAC_BAD_MODE -1
  56. #define HMAC_IN_DATA 0xffffffff
  57. typedef struct
  58. { unsigned char key[HASH_INPUT_SIZE];
  59. sha_ctx ctx[1];
  60. unsigned long klen;
  61. } hmac_ctx;
  62. void hmac_sha_begin(hmac_ctx cx[1]);
  63. int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]);
  64. void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]);
  65. void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]);
  66. void hmac_sha(const unsigned char key[], unsigned long key_len,
  67. const unsigned char data[], unsigned long data_len,
  68. unsigned char mac[], unsigned long mac_len);
  69. #if defined(__cplusplus)
  70. }
  71. #endif
  72. #endif