![معاينة ZK-Call [C ++]](https://images.downcodes.com/uploads/20250315/img_67d5683eb87ef30.png)
يستضيف هذا المستودع تنفيذًا دقيقًا لبروتوكول Schnorr ، والذي يتضمن مبتكرًا بذرة الدولة لتدابير أمنية محسنة. على الرغم من أن الأدلة الأساسية قد تبدو معقدة ، إلا أنني أهدف إلى توضيح وظائفها بأفضل ما لدي. ومع ذلك ، من أجل الفهم الأعمق ، أشجع الرجوع إلى أوراق البحث الأساسي التي تقوم عليها هذا التنفيذ ، لأنها توفر رؤى شاملة.

لمزيد من الاستكشاف:
البراهين الإهليلجية على المنحنى الإهليلجي "المعرفة الصفرية" وقابلية تطبيقها على الأجهزة المقيدة للموارد من قبل Ioannis Chatzigiannakis ، Apostolos Pyrgelis ، Paul G. Spirakis ، و Yannis C. Stamatiou

بالإضافة إلى ذلك ، يتعمق هذا المستودع في مفاهيم البراهين "المعرفة الصفرية" (ZKPs) ورموز مصادقة الرسائل القائمة على التجزئة (HMACs) . ZKPs هي بروتوكولات تشفير تسمح لطرف واحد (المثل) بإثبات طرف آخر (المدقق) بأن بيان معين صحيح ، دون الكشف عن أي معلومات إضافية تتجاوز صحة البيان نفسه. هذه الخاصية ذات قيمة خاصة للحفاظ على الخصوصية مع تأسيس الثقة.
من ناحية أخرى ، HMACs هي نوع من وظيفة تجزئة التشفير المستخدمة لمصادقة الرسائل. أنها تنطوي على وظيفة تجزئة التشفير (مثل SHA-256) ومفتاح تشفير سري. توفر HMACs طريقة للتحقق من سلامة البيانات وأصالة الرسالة ، مما يضمن عدم تغييرها أو العبث بها أثناء الإرسال وأنها تنشأ بالفعل من المرسل المزعوم.
في تطور تكنولوجيا المعلومات بسرعة اليوم وتطوير التطبيقات ، تظهر "المعرفة الصفرية" (ZKPs) كنموذج محوري لأمن المصادقة. إن قدرتهم على تأكيد صحة المطالبة ، مثل إثبات حيازة كلمة مرور سرية - دون الكشف عن أي معلومات حساسة حول المطالبة نفسها ، مثل كلمات المرور أو التجزئة ، تحدث ثورة في ضمان عمليات AAA الآمنة ( المصادقة ، والترخيص ، والمحاسبة ).

يمثل ZK-Call & Labs تطبيقًا لبروتوكول إثبات "المعرفة الصفرية" غير التفاعلي (NIZKP) مصمم خصيصًا للتحقق من الأسرار المستندة إلى النص. يثبت هذا الإطار لا يقدر بثمن في حماية كلمات المرور وآليات المصادقة الأخرى ، مما يضمن تدابير أمنية قوية دون المساس بالخصوصية. بالإضافة إلى ذلك ، فإن تكامل HMAC (رمز مصادقة الرسائل القائم على التجزئة) يزيد من تحصين عملية المصادقة ، وتعزيز تكامل البيانات وإحباط انتهاكات الأمان المحتملة.
يعمل بروتوكول المصادقة المستخدم في هذا النظام على أساس مفهومين أساسيين: "المعرفة الصفرية" (ZKPS) ورمز مصادقة الرسائل القائم على التجزئة (HMAC) . دعنا نتعمق في كل من هذه المكونات ونفهم كيف يتآكلون لضمان المصادقة الآمنة في تطبيقات الرسائل.
تشكل ZKPs الأساس لآليات المصادقة للحفاظ على الخصوصية. تتيح هذه الأدلة أحد الأطراف (المثل) إظهار صحة المطالبة إلى طرف آخر (المدقق) دون الكشف عن أي معلومات إضافية تتجاوز صحة المطالبة. في جوهرها ، تتيح ZKPs المصادقة دون الحاجة إلى الكشف عن البيانات الحساسة ، مثل كلمات المرور أو مفاتيح التشفير.




في سياق تطبيقات المراسلة ، تلعب ZKPs دورًا محوريًا في التحقق من هوية المستخدم دون الحاجة إلى نقل بيانات اعتماد واضحة عبر الشبكة. بدلاً من ذلك ، يمكن للمستخدمين إنشاء أدلة تشفير تشهد على هويتهم أو حيازتهم لبيانات اعتماد معينة دون تعريض أوراق الاعتماد نفسها. هذا يضمن أن المعلومات الحساسة تظل سرية أثناء عملية المصادقة ، وتعزيز الأمن والخصوصية.
يوفر HMAC آلية قوية للتحقق من سلامة وأصالة الرسائل المتبادلة بين الأطراف. يتضمن استخدام وظيفة تجزئة التشفير بالتزامن مع مفتاح سري لإنشاء رمز فريد (HMAC) لكل رسالة. يعمل هذا الرمز كتوقيع رقمي ، مما يسمح للمستلم بالتحقق من أن الرسالة لم يتم العبث بها أو تغييرها أثناء الإرسال.

في تطبيقات المراسلة ، يمكن استخدام HMAC لمصادقة مرسلي الرسائل وضمان سلامة قنوات الاتصال. عن طريق إلحاق HMAC بكل رسالة باستخدام مفتاح سري مشترك ، يمكن لكل من المرسل والمستلم التحقق من صحة أصالة الرسالة عند الاستلام. أي تعديلات غير مصرح بها للرسالة ستؤدي إلى عدم تطابق بين HMAC المحسوبة و HMAC المستلمة ، وبالتالي تنبيه المستلم إلى العبث المحتمل.
عند الجمع ، يقوم "المعرفة الصفرية" و HMAC بإنشاء إطار هائل للمصادقة الآمنة في تطبيقات المراسلة. تسهل ZKPs التحقق من الهوية دون الكشف عن المعلومات الحساسة ، في حين أن HMAC يضمن سلامة وأصالة الرسائل المتبادلة بين الأطراف. معا ، تدعم هذه الآليات سرية قنوات الاتصال ونزاهتها وأصالةها ، وحماية خصوصية وأمن المستخدمين في المجال الرقمي.

من المفترض أن تكون واجهة برمجة تطبيقات "HMAC_Client" с ++ بسيطة وبديهية:
تقوم Core Components بتبسيط تشفير الرسائل الآمن وفك التشفير ، ودعم كل من المعالجة على مستوى القطع والحرمان لحماية البيانات المعززة.

طريقة لتشفير رسالة عن طريق معالجتها في قطع .
std::string encrypt_message_by_chunks(const std::string& message);
message: string # The message to be encrypted, processed in chunks
طريقة لتشفير رسالة بواسطة chars .
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
طريقة لفك تشفير رسالة عن طريق معالجتها في chars .
std::string encrypt_message(const std::string& message);
message: string # The message to be decrypted, processed in characters
تودو: قم بتضمين 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
}