sha2.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  29. * \brief SHA-256 context structure
  30. */
  31. typedef struct
  32. {
  33. unsigned long total[2]; /*!< number of bytes processed */
  34. unsigned long state[8]; /*!< intermediate digest state */
  35. unsigned char buffer[64]; /*!< data block being processed */
  36. unsigned char ipad[64]; /*!< HMAC: inner padding */
  37. unsigned char opad[64]; /*!< HMAC: outer padding */
  38. int is224; /*!< 0 => SHA-256, else SHA-224 */
  39. }
  40. sha2_context;
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \brief SHA-256 context setup
  46. *
  47. * \param ctx context to be initialized
  48. * \param is224 0 = use SHA256, 1 = use SHA224
  49. */
  50. void sha2_starts( sha2_context *ctx, int is224 );
  51. /**
  52. * \brief SHA-256 process buffer
  53. *
  54. * \param ctx SHA-256 context
  55. * \param input buffer holding the data
  56. * \param ilen length of the input data
  57. */
  58. void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen );
  59. /**
  60. * \brief SHA-256 final digest
  61. *
  62. * \param ctx SHA-256 context
  63. * \param output SHA-224/256 checksum result
  64. */
  65. void sha2_finish( sha2_context *ctx, unsigned char output[32] );
  66. /**
  67. * \brief Output = SHA-256( input buffer )
  68. *
  69. * \param input buffer holding the data
  70. * \param ilen length of the input data
  71. * \param output SHA-224/256 checksum result
  72. * \param is224 0 = use SHA256, 1 = use SHA224
  73. */
  74. void sha2( const unsigned char *input, int ilen,
  75. unsigned char output[32], int is224 );
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* sha2.h */