• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef MINDSPORE_CORE_UTILS_CRYPTO_H
18 #define MINDSPORE_CORE_UTILS_CRYPTO_H
19 
20 #include <string>
21 #include <memory>
22 
23 typedef unsigned char Byte;
24 namespace mindspore {
25 constexpr size_t MAX_BLOCK_SIZE = 512 * 1024 * 1024;  // Maximum ciphertext segment, units is Byte
26 constexpr size_t RESERVED_BYTE_PER_BLOCK = 50;        // Reserved byte per block to save addition info
27 constexpr unsigned int MAGIC_NUM = 0x7F3A5ED8;        // Magic number
28 
29 std::unique_ptr<Byte[]> Encrypt(size_t *encrypt_len, const Byte *plain_data, size_t plain_len, const Byte *key,
30                                 size_t key_len, const std::string &enc_mode);
31 std::unique_ptr<Byte[]> Decrypt(size_t *decrypt_len, const std::string &encrypt_data_path, const Byte *key,
32                                 size_t key_len, const std::string &dec_mode);
33 std::unique_ptr<Byte[]> Decrypt(size_t *decrypt_len, const Byte *model_data, size_t data_size, const Byte *key,
34                                 size_t key_len, const std::string &dec_mode);
35 bool IsCipherFile(const std::string &file_path);
36 bool IsCipherFile(const Byte *model_data);
37 }  // namespace mindspore
38 #endif
39