sm4.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * \file sm4.h
  3. */
  4. #ifndef XYSSL_SM4_H
  5. #define XYSSL_SM4_H
  6. #define SM4_ENCRYPT 1
  7. #define SM4_DECRYPT 0
  8. /**
  9. * \brief SM4 context structure
  10. */
  11. typedef struct
  12. {
  13. int mode; /*!< encrypt/decrypt */
  14. unsigned long sk[32]; /*!< SM4 subkeys */
  15. }
  16. sm4_context;
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * \brief SM4 key schedule (128-bit, encryption)
  22. *
  23. * \param ctx SM4 context to be initialized
  24. * \param key 16-byte secret key
  25. */
  26. void sm4_setkey_enc( sm4_context *ctx, unsigned char key[16] );
  27. /**
  28. * \brief SM4 key schedule (128-bit, decryption)
  29. *
  30. * \param ctx SM4 context to be initialized
  31. * \param key 16-byte secret key
  32. */
  33. void sm4_setkey_dec( sm4_context *ctx, unsigned char key[16] );
  34. /**
  35. * \brief SM4-ECB block encryption/decryption
  36. * \param ctx SM4 context
  37. * \param mode SM4_ENCRYPT or SM4_DECRYPT
  38. * \param length length of the input data
  39. * \param input input block
  40. * \param output output block
  41. */
  42. void sm4_crypt_ecb( sm4_context *ctx,
  43. int mode,
  44. int length,
  45. unsigned char *input,
  46. unsigned char *output);
  47. /**
  48. * \brief SM4-CBC buffer encryption/decryption
  49. * \param ctx SM4 context
  50. * \param mode SM4_ENCRYPT or SM4_DECRYPT
  51. * \param length length of the input data
  52. * \param iv initialization vector (updated after use)
  53. * \param input buffer holding the input data
  54. * \param output buffer holding the output data
  55. */
  56. void sm4_crypt_cbc( sm4_context *ctx,
  57. int mode,
  58. int length,
  59. unsigned char iv[16],
  60. unsigned char *input,
  61. unsigned char *output );
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* sm4.h */