sm4_cl.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_SM4_CL_H
  10. #define GMSSL_SM4_CL_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <stdint.h>
  18. #include <gmssl/sm4.h>
  19. #ifdef APPLE
  20. #include <OpenCL/OpenCL.h>
  21. #else
  22. #include <CL/cl.h>
  23. #endif
  24. typedef struct {
  25. uint32_t rk[32];
  26. cl_context context;
  27. cl_command_queue queue;
  28. cl_program program;
  29. cl_kernel kernel;
  30. cl_mem mem_rk;
  31. cl_mem mem_io;
  32. size_t workgroup_size;
  33. } SM4_CL_CTX;
  34. int sm4_cl_set_encrypt_key(SM4_CL_CTX *ctx, const uint8_t key[16]);
  35. int sm4_cl_set_decrypt_key(SM4_CL_CTX *ctx, const uint8_t key[16]);
  36. int sm4_cl_encrypt(SM4_CL_CTX *ctx, const uint8_t *in, size_t nblocks, uint8_t *out);
  37. void sm4_cl_cleanup(SM4_CL_CTX *ctx);
  38. int test_sm4_cl_encrypt(void);
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif