You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rc4_cryption.cpp 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * \file src/decryption/rc4_cryption.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "rc4_cryption.h"
  12. #include "rc4/rc4_cryption_impl.h"
  13. #include <vector>
  14. using namespace lite;
  15. std::vector<uint8_t> RC4::decrypt_model(const void* model_mem, size_t size,
  16. const std::vector<uint8_t>& key) {
  17. RC4Impl rc4_impl(model_mem, size, key);
  18. rc4_impl.init_rc4_state();
  19. return rc4_impl.decrypt_model();
  20. }
  21. std::vector<uint8_t> RC4::encrypt_model(const void* model_mem, size_t size,
  22. const std::vector<uint8_t>& key) {
  23. RC4Impl rc4_impl(model_mem, size, key);
  24. return rc4_impl.encrypt_model();
  25. }
  26. std::vector<uint8_t> RC4::get_decrypt_key() {
  27. std::vector<uint8_t> keys(128, 0);
  28. uint64_t* data = reinterpret_cast<uint64_t*>(keys.data());
  29. data[0] = rc4::key_gen_hash_key();
  30. data[1] = rc4::key_gen_enc_key();
  31. return keys;
  32. };
  33. std::vector<uint8_t> SimpleFastRC4::decrypt_model(
  34. const void* model_mem, size_t size, const std::vector<uint8_t>& key) {
  35. SimpleFastRC4Impl simple_fast_rc4_impl(model_mem, size, key);
  36. simple_fast_rc4_impl.init_sfrc4_state();
  37. return simple_fast_rc4_impl.decrypt_model();
  38. }
  39. std::vector<uint8_t> SimpleFastRC4::encrypt_model(
  40. const void* model_mem, size_t size, const std::vector<uint8_t>& key) {
  41. SimpleFastRC4Impl simple_fast_rc4_impl(model_mem, size, key);
  42. return simple_fast_rc4_impl.encrypt_model();
  43. }
  44. std::vector<uint8_t> SimpleFastRC4::get_decrypt_key() {
  45. std::vector<uint8_t> keys(128, 0);
  46. uint64_t* data = reinterpret_cast<uint64_t*>(keys.data());
  47. data[0] = rc4::key_gen_hash_key();
  48. data[1] = rc4::key_gen_enc_key();
  49. return keys;
  50. }
  51. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台