1
0

hmac_sha256.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * hmac_sha256.h
  3. *
  4. * Version 1.0.0
  5. *
  6. * Written by Aaron D. Gifford <[email protected]>
  7. *
  8. * Copyright 1998, 2000 Aaron D. Gifford. All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holder nor the names of contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. */
  34. #ifndef HEADER_HMAC_SHA256_H
  35. #define HEADER_HMAC_SHA256_H
  36. #include "sha2.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #define HMAC_SHA256_DIGEST_LENGTH 32
  41. #define HMAC_SHA256_BLOCK_LENGTH 64
  42. /* The HMAC_SHA1 structure: */
  43. typedef struct _HMAC_SHA256_CTX {
  44. unsigned char ipad[HMAC_SHA256_BLOCK_LENGTH];
  45. unsigned char opad[HMAC_SHA256_BLOCK_LENGTH];
  46. SHA256_CTX shactx;
  47. unsigned char key[HMAC_SHA256_BLOCK_LENGTH];
  48. unsigned int keylen;
  49. unsigned int hashkey;
  50. } HMAC_SHA256_CTX;
  51. #ifndef NOPROTO
  52. void HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx);
  53. void HMAC_SHA256_UpdateKey(HMAC_SHA256_CTX *ctx, unsigned char *key, unsigned int keylen);
  54. void HMAC_SHA256_EndKey(HMAC_SHA256_CTX *ctx);
  55. void HMAC_SHA256_StartMessage(HMAC_SHA256_CTX *ctx);
  56. void HMAC_SHA256_UpdateMessage(HMAC_SHA256_CTX *ctx, unsigned char *data, unsigned int datalen);
  57. void HMAC_SHA256_EndMessage(unsigned char *out, HMAC_SHA256_CTX *ctx);
  58. void HMAC_SHA256_Done(HMAC_SHA256_CTX *ctx);
  59. #else
  60. void HMAC_SHA256_Init();
  61. void HMAC_SHA256_UpdateKey();
  62. void HMAC_SHA256_EndKey();
  63. void HMAC_SHA256_StartMessage();
  64. void HMAC_SHA256_UpdateMessage();
  65. void HMAC_SHA256_EndMessage();
  66. void HMAC_SHA256_Done();
  67. #endif
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif