hmac_sha2.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * HMAC-SHA-224/256/384/512 implementation
  3. * Last update: 06/15/2005
  4. * Issue date: 06/15/2005
  5. *
  6. * Since this code has been incorporated into a GPLv2 project, it is
  7. * distributed under GPLv2 inside mmc-utils. The original BSD license
  8. * that the code was released under is included below for clarity.
  9. *
  10. * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch>
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the project nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. */
  37. #ifndef HMAC_SHA2_H
  38. #define HMAC_SHA2_H
  39. #include "sha2.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. typedef struct {
  44. sha224_ctx ctx_inside;
  45. sha224_ctx ctx_outside;
  46. /* for hmac_reinit */
  47. sha224_ctx ctx_inside_reinit;
  48. sha224_ctx ctx_outside_reinit;
  49. unsigned char block_ipad[SHA224_BLOCK_SIZE];
  50. unsigned char block_opad[SHA224_BLOCK_SIZE];
  51. } hmac_sha224_ctx;
  52. typedef struct {
  53. sha256_ctx ctx_inside;
  54. sha256_ctx ctx_outside;
  55. /* for hmac_reinit */
  56. sha256_ctx ctx_inside_reinit;
  57. sha256_ctx ctx_outside_reinit;
  58. unsigned char block_ipad[SHA256_BLOCK_SIZE];
  59. unsigned char block_opad[SHA256_BLOCK_SIZE];
  60. } hmac_sha256_ctx;
  61. typedef struct {
  62. sha384_ctx ctx_inside;
  63. sha384_ctx ctx_outside;
  64. /* for hmac_reinit */
  65. sha384_ctx ctx_inside_reinit;
  66. sha384_ctx ctx_outside_reinit;
  67. unsigned char block_ipad[SHA384_BLOCK_SIZE];
  68. unsigned char block_opad[SHA384_BLOCK_SIZE];
  69. } hmac_sha384_ctx;
  70. typedef struct {
  71. sha512_ctx ctx_inside;
  72. sha512_ctx ctx_outside;
  73. /* for hmac_reinit */
  74. sha512_ctx ctx_inside_reinit;
  75. sha512_ctx ctx_outside_reinit;
  76. unsigned char block_ipad[SHA512_BLOCK_SIZE];
  77. unsigned char block_opad[SHA512_BLOCK_SIZE];
  78. } hmac_sha512_ctx;
  79. void hmac_sha224_init(hmac_sha224_ctx *ctx, const unsigned char *key,
  80. unsigned int key_size);
  81. void hmac_sha224_reinit(hmac_sha224_ctx *ctx);
  82. void hmac_sha224_update(hmac_sha224_ctx *ctx, const unsigned char *message,
  83. unsigned int message_len);
  84. void hmac_sha224_final(hmac_sha224_ctx *ctx, unsigned char *mac,
  85. unsigned int mac_size);
  86. void hmac_sha224(const unsigned char *key, unsigned int key_size,
  87. const unsigned char *message, unsigned int message_len,
  88. unsigned char *mac, unsigned mac_size);
  89. void hmac_sha256_init(hmac_sha256_ctx *ctx, const unsigned char *key,
  90. unsigned int key_size);
  91. void hmac_sha256_reinit(hmac_sha256_ctx *ctx);
  92. void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message,
  93. unsigned int message_len);
  94. void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac,
  95. unsigned int mac_size);
  96. void hmac_sha256(const unsigned char *key, unsigned int key_size,
  97. const unsigned char *message, unsigned int message_len,
  98. unsigned char *mac, unsigned mac_size);
  99. void hmac_sha384_init(hmac_sha384_ctx *ctx, const unsigned char *key,
  100. unsigned int key_size);
  101. void hmac_sha384_reinit(hmac_sha384_ctx *ctx);
  102. void hmac_sha384_update(hmac_sha384_ctx *ctx, const unsigned char *message,
  103. unsigned int message_len);
  104. void hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *mac,
  105. unsigned int mac_size);
  106. void hmac_sha384(const unsigned char *key, unsigned int key_size,
  107. const unsigned char *message, unsigned int message_len,
  108. unsigned char *mac, unsigned mac_size);
  109. void hmac_sha512_init(hmac_sha512_ctx *ctx, const unsigned char *key,
  110. unsigned int key_size);
  111. void hmac_sha512_reinit(hmac_sha512_ctx *ctx);
  112. void hmac_sha512_update(hmac_sha512_ctx *ctx, const unsigned char *message,
  113. unsigned int message_len);
  114. void hmac_sha512_final(hmac_sha512_ctx *ctx, unsigned char *mac,
  115. unsigned int mac_size);
  116. void hmac_sha512(const unsigned char *key, unsigned int key_size,
  117. const unsigned char *message, unsigned int message_len,
  118. unsigned char *mac, unsigned mac_size);
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif /* !HMAC_SHA2_H */