sha2.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }
  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. */
  49. void sha2_starts( sha2_context *ctx);
  50. /**
  51. * \brief SHA-256 process buffer
  52. *
  53. * \param ctx SHA-256 context
  54. * \param input buffer holding the data
  55. * \param ilen length of the input data
  56. */
  57. void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen );
  58. /**
  59. * \brief SHA-256 final digest
  60. *
  61. * \param ctx SHA-256 context
  62. * \param output SHA-256 checksum result
  63. */
  64. void sha2_finish( sha2_context *ctx, unsigned char output[32] );
  65. /**
  66. * \brief Output = SHA-256( input buffer )
  67. *
  68. * \param input buffer holding the data
  69. * \param ilen length of the input data
  70. * \param output SHA-256 checksum result
  71. */
  72. void sha2( const unsigned char *input, int ilen,
  73. unsigned char output[32]);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* sha2.h */