![Aperçu du ZK-Call [C ++]](https://images.downcodes.com/uploads/20250315/img_67d5683eb87ef30.png)
Ce référentiel héberge une implémentation raffinée du protocole de Schnorr , incorporant de manière innovante une graine d'État pour des mesures de sécurité améliorées. Bien que les preuves sous-jacentes puissent sembler complexes, je vise à élucider leur fonctionnalité au mieux de mes capacités. Cependant, pour une compréhension plus approfondie, j'encourage à référence aux documents de recherche fondamentaux qui sous-tendent cette mise en œuvre, car ils offrent des informations complètes.

Pour une exploration plus approfondie:
Les preuves "zéro-connaissance" basées sur la courbe elliptique et leur applicabilité sur les dispositifs contraints des ressources par Ioannis Chatzigiannakis, Apostolos Pyrgelis, Paul G. Spirakis et Yannis C. Stamatiou

De plus, ce référentiel plonge dans les concepts des preuves "zéro-connaissance" (ZKPS) et des codes d'authentification de message (HMACS) basés sur le hachage . Les ZKP sont des protocoles cryptographiques qui permettent à une partie (le prover) de prouver à une autre partie (le vérificateur) qu'une déclaration donnée est vraie, sans révéler aucune information supplémentaire au-delà de la validité de la déclaration elle-même. Cette propriété est particulièrement précieuse pour préserver la vie privée lors de l'établissement de la confiance.
D'un autre côté, les HMAC sont un type de fonction de hachage cryptographique utilisé pour l'authentification des messages. Ils impliquent une fonction de hachage cryptographique (comme SHA-256) et une clé cryptographique secrète. Les HMAC fournissent un moyen de vérifier à la fois l'intégrité des données et l'authenticité d'un message, garantissant qu'elle n'a pas été modifiée ou falsifiée pendant la transmission et qu'elle provient en effet de l'expéditeur prétendu.
Dans le paysage de développement informatique et des applications en évolution rapide d'aujourd'hui, les preuves de la «connaissance zéro» (ZKPS) émergent comme un paradigme pivot pour la sécurité de l'authentification. Leur capacité à affirmer la validité d'une réclamation, comme prouver la possession d'un mot de passe secret - sans révéler aucune information sensible sur la réclamation elle-même, telle que les mots de passe ou les hachages, révolutionne l'assurance des opérations sécurisées AAA ( authentification , autorisation et comptabilité ).

ZK-Call & Labs représente une implémentation d'un protocole de preuve (NIZKP) non interactif "Zero-Knowledge" spécialement conçu spécifiquement pour valider des secrets textuels. Ce cadre s'avère inestimable pour la sauvegarde des mots de passe et d'autres mécanismes d'authentification, garantissant des mesures de sécurité robustes sans compromettre la confidentialité. De plus, l'intégration de HMAC (code d'authentification des messages basé sur le hachage) fortifie en outre le processus d'authentification, améliorant l'intégrité des données et contrecarrant les violations de sécurité potentielles.
Le protocole d'authentification utilisé dans ce système fonctionne sur la base de deux concepts fondamentaux: les preuves "zéro-connaissance" (ZKPS) et le code d'authentification des messages basé sur le hachage (HMAC) . Plongeons dans chacun de ces composants et comprenons comment ils synergiquent pour assurer une authentification sécurisée dans les applications de messagerie.
ZKPS forment le fondement des mécanismes d'authentification préservant la confidentialité. Ces preuves permettent à une partie (le prover) de démontrer la validité d'une réclamation à une autre partie (le vérificateur) sans révéler aucune information supplémentaire au-delà de la validité de la réclamation. Essentiellement, les ZKP permettent d'authentification sans avoir besoin pour le prover de divulguer des données sensibles, telles que des mots de passe ou des clés cryptographiques.




Dans le contexte des applications de messagerie, les ZKPs jouent un rôle central dans la vérification de l'identité d'un utilisateur sans avoir besoin de transmettre des informations d'identification explicites sur le réseau. Au lieu de cela, les utilisateurs peuvent générer des preuves cryptographiques atteignant leur identité ou leur possession de certaines informations d'identification sans exposer ces informations d'identification elles-mêmes. Cela garantit que les informations sensibles restent confidentielles pendant le processus d'authentification, renforçant la sécurité et la confidentialité.
HMAC fournit un mécanisme robuste pour vérifier l'intégrité et l'authenticité des messages échangés entre les parties. Il implique l'utilisation d'une fonction de hachage cryptographique en conjonction avec une clé secrète pour générer un code unique (le HMAC) pour chaque message. Ce code sert de signature numérique, permettant au destinataire de vérifier que le message n'a pas été falsifié ou modifié pendant la transmission.

Dans les applications de messagerie, HMAC peut être utilisé pour authentifier les expéditeurs de messages et assurer l'intégrité des canaux de communication. En ajoutant un HMAC à chaque message à l'aide d'une clé secrète partagée, l'expéditeur et le destinataire peuvent valider l'authenticité du message à réception. Toutes les modifications non autorisées du message entraîneraient un décalage entre le HMAC calculé et le HMAC reçu , alertant ainsi le destinataire de la falsification potentielle.
Lorsqu'ils sont combinés, les preuves "Zero-Knowledge" et HMAC créent un framework formidable pour l'authentification sécurisée dans les applications de messagerie. Les ZKPs facilitent la vérification de l'identité sans divulguer des informations sensibles, tandis que HMAC assure l'intégrité et l'authenticité des messages échangés entre les parties. Ensemble, ces mécanismes soutiennent la confidentialité, l'intégrité et l'authenticité des canaux de communication, protégeant la confidentialité et la sécurité des utilisateurs dans le domaine numérique.

L'API "HMAC_Client" с ++ est censée être simple et intuitive:
Les Core Components rationalisent le cryptage et le déchiffrement des messages sécurisés, prenant en charge le traitement de morceaux et de niveau des caractères pour une protection améliorée de données.

Méthode pour chiffrer un message en le traitant en morceaux .
std::string encrypt_message_by_chunks(const std::string& message);
message: string # The message to be encrypted, processed in chunks
Méthode pour crypter un message par un char .
std::string encrypt_message(const std::string& message);
message: string # The message to be encrypted, processed in characters
Méthode pour décrypter un message en le traitant en morceaux .
std::string decrypt_message_by_chunks(const std::string& message);
message: string # The message to be decrypted, processed in chunks
Méthode pour décrypter un message en le traitant dans Chars .
std::string encrypt_message(const std::string& message);
message: string # The message to be decrypted, processed in characters
TODO: inclure 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
}