![ตัวอย่าง ZK-call [C ++]](https://images.downcodes.com/uploads/20250315/img_67d5683eb87ef30.png)
พื้นที่เก็บข้อมูลนี้เป็นเจ้าภาพการดำเนินการตาม โปรโตคอลของ Schnorr ซึ่งเป็นการผสมผสานอย่างสร้างสรรค์ในการรวมเมล็ดพันธุ์ของรัฐเพื่อเพิ่มมาตรการรักษาความปลอดภัย ในขณะที่หลักฐานพื้นฐานอาจดูซับซ้อนฉันมุ่งมั่นที่จะอธิบายการทำงานของพวกเขาให้ดีที่สุดเท่าที่จะทำได้ อย่างไรก็ตามเพื่อความเข้าใจที่ลึกซึ้งยิ่งขึ้นฉันขอแนะนำให้อ้างอิงเอกสารการวิจัยน้ำเชื้อที่สนับสนุนการดำเนินการนี้เนื่องจากพวกเขาเสนอข้อมูลเชิงลึกที่ครอบคลุม

สำหรับการสำรวจเพิ่มเติม:
เส้นโค้งรูปวงรีที่มีการพิสูจน์ "zero-knowledge" และการบังคับใช้ของพวกเขาในอุปกรณ์ที่ จำกัด ทรัพยากรโดย ioannis chatzigiannakis, Apostolos pyrgelis, Paul G. Spirakis และ Yannis C. Stamatiou

นอกจากนี้ที่เก็บนี้นำเสนอแนวคิดของ การพิสูจน์ "zero-knowledge" (ZKPS) และ รหัสการตรวจสอบข้อความที่ใช้แฮช (HMACs) ZKPS เป็นโปรโตคอลการเข้ารหัสที่อนุญาตให้ฝ่ายใดฝ่ายหนึ่ง (สุภาษิต) พิสูจน์ต่อบุคคลอื่น (ผู้ตรวจสอบ) ว่าคำสั่งที่กำหนดนั้นเป็นจริงโดยไม่เปิดเผยข้อมูลเพิ่มเติมใด ๆ นอกเหนือจากความถูกต้องของคำสั่ง สถานที่ให้บริการนี้มีค่าอย่างยิ่งสำหรับการรักษาความเป็นส่วนตัวในขณะที่สร้างความไว้วางใจ
ในทางกลับกัน HMACs เป็นประเภทของฟังก์ชันแฮชเข้ารหัสที่ใช้สำหรับการตรวจสอบข้อความ พวกเขาเกี่ยวข้องกับฟังก์ชั่นแฮชเข้ารหัส (เช่น SHA-256) และคีย์การเข้ารหัสลับ HMACs ให้วิธีการตรวจสอบทั้งความสมบูรณ์ของข้อมูลและความถูกต้องของข้อความเพื่อให้แน่ใจว่ามันยังไม่ได้รับการเปลี่ยนแปลงหรือดัดแปลงในระหว่างการส่งและมันมีต้นกำเนิดมาจากผู้ส่งที่อ้างไว้
ในการพัฒนาอย่างรวดเร็วและภูมิทัศน์การพัฒนาแอปพลิเคชัน การพิสูจน์ "zero-knowledge" (ZKPS) กลายเป็นกระบวนทัศน์สำคัญสำหรับความปลอดภัยการตรวจสอบความปลอดภัย ความสามารถของพวกเขาในการยืนยันความถูกต้องของการเรียกร้องเช่นการพิสูจน์การครอบครองรหัสผ่านลับ - โดยไม่เปิดเผยข้อมูลที่ละเอียดอ่อนใด ๆ เกี่ยวกับการเรียกร้องเองเช่นรหัสผ่านหรือแฮชปฏิวัติการประกัน การดำเนินการ AAA ที่ปลอดภัย ( การรับรอง ความถูกต้องการอนุญาต และ การบัญชี )

ZK-Call & Labs แสดงให้เห็นถึงการใช้งานโปรโตคอล การพิสูจน์ "ศูนย์ความรู้" ที่ไม่โต้ตอบ (NIZKP) ที่ไม่โต้ตอบซึ่งได้รับการปรับแต่งโดยเฉพาะสำหรับการตรวจสอบความลับตามข้อความ เฟรมเวิร์กนี้พิสูจน์ได้ว่ามีค่าสำหรับการปกป้องรหัสผ่านและกลไกการตรวจสอบความถูกต้องอื่น ๆ นอกจากนี้การรวมกันของ HMAC (รหัสการตรวจสอบข้อความที่ใช้แฮชที่ใช้ HASH) เสริมสร้างกระบวนการตรวจสอบความถูกต้องเพิ่มความสมบูรณ์ของข้อมูลและขัดขวางการละเมิดความปลอดภัยที่อาจเกิดขึ้น
โปรโตคอลการตรวจสอบความถูกต้องที่ใช้ในระบบนี้ดำเนินการตามแนวคิดพื้นฐานสองประการ: การพิสูจน์ "zero-knowledge" (ZKPS) และ รหัสการรับรองความถูกต้องข้อความที่ใช้แฮช (HMAC) มาเจาะลึกลงไปในแต่ละองค์ประกอบเหล่านี้และเข้าใจว่าพวกเขาทำงานร่วมกันอย่างไรเพื่อให้แน่ใจว่าการตรวจสอบความถูกต้องในแอปพลิเคชันส่งข้อความ
ZKPS ก่อให้เกิดข้อเท็จจริงของกลไกการตรวจสอบความเป็นส่วนตัวในการรักษาความเป็นส่วนตัว หลักฐานเหล่านี้อนุญาตให้ฝ่ายหนึ่ง (สุภาษิต) แสดงให้เห็นถึงความถูกต้องของการเรียกร้องต่อบุคคลอื่น (ผู้ตรวจสอบ) โดยไม่เปิดเผยข้อมูลเพิ่มเติมใด ๆ นอกเหนือจากความถูกต้องของการเรียกร้อง ในสาระสำคัญ ZKPS เปิดใช้งานการรับรองความถูกต้องโดยไม่จำเป็นต้องให้สุภาษิตเปิดเผยข้อมูลที่ละเอียดอ่อนเช่นรหัสผ่านหรือปุ่มเข้ารหัส




ในบริบทของแอปพลิเคชันการส่งข้อความ ZKPS มีบทบาทสำคัญในการตรวจสอบตัวตนของผู้ใช้โดยไม่จำเป็นต้องส่งข้อมูลรับรองที่ชัดเจนผ่านเครือข่าย แต่ผู้ใช้สามารถสร้างหลักฐานการเข้ารหัสที่ยืนยันถึงตัวตนหรือการครอบครองข้อมูลประจำตัวบางอย่างโดยไม่เปิดเผยข้อมูลประจำตัวเหล่านั้น สิ่งนี้ทำให้มั่นใจได้ว่าข้อมูลที่ละเอียดอ่อนยังคงเป็นความลับในระหว่างกระบวนการตรวจสอบความปลอดภัยการสนับสนุนความปลอดภัยและความเป็นส่วนตัว
HMAC ให้กลไกที่แข็งแกร่งสำหรับการตรวจสอบความสมบูรณ์และความถูกต้องของข้อความที่แลกเปลี่ยนระหว่างบุคคล มันเกี่ยวข้องกับการใช้ฟังก์ชันแฮชเข้ารหัสลับร่วมกับคีย์ลับเพื่อสร้างรหัสที่ไม่ซ้ำกัน (HMAC) สำหรับแต่ละข้อความ รหัสนี้ทำหน้าที่เป็นลายเซ็นดิจิตอลทำให้ผู้รับสามารถตรวจสอบได้ว่าข้อความนั้นไม่ได้ถูกดัดแปลงหรือเปลี่ยนแปลงระหว่างการส่ง

ในแอปพลิเคชันการส่งข้อความ HMAC สามารถใช้เพื่อตรวจสอบความถูกต้องของผู้ส่งข้อความและตรวจสอบให้แน่ใจว่ามีความสมบูรณ์ของช่องทางการสื่อสาร โดยการต่อท้าย HMAC กับแต่ละข้อความโดยใช้คีย์ลับที่ใช้ร่วมกันทั้งผู้ส่งและผู้รับสามารถตรวจสอบความถูกต้องของข้อความเมื่อได้รับ การปรับเปลี่ยนข้อความใด ๆ ที่ไม่ได้รับอนุญาตจะส่งผลให้เกิดความไม่ตรงกันระหว่าง HMAC ที่คำนวณได้ และ HMAC ที่ได้รับ ซึ่งจะแจ้งให้ผู้รับทราบถึงการดัดแปลงที่อาจเกิดขึ้น
เมื่อรวมกัน การพิสูจน์ "zero-knowledge" และ HMAC จะสร้างกรอบการทำงานที่น่ากลัวสำหรับการตรวจสอบความปลอดภัยในแอปพลิเคชันการส่งข้อความ ZKPS อำนวยความสะดวกในการตรวจสอบตัวตนโดยไม่เปิดเผยข้อมูลที่ละเอียดอ่อนในขณะที่ HMAC ช่วยให้มั่นใจถึงความสมบูรณ์และความถูกต้องของข้อความที่แลกเปลี่ยนระหว่างฝ่ายต่างๆ กลไกเหล่านี้ช่วยรักษาความลับความซื่อสัตย์และความถูกต้องของช่องทางการสื่อสารการปกป้องความเป็นส่วนตัวและความปลอดภัยของผู้ใช้ในดินแดนดิจิตอล

"HMAC_Client" с ++ API นั้นง่ายและใช้งานง่าย:
Core Components ปรับปรุง การเข้ารหัสข้อความ ที่ปลอดภัยและ การถอดรหัส ซึ่งรองรับทั้งการประมวลผล แบบก้อน และ ระดับอักขระ เพื่อการปกป้องข้อมูลที่เพิ่มขึ้น

วิธีการ เข้ารหัสข้อความ โดยการประมวลผลเป็น ชิ้น
std::string encrypt_message_by_chunks(const std::string& message);
message: string # The message to be encrypted, processed in chunks
วิธีการ เข้ารหัสข้อความ โดย ตัวอักษร
std::string encrypt_message(const std::string& message);
message: string # The message to be encrypted, processed in characters
วิธีการ ถอดรหัสข้อความ โดยการประมวลผลเป็น ชิ้น
std::string decrypt_message_by_chunks(const std::string& message);
message: string # The message to be decrypted, processed in chunks
วิธีการ ถอดรหัสข้อความ โดยการประมวลผลเป็น ตัวอักษร
std::string encrypt_message(const std::string& message);
message: string # The message to be decrypted, processed in characters
TODO: รวม Example Usage
#include <iostream> // Include the input/output stream standard header
#include <thread> // Include the thread standard header
#include <queue> // Include the queue standard header
#include <string> // Include the string standard header
#include "src/HMAC/core/base.h" // Include the header file for HMAC_Client functionality
#include "src/SeedGeneration/core/base.h" // Include the header file for SeedGenerator functionality
constexpr bool DEBUG = true; // Define a constexpr boolean variable DEBUG with value true
void print_msg(const std::string &who, const std::string &message) { // Define a function to print messages
if (DEBUG) { // Check if debugging is enabled
std::cout << "[" << who << "] " << message << std::endl; // Print the message with source identifier
}
}
bool check_if_queue_empty(std::queue<std::string> &socket) { // Define a function to check if a queue is empty
while (true) { // Infinite loop
if (!socket.empty()) { // Check if the queue is not empty
return true; // Return true if the queue is not empty
}
}
}
std::string get_content_from_socket(std::queue<std::string> &socket) { // Define a function to get content from a socket (queue)
if (check_if_queue_empty(socket)) { // Check if the queue is not empty
std::string val = socket.front(); // Get the front element of the queue
socket.pop(); // Remove the front element from the queue
return val; // Return the retrieved value
}
}
void client(std::queue<std::string> &client_socket, std::queue<std::string> &server_socket) { // Define the client function
// Generating the main seed
SeedGenerator seed_generator("job"); // Create an instance of SeedGenerator
std::vector<unsigned char> main_seed = seed_generator.generate(); // Generate the main seed
// Creating an instance of HMAC_Client for encrypting messages
print_msg("client", "first");
HMAC_Client obj("sha256", main_seed, 1); // Create an instance of HMAC_Client
// Sending the main seed to the server
server_socket.emplace(main_seed.begin(), main_seed.end()); // Convert the main seed vector to a string and send it to the server
print_msg("client", "after obj");
// Checking if the server has successfully received the seed
if (get_content_from_socket(client_socket) == obj.encrypt_message("")) { // Check if the server received the seed
print_msg("client", "after if");
// If successful, send a message to the server
std::string message = "hello"; // Define the message to be sent
server_socket.push(obj.encrypt_message_by_chunks(message)); // Encrypt and send the message to the server
print_msg("client", "client sent message " + message);
// Checking if the server has successfully decrypted the message
if (get_content_from_socket(client_socket) == obj.encrypt_message(message)) { // Check if the server decrypted the message
print_msg("client", "server has decrypted message");
}
}
}
void server(std::queue<std::string> &server_socket, std::queue<std::string> &client_socket) { // Define the server function
// Receiving the main seed from the client
std::string main_seed = get_content_from_socket(server_socket); // Receive the main seed from the client
// Creating an instance of HMAC_Client for encrypting messages
HMAC_Client obj("sha256", std::vector<unsigned char>(main_seed.begin(), main_seed.end()), 1); // Create an instance of HMAC_Client
// Sending an empty message to the client as acknowledgment
client_socket.push(obj.encrypt_message("")); // Encrypt and send an empty message to the client as acknowledgment
// Receiving the encrypted message from the client
std::string msg = get_content_from_socket(server_socket); // Receive the encrypted message from the client
print_msg("server", "message encrypted: " + msg);
// Decrypting the message
print_msg("server", "before decrypt ");
std::string msg_raw = obj.decrypt_message_by_chunks(msg); // Decrypt the received message
print_msg("server", "message raw: " + msg_raw);
// Sending the encrypted message back to the client
client_socket.push(obj.encrypt_message(msg_raw)); // Encrypt and send the decrypted message back to the client
}
int main() { // Main function
std::queue<std::string> client_socket, server_socket; // Create queues for client and server sockets
std::thread client_thread(client, std::ref(client_socket), std::ref(server_socket)); // Create a thread for the client function
std::thread server_thread(server, std::ref(server_socket), std::ref(client_socket)); // Create a thread for the server function
// Joining the threads to wait for their completion
client_thread.join(); // Wait for the client thread to finish
server_thread.join(); // Wait for the server thread to finish
return 0; // Return 0 to indicate successful execution
}
#include "src/ZeroKnowledge/core/base.h" // Include the header file for ZeroKnowledge class
int main() { // Main function
// Creating a ZeroKnowledge object for the client with specified curve and hash algorithm
ZeroKnowledge clientObject = ZeroKnowledge::createNew("secp256k1", "sha3_256");
// Creating a ZeroKnowledge object for the server with specified curve and hash algorithm
ZeroKnowledge serverObject = ZeroKnowledge::createNew("secp384r1", "sha3_512");
// Setting the server password
std::string serverPassword = "SecretServerPassword";
// Creating a signature for the server password
ZeroKnowledgeSignature serverSignature = serverObject.createSignature(serverPassword);
// Creating a signature for the client identity
std::string identity = "John";
ZeroKnowledgeSignature clientSignature = clientObject.createSignature(identity);
std::cout<<"beforen";
// Generating a token signed by the server for the client
std::cout<<clientObject.token()<<"n";
ZeroKnowledgeData token = serverObject.sign(serverPassword, clientObject.token());
std::cout<<"aftern";
// Generating proof using client identity and token
ZeroKnowledgeData proof = clientObject.sign(identity, token.data);
// Verifying the received proof
bool serverVerification = serverObject.verify(token, serverSignature);
if (!serverVerification) { // Check if server verification failed
std::cout << "Server verification failed" << std::endl; // Print error message
} else { // If server verification succeeded
// Otherwise, verify the proof using client signature
bool clientVerification = clientObject.verify(token, clientSignature, proof.proof);
if (!clientVerification) { // Check if client verification failed
std::cout << "Client verification failed" << std::endl; // Print error message
} else { // If client verification succeeded
std::cout << "Authentication successful" << std::endl; // Print success message
}
}
return 0; // Return 0 to indicate successful execution
}
#include "src/ZeroKnowledge/core/base.h" // Include the header file for ZeroKnowledge class
#include "src/HMAC/core/base.h" // Include the header file for HMAC_Client functionality
#include "src/SeedGeneration/core/base.h" // Include the header file for SeedGenerator functionality
#include <iostream> // Include the input/output stream standard header
#include <thread> // Include the thread standard header
#include <queue> // Include the queue standard header
#include <string> // Include the string standard header
constexpr bool DEBUG = true; // Define a constexpr boolean variable DEBUG with value true
void print_msg(const std::string &who, const std::string &message) { // Define a function to print messages
if (DEBUG) { // Check if debugging is enabled
std::cout << "[" << who << "] " << message << std::endl; // Print the message with source identifier
}
}
bool check_if_queue_empty(std::queue<std::string> &socket) { // Define a function to check if a queue is empty
while (true) { // Infinite loop
if (!socket.empty()) { // Check if the queue is not empty
return true; // Return true if the queue is not empty
}
}
}
std::string get_content_from_socket(std::queue<std::string> &socket) { // Define a function to get content from a socket (queue)
if (check_if_queue_empty(socket)) { // Check if the queue is not empty
std::string val = socket.front(); // Get the front element of the queue
socket.pop(); // Remove the front element from the queue
return val; // Return the retrieved value
}
}
void client(std::queue<std::string> &client_socket, std::queue<std::string> &server_socket) { // Define the client function
// Generating the main seed
SeedGenerator seed_generator("job"); // Create an instance of SeedGenerator
std::vector<unsigned char> main_seed = seed_generator.generate(); // Generate the main seed
// Creating an instance of HMAC_Client for encrypting messages
print_msg("client", "first");
HMAC_Client obj("sha256", main_seed, 1); // Create an instance of HMAC_Client
// Sending the main seed to the server
server_socket.emplace(main_seed.begin(), main_seed.end()); // Convert the main seed vector to a string and send it to the server
print_msg("client", "after obj");
// Checking if the server has successfully received the seed
if (get_content_from_socket(client_socket) == obj.encrypt_message("")) { // Check if the server received the seed
print_msg("client", "after if");
// If successful, send a message to the server
std::string message = "hello"; // Define the message to be sent
server_socket.push(obj.encrypt_message_by_chunks(message)); // Encrypt and send the message to the server
print_msg("client", "client sent message " + message);
// Checking if the server has successfully decrypted the message
if (get_content_from_socket(client_socket) == obj.encrypt_message(message)) { // Check if the server decrypted the message
print_msg("client", "server has decrypted message");
}
}
}
void server(std::queue<std::string> &server_socket, std::queue<std::string> &client_socket) { // Define the server function
// Receiving the main seed from the client
std::string main_seed = get_content_from_socket(server_socket); // Receive the main seed from the client
// Creating an instance of HMAC_Client for encrypting messages
HMAC_Client obj("sha256", std::vector<unsigned char>(main_seed.begin(), main_seed.end()), 1); // Create an instance of HMAC_Client
// Sending an empty message to the client as acknowledgment
client_socket.push(obj.encrypt_message("")); // Encrypt and send an empty message to the client as acknowledgment
// Receiving the encrypted message from the client
std::string msg = get_content_from_socket(server_socket); // Receive the encrypted message from the client
print_msg("server", "message encrypted: " + msg);
// Decrypting the message
print_msg("server", "before decrypt ");
std::string msg_raw = obj.decrypt_message_by_chunks(msg); // Decrypt the received message
print_msg("server", "message raw: " + msg_raw);
// Sending the encrypted message back to the client
client_socket.push(obj.encrypt_message(msg_raw)); // Encrypt and send the decrypted message back to the client
}
void init_talking() { // Define a function to initialize client-server communication
std::queue<std::string> client_socket, server_socket; // Create queues for client and server sockets
std::thread client_thread(client, std::ref(client_socket), std::ref(server_socket)); // Create a thread for the client function
std::thread server_thread(server, std::ref(server_socket), std::ref(client_socket)); // Create a thread for the server function
// Joining the threads to wait for their completion
client_thread.join(); // Wait for the client thread to finish
server_thread.join(); // Wait for the server thread to finish
}
int main() { // Main function
// Creating a ZeroKnowledge object for the client with specified curve and hash algorithm
ZeroKnowledge clientObject = ZeroKnowledge::createNew("secp256k1", "sha3_256");
// Creating a ZeroKnowledge object for the server with specified curve and hash algorithm
ZeroKnowledge serverObject = ZeroKnowledge::createNew("secp384r1", "sha3_512");
// Setting the server password
std::string serverPassword = "SecretServerPassword";
// Creating a signature for the server password
ZeroKnowledgeSignature serverSignature = serverObject.createSignature(serverPassword);
// Creating a signature for the client identity
std::string identity = "John";
ZeroKnowledgeSignature clientSignature = clientObject.createSignature(identity);
std::cout << "beforen";
// Generating a token signed by the server for the client
std::cout << clientObject.token() << "n";
ZeroKnowledgeData token = serverObject.sign(serverPassword, clientObject.token());
std::cout << "aftern";
// Generating proof using client identity and token
ZeroKnowledgeData proof = clientObject.sign(identity, token.data);
// Verifying the received proof
bool serverVerification = serverObject.verify(token, serverSignature);
if (!serverVerification) { // Check if server verification failed
std::cout << "Server verification failed" << std::endl; // Print error message
} else { // If server verification succeeded
// Otherwise, verify the proof using client signature
bool clientVerification = clientObject.verify(token, clientSignature, proof.proof);
if (!clientVerification) { // Check if client verification failed
std::cout << "Client verification failed" << std::endl; // Print error message
} else { // If client verification succeeded
std::cout << "Authentication successful" << std::endl; // Print success message
init_talking(); // Initialize client-server communication
}
}
return 0; // Return 0 to indicate successful execution
}