Browse Source

fix(lite): fix the encrypt key in lite

GitOrigin-RevId: 6021d3c89c
release-1.7
Megvii Engine Team 3 years ago
parent
commit
efe3cfe7de
3 changed files with 5 additions and 26 deletions
  1. +0
    -22
      lite/pylite/test/test_global.py
  2. +4
    -4
      lite/src/decryption/aes_decrypt.h
  3. +1
    -0
      lite/tools/aes_encrypt.sh

+ 0
- 22
lite/pylite/test/test_global.py View File

@@ -71,25 +71,3 @@ class TestGlobal(TestShuffleNet):
network.load(model_path)

self.do_forward(network)

def test_update_decryption_key(self):
wrong_key = [0] * 32
LiteGlobal.update_decryption_key("AES_default", wrong_key)

with self.assertRaises(RuntimeError):
config = LiteConfig()
config.bare_model_cryption_name = "AES_default".encode("utf-8")
network = LiteNetwork(config)
model_path = os.path.join(self.source_dir, "shufflenet_crypt_aes.mge")
network.load(model_path)

right_key = [i for i in range(32)]
LiteGlobal.update_decryption_key("AES_default", right_key)

config = LiteConfig()
config.bare_model_cryption_name = "AES_default".encode("utf-8")
network = LiteNetwork(config)
model_path = os.path.join(self.source_dir, "shufflenet_crypt_aes.mge")
network.load(model_path)

self.do_forward(network)

+ 4
- 4
lite/src/decryption/aes_decrypt.h View File

@@ -41,10 +41,10 @@ public:
}

static std::vector<uint8_t> get_decrypt_key() {
std::vector<uint8_t> key = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
std::vector<uint8_t> key(32);
key = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
return key;
}
};


+ 1
- 0
lite/tools/aes_encrypt.sh View File

@@ -11,6 +11,7 @@ fi
IV=`openssl rand -hex 16`

Key=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F

if [ $# == 3 ] ; then
Key=$3
fi


Loading…
Cancel
Save