sm3.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Common values for SM3 algorithm
  4. *
  5. * Copyright (C) 2017 ARM Limited or its affiliates.
  6. * Copyright (C) 2017 Gilad Ben-Yossef <[email protected]>
  7. * Copyright (C) 2021 Tianjia Zhang <[email protected]>
  8. */
  9. #ifndef _CRYPTO_SM3_H
  10. #define _CRYPTO_SM3_H
  11. #include <linux/types.h>
  12. #define SM3_DIGEST_SIZE 32
  13. #define SM3_BLOCK_SIZE 64
  14. #define SM3_T1 0x79CC4519
  15. #define SM3_T2 0x7A879D8A
  16. #define SM3_IVA 0x7380166f
  17. #define SM3_IVB 0x4914b2b9
  18. #define SM3_IVC 0x172442d7
  19. #define SM3_IVD 0xda8a0600
  20. #define SM3_IVE 0xa96f30bc
  21. #define SM3_IVF 0x163138aa
  22. #define SM3_IVG 0xe38dee4d
  23. #define SM3_IVH 0xb0fb0e4e
  24. extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE];
  25. struct sm3_state {
  26. u32 state[SM3_DIGEST_SIZE / 4];
  27. u64 count;
  28. u8 buffer[SM3_BLOCK_SIZE];
  29. };
  30. /*
  31. * Stand-alone implementation of the SM3 algorithm. It is designed to
  32. * have as little dependencies as possible so it can be used in the
  33. * kexec_file purgatory. In other cases you should generally use the
  34. * hash APIs from include/crypto/hash.h. Especially when hashing large
  35. * amounts of data as those APIs may be hw-accelerated.
  36. *
  37. * For details see lib/crypto/sm3.c
  38. */
  39. static inline void sm3_init(struct sm3_state *sctx)
  40. {
  41. sctx->state[0] = SM3_IVA;
  42. sctx->state[1] = SM3_IVB;
  43. sctx->state[2] = SM3_IVC;
  44. sctx->state[3] = SM3_IVD;
  45. sctx->state[4] = SM3_IVE;
  46. sctx->state[5] = SM3_IVF;
  47. sctx->state[6] = SM3_IVG;
  48. sctx->state[7] = SM3_IVH;
  49. sctx->count = 0;
  50. }
  51. void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len);
  52. void sm3_final(struct sm3_state *sctx, u8 *out);
  53. #endif