![ZK-Call Preview [C ++]](https://images.downcodes.com/uploads/20250315/img_67d5683eb87ef30.png)
このリポジトリは、 Schnorrのプロトコルの洗練された実装を開催し、強化されたセキュリティ対策のために州の種を革新的に組み込みます。根本的な証拠は複雑に見えるかもしれませんが、私は彼らの機能を自分の能力を最大限に発揮することを目指しています。しかし、より深い理解のために、私はこの実装を支える独創的な研究論文を包括的な洞察を提供するので、言及することをお勧めします。

さらなる調査のために:
楕円曲線に基づいた「ゼロ知識」の証明と、Ioannis Chatzigiannakis、Apostolos Pyrgelis、Paul G. Spirakis、およびYannis C. Stamatiouによるリソース制約デバイスへの適用性

さらに、このリポジトリは、「ゼロ知識」証明(ZKPS)およびハッシュベースのメッセージ認証コード(HMACS)の概念を掘り下げます。 ZKPSは、声明自体の有効性を超えた追加情報を明らかにすることなく、特定のステートメントが真であることを、ある当事者(Prover)が別の当事者(Verifier)に証明できるようにする暗号化プロトコルです。このプロパティは、信頼を確立しながらプライバシーを維持するために特に価値があります。
一方、 HMACはメッセージ認証に使用される暗号化ハッシュ関数の一種です。それらには、暗号化ハッシュ関数(SHA-256など)と秘密の暗号化キーが含まれます。 HMACSは、メッセージのデータの整合性と信ity性の両方を検証する方法を提供し、送信中に変更または改ざんされておらず、実際に意図された送信者に由来することを保証します。
今日の急速に進化しているITおよびアプリケーション開発の状況では、 「ゼロ知識」証明(ZKPS)が認証セキュリティのための重要なパラダイムとして現れます。秘密のパスワードの所有を証明するなど、請求の有効性を確認する能力は、パスワードやハッシュなどのクレーム自体に関する機密情報を明らかにすることなく、安全なAAA運用(認証、承認、会計)の保証に革命をもたらします。

ZK-Call&Labsは、テキストベースの秘密を検証するために特別に調整された非対話的な「ゼロ知識」証明(NIZKP)プロトコルの実装を表しています。このフレームワークは、パスワードやその他の認証メカニズムを保護するために非常に貴重であり、プライバシーを損なうことなく堅牢なセキュリティ対策を確保します。さらに、 HMAC(ハッシュベースのメッセージ認証コード)の統合により、認証プロセスがさらに強化され、データの整合性が向上し、潜在的なセキュリティ侵害が妨げられます。
このシステムで採用されている認証プロトコルは、2つの基本的な概念に基づいて動作します: 「ゼロ知識」証明(ZKPS)とハッシュベースのメッセージ認証コード(HMAC) 。これらのコンポーネントのそれぞれを掘り下げ、それらがどのように相乗化するかを理解して、メッセージングアプリケーションで安全な認証を確保します。
ZKPSは、プライバシーを提供する認証メカニズムの基盤を形成します。これらの証明により、一方の当事者(Prover)は、請求の有効性を超えて追加情報を明らかにすることなく、別の当事者(Verifier)に対する請求の妥当性を示すことができます。本質的に、 ZKPSは、パスワードや暗号化キーなど、プローバーが機密データを開示する必要なく認証を可能にします。




メッセージングアプリケーションのコンテキストでは、 ZKPSは、ネットワーク上に明示的な資格情報を送信する必要なく、ユーザーのIDを検証する上で極めて重要な役割を果たします。代わりに、ユーザーは、これらの資格情報自体を公開することなく、特定の資格情報の身元または所有を証明する暗号化された証明を生成できます。これにより、認証プロセス中に機密情報が秘密にされ、セキュリティとプライバシーが強化されます。
HMACは、当事者間で交換されるメッセージの整合性と信頼性を検証するための堅牢なメカニズムを提供します。これには、各メッセージに一意のコード(HMAC)を生成するために、シークレットキーと組み合わせて暗号化ハッシュ関数を使用することが含まれます。このコードはデジタル署名として機能し、受信者がメッセージが改ざんされていないか、送信中に変更されていないことを確認できるようにします。

メッセージングアプリケーションでは、 HMACを使用してメッセージ送信者を認証し、通信チャネルの整合性を確保できます。共有シークレットキーを使用して各メッセージにHMACを追加することにより、送信者と受信者の両方が、受領時にメッセージの信頼性を検証できます。メッセージに対する不正な変更は、計算されたHMACと受信されたHMACとの間に不一致が発生し、それにより受信者に潜在的な改ざんを警告します。
組み合わせると、 「ゼロ知識」証明と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
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
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
}