sm4.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* $OpenBSD: sm4.h,v 1.1 2019/03/17 17:42:37 tb Exp $ */
  2. /*
  3. * Copyright (c) 2017, 2019 Ribose Inc
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef HEADER_SM4_H
  18. #define HEADER_SM4_H
  19. #include <stdint.h>
  20. #include <openssl/opensslconf.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #ifdef OPENSSL_NO_SM4
  25. #error SM4 is disabled.
  26. #endif
  27. #define SM4_DECRYPT 0
  28. #define SM4_ENCRYPT 1
  29. #define SM4_BLOCK_SIZE 16
  30. #define SM4_KEY_SCHEDULE 32
  31. typedef struct sm4_key_st {
  32. unsigned char opaque[128];
  33. } SM4_KEY;
  34. int SM4_set_key(const uint8_t *key, SM4_KEY *ks);
  35. void SM4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks);
  36. void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. #endif /* HEADER_SM4_H */