sm3.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * \file sm3.h
  3. * thanks to Xyssl
  4. * SM3 standards:http://www.oscca.gov.cn/News/201012/News_1199.htm
  5. * author:goldboar
  6. * email:[email protected]
  7. * 2011-10-26
  8. */
  9. #ifndef XYSSL_SM3_H
  10. #define XYSSL_SM3_H
  11. /**
  12. * \brief SM3 context structure
  13. */
  14. typedef struct
  15. {
  16. unsigned long total[2]; /*!< number of bytes processed */
  17. unsigned long state[8]; /*!< intermediate digest state */
  18. unsigned char buffer[64]; /*!< data block being processed */
  19. unsigned char ipad[64]; /*!< HMAC: inner padding */
  20. unsigned char opad[64]; /*!< HMAC: outer padding */
  21. }
  22. sm3_context;
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * \brief SM3 context setup
  28. *
  29. * \param ctx context to be initialized
  30. */
  31. void sm3_starts( sm3_context *ctx );
  32. /**
  33. * \brief SM3 process buffer
  34. *
  35. * \param ctx SM3 context
  36. * \param input buffer holding the data
  37. * \param ilen length of the input data
  38. */
  39. void sm3_update( sm3_context *ctx, unsigned char *input, int ilen );
  40. /**
  41. * \brief SM3 final digest
  42. *
  43. * \param ctx SM3 context
  44. */
  45. void sm3_finish( sm3_context *ctx, unsigned char output[32] );
  46. /**
  47. * \brief Output = SM3( input buffer )
  48. *
  49. * \param input buffer holding the data
  50. * \param ilen length of the input data
  51. * \param output SM3 checksum result
  52. */
  53. void sm3( unsigned char *input, int ilen,
  54. unsigned char output[32]);
  55. /**
  56. * \brief Output = SM3( file contents )
  57. *
  58. * \param path input file name
  59. * \param output SM3 checksum result
  60. *
  61. * \return 0 if successful, 1 if fopen failed,
  62. * or 2 if fread failed
  63. */
  64. int sm3_file( char *path, unsigned char output[32] );
  65. /**
  66. * \brief SM3 HMAC context setup
  67. *
  68. * \param ctx HMAC context to be initialized
  69. * \param key HMAC secret key
  70. * \param keylen length of the HMAC key
  71. */
  72. void sm3_hmac_starts( sm3_context *ctx, unsigned char *key, int keylen);
  73. /**
  74. * \brief SM3 HMAC process buffer
  75. *
  76. * \param ctx HMAC context
  77. * \param input buffer holding the data
  78. * \param ilen length of the input data
  79. */
  80. void sm3_hmac_update( sm3_context *ctx, unsigned char *input, int ilen );
  81. /**
  82. * \brief SM3 HMAC final digest
  83. *
  84. * \param ctx HMAC context
  85. * \param output SM3 HMAC checksum result
  86. */
  87. void sm3_hmac_finish( sm3_context *ctx, unsigned char output[32] );
  88. /**
  89. * \brief Output = HMAC-SM3( hmac key, input buffer )
  90. *
  91. * \param key HMAC secret key
  92. * \param keylen length of the HMAC key
  93. * \param input buffer holding the data
  94. * \param ilen length of the input data
  95. * \param output HMAC-SM3 result
  96. */
  97. void sm3_hmac( unsigned char *key, int keylen,
  98. unsigned char *input, int ilen,
  99. unsigned char output[32] );
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* sm3.h */