sha2.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * \file sha2.h
  3. *
  4. * Copyright (C) 2011, Con Kolivas <kernel@kolivas.org>
  5. * Copyright (C) 2006-2010, Brainspark B.V.
  6. *
  7. * This file is part of PolarSSL (http://www.polarssl.org)
  8. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  25. */
  26. #ifndef POLARSSL_SHA2_H
  27. #define POLARSSL_SHA2_H
  28. #include <stdint.h>
  29. /**
  30. * \brief SHA-256 context structure
  31. */
  32. typedef struct
  33. {
  34. uint32_t total[2]; /*!< number of bytes processed */
  35. uint32_t state[8]; /*!< intermediate digest state */
  36. unsigned char buffer[64]; /*!< data block being processed */
  37. unsigned char ipad[64]; /*!< HMAC: inner padding */
  38. unsigned char opad[64]; /*!< HMAC: outer padding */
  39. int is224; /*!< 0 => SHA-256, else SHA-224 */
  40. }
  41. sha2_context;
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * \brief SHA-256 context setup
  47. *
  48. * \param ctx context to be initialized
  49. * \param is224 0 = use SHA256, 1 = use SHA224
  50. */
  51. void sha2_starts( sha2_context *ctx, int is224 );
  52. /**
  53. * \brief SHA-256 process buffer
  54. *
  55. * \param ctx SHA-256 context
  56. * \param input buffer holding the data
  57. * \param ilen length of the input data
  58. */
  59. void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen );
  60. /**
  61. * \brief SHA-256 final digest
  62. *
  63. * \param ctx SHA-256 context
  64. * \param output SHA-224/256 checksum result
  65. */
  66. void sha2_finish( sha2_context *ctx, unsigned char output[32] );
  67. /**
  68. * \brief Output = SHA-256( input buffer )
  69. *
  70. * \param input buffer holding the data
  71. * \param ilen length of the input data
  72. * \param output SHA-224/256 checksum result
  73. * \param is224 0 = use SHA256, 1 = use SHA224
  74. */
  75. void sha2( const unsigned char *input, int ilen,
  76. unsigned char output[32], int is224 );
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* sha2.h */