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.

crypto.h 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_CRYPTO_CRYPTO_H
  17. #define MINDSPORE_CCSRC_CRYPTO_CRYPTO_H
  18. #if not defined(_WIN32)
  19. #include <openssl/aes.h>
  20. #include <openssl/evp.h>
  21. #include <openssl/rand.h>
  22. #endif
  23. #include <stdio.h>
  24. #include <fstream>
  25. #include <string>
  26. #include <regex>
  27. #include "utils/log_adapter.h"
  28. typedef unsigned char Byte;
  29. namespace mindspore {
  30. namespace crypto {
  31. const int MAX_BLOCK_SIZE = 512 * 1024 * 1024; // Maximum ciphertext segment, units is Byte
  32. const unsigned int MAGIC_NUM = 0x7F3A5ED8; // Magic number
  33. Byte *Encrypt(int64_t *encrypt_len, Byte *plain_data, const int64_t plain_len, Byte *key, const int32_t key_len,
  34. const std::string &enc_mode);
  35. Byte *Decrypt(int64_t *decrypt_len, const std::string &encrypt_data_path, Byte *key, const int32_t key_len,
  36. const std::string &dec_mode);
  37. bool IsCipherFile(const std::string file_path);
  38. } // namespace crypto
  39. } // namespace mindspore
  40. #endif