wuxiang пре 4 месеци
родитељ
комит
8a9d6511cb

BIN
cmake-build-debug/.ninja_deps


+ 3 - 0
cmake-build-debug/.ninja_log

@@ -44,3 +44,6 @@
 5	340	7636814646983454	new_protect.exe	24232ba513665ba7
 6	675	7636815226906637	CMakeFiles/new_protect.dir/main.cpp.obj	870137a341e2e732
 676	978	7636815233600163	new_protect.exe	24232ba513665ba7
+6	978	7643372042957030	CMakeFiles/new_protect.dir/main.cpp.obj	870137a341e2e732
+978	1845	7643372052685489	new_protect.exe	24232ba513665ba7
+7	372	7643372617087841	new_protect.exe	24232ba513665ba7

BIN
cmake-build-debug/CMakeFiles/new_protect.dir/main.cpp.obj


+ 2 - 2
cmake-build-debug/Testing/Temporary/LastTest.log

@@ -1,3 +1,3 @@
-Start testing: Mar 15 02:52 中国标准时间
+Start testing: Mar 22 17:01 中国标准时间
 ----------------------------------------------------------
-End testing: Mar 15 02:52 中国标准时间
+End testing: Mar 22 17:01 中国标准时间

BIN
cmake-build-debug/new_protect.exe


+ 30 - 6
main.cpp

@@ -78,6 +78,27 @@ int hexStringToByteArray(const char *hexString, unsigned char *byteArray, int by
   return count; // 返回转换的字节数
 }
 
+void replaceWithMiddleEight(unsigned char arr[], int length) {
+    if (length < 8) {
+        printf("数组长度不足8位\n");
+        return;
+    }
+
+    // 计算中间8位的起始索引
+    int start = (length - 8) / 2;
+
+    // 提取中间的8个元素
+    int middleEight[8];
+    for (int i = 0; i < 8; i++) {
+        middleEight[i] = arr[start + i];
+    }
+
+    // 用中间的8位替换源数组的内容
+    for (int i = 0; i < length; i++) {
+        arr[i] = middleEight[i % 8]; // 循环使用中间的8位
+    }
+}
+
 int main(int argc, char *argv[]) {
   FILE *input_file;
 
@@ -163,7 +184,7 @@ int main(int argc, char *argv[]) {
   const int serial_length = 39;
   unsigned char puf_key[serial_length];
   memset(puf_key, 0, serial_length);
-  unsigned char puf_value[serial_length];
+  unsigned char puf_value[serial_length+2];
   memset(puf_value, 0, serial_length);
   if (protect_type == 1) {
     printf("[STATE] node:1 ; message:PUF交互\n");
@@ -221,11 +242,13 @@ int main(int argc, char *argv[]) {
 
   printf("[STATE] node:2 ; message:获取密钥\n");
   uint8_t module_key[32] = {0};
-  if (protect_type == 1)
-    memcpy(module_key, puf_value + 4, 32);
-  else
-    get_random_bytes(module_key, 32);
-
+  if (protect_type == 1){
+      replaceWithMiddleEight(puf_value, 41);
+      memcpy(module_key, puf_value + 4, 32);
+  }
+  else {
+      get_random_bytes(module_key, 32);
+  }
   printf("module key:\n");
   for (int i = 0; i < 32; i++) {
     printf("%02x ", module_key[i]);
@@ -493,6 +516,7 @@ int main(int argc, char *argv[]) {
   return 0;
 }
 
+
 /**
  * magic
  * encrypted_file