![Pratinjau ZK-Call [C ++]](https://images.downcodes.com/uploads/20250315/img_67d5683eb87ef30.png)
Repositori ini menyelenggarakan implementasi protokol Schnorr yang disempurnakan, secara inovatif menggabungkan benih negara untuk meningkatkan langkah -langkah keamanan. Sementara bukti yang mendasari mungkin tampak rumit, saya bertujuan untuk menjelaskan fungsionalitas mereka dengan kemampuan terbaik saya. Namun, untuk pemahaman yang lebih dalam, saya mendorong referensi makalah penelitian seminal yang mendasari implementasi ini, karena mereka menawarkan wawasan yang komprehensif.

Untuk eksplorasi lebih lanjut:
Bukti Kurva Elliptic Berbasis "Nol-Knowledge" dan penerapannya pada perangkat yang dibatasi sumber daya oleh Ioannis Chatzigiannakis, Apostolos pyrgelis, Paul G. Spirakis, dan Yannis C. Stamatiou

Selain itu, repositori ini menggali konsep bukti "nol-pengetahuan" (ZKPS) dan kode otentikasi pesan berbasis hash (HMACS) . ZKP adalah protokol kriptografi yang memungkinkan satu pihak (pepatah) untuk membuktikan kepada pihak lain (verifier) bahwa pernyataan yang diberikan adalah benar, tanpa mengungkapkan informasi tambahan apa pun di luar validitas pernyataan itu sendiri. Properti ini sangat berharga untuk menjaga privasi sambil membangun kepercayaan.
Di sisi lain, HMAC adalah jenis fungsi hash kriptografi yang digunakan untuk otentikasi pesan. Mereka melibatkan fungsi hash kriptografi (seperti SHA-256) dan kunci kriptografi rahasia. HMACS menyediakan cara untuk memverifikasi integritas data dan keaslian pesan, memastikan bahwa itu belum diubah atau dirusak selama transmisi dan memang berasal dari pengirim yang diakui.
Dalam lanskap pengembangannya dan pengembangan aplikasi yang berkembang pesat saat ini, bukti "Zero-Knowledge" (ZKPS) muncul sebagai paradigma penting untuk keamanan otentikasi. Kapasitas mereka untuk menegaskan validitas klaim, seperti membuktikan kepemilikan kata sandi rahasia - tanpa mengungkapkan informasi sensitif tentang klaim itu sendiri, seperti kata sandi atau hash, merevolusi jaminan operasi AAA yang aman ( otentikasi , otorisasi , dan akuntansi ).

ZK-Call & Labs mewakili implementasi protokol "nol-pengetahuan" non-interaktif (NIZKP) yang dirancang khusus untuk memvalidasi rahasia berbasis teks. Kerangka kerja ini terbukti sangat berharga untuk melindungi kata sandi dan mekanisme otentikasi lainnya, memastikan langkah -langkah keamanan yang kuat tanpa mengorbankan privasi. Selain itu, integrasi HMAC (kode otentikasi pesan berbasis hash) semakin membentengi proses otentikasi, meningkatkan integritas data dan menggagalkan pelanggaran keamanan potensial.
Protokol otentikasi yang digunakan dalam sistem ini beroperasi berdasarkan dua konsep mendasar: bukti "nol-pengetahuan" (ZKPS) dan kode otentikasi pesan berbasis hash (HMAC) . Mari kita mempelajari masing -masing komponen ini dan pahami bagaimana mereka bersinergi untuk memastikan otentikasi yang aman dalam aplikasi pesan.
ZKPS membentuk landasan mekanisme otentikasi pemeliharaan privasi. Bukti -bukti ini memungkinkan satu pihak (pepatah) untuk menunjukkan validitas klaim kepada pihak lain (verifier) tanpa mengungkapkan informasi tambahan apa pun di luar validitas klaim. Intinya, ZKP memungkinkan otentikasi tanpa perlu pepatah untuk mengungkapkan data sensitif, seperti kata sandi atau kunci kriptografi.




Dalam konteks aplikasi pesan, ZKP memainkan peran penting dalam memverifikasi identitas pengguna tanpa perlu mengirimkan kredensial eksplisit melalui jaringan. Sebaliknya, pengguna dapat menghasilkan bukti kriptografi yang membuktikan identitas mereka atau memiliki kredensial tertentu tanpa mengekspos kredensial itu sendiri. Ini memastikan bahwa informasi sensitif tetap bersifat rahasia selama proses otentikasi, memperkuat keamanan dan privasi.
HMAC menyediakan mekanisme yang kuat untuk memverifikasi integritas dan keaslian pesan yang dipertukarkan antar pihak. Ini melibatkan penggunaan fungsi hash kriptografi bersama dengan kunci rahasia untuk menghasilkan kode unik (HMAC) untuk setiap pesan. Kode ini berfungsi sebagai tanda tangan digital, yang memungkinkan penerima untuk memverifikasi bahwa pesan belum dirusak atau diubah selama transmisi.

Dalam aplikasi pesan, HMAC dapat digunakan untuk mengotentikasi pengirim pesan dan memastikan integritas saluran komunikasi. Dengan menambahkan HMAC ke setiap pesan menggunakan kunci rahasia bersama, baik pengirim dan penerima dapat memvalidasi keaslian pesan setelah diterima. Setiap modifikasi yang tidak sah pada pesan akan mengakibatkan ketidakcocokan antara HMAC yang dihitung dan HMAC yang diterima , dengan demikian memperingatkan penerima untuk potensi perusakan.
Saat digabungkan, bukti "nol-pengetahuan" dan HMAC membuat kerangka kerja yang tangguh untuk otentikasi aman dalam aplikasi pesan. ZKPS memfasilitasi verifikasi identitas tanpa membocorkan informasi sensitif, sementara HMAC memastikan integritas dan keaslian pesan yang dipertukarkan di antara para pihak. Bersama -sama, mekanisme ini menjunjung tinggi kerahasiaan, integritas, dan keaslian saluran komunikasi, melindungi privasi dan keamanan pengguna di ranah digital.

API "HMAC_Client" с ++ dimaksudkan untuk sederhana dan intuitif:
Core Components merampingkan enkripsi dan dekripsi pesan aman, mendukung pemrosesan level chunk dan karakter untuk peningkatan perlindungan data.

Metode untuk mengenkripsi pesan dengan memprosesnya dalam potongan .
std::string encrypt_message_by_chunks(const std::string& message);
message: string # The message to be encrypted, processed in chunks
Metode untuk mengenkripsi pesan dengan karakter .
std::string encrypt_message(const std::string& message);
message: string # The message to be encrypted, processed in characters
Metode untuk mendekripsi pesan dengan memprosesnya dalam potongan .
std::string decrypt_message_by_chunks(const std::string& message);
message: string # The message to be decrypted, processed in chunks
Metode untuk mendekripsi pesan dengan memprosesnya dalam chars .
std::string encrypt_message(const std::string& message);
message: string # The message to be decrypted, processed in characters
TODO: Sertakan 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
}