-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_qbtc_basic.cpp
More file actions
91 lines (78 loc) · 4.22 KB
/
Copy pathtest_qbtc_basic.cpp
File metadata and controls
91 lines (78 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2025 QBTC developers
// Basic test demonstrating QBTC quantum-resistant functionality
#include <iostream>
#include <vector>
#include <iomanip>
// External dilithium function declarations
extern "C" {
int qbtc_dilithium3_keypair(unsigned char *pk, unsigned char *sk);
int qbtc_dilithium3_signature(unsigned char *sig, size_t *siglen,
const unsigned char *m, size_t mlen,
const unsigned char *ctx, size_t ctxlen,
const unsigned char *sk);
int qbtc_dilithium3_verify(const unsigned char *sig, size_t siglen,
const unsigned char *m, size_t mlen,
const unsigned char *ctx, size_t ctxlen,
const unsigned char *pk);
}
int main() {
std::cout << "=== QBTC - Quantum-Resistant Bitcoin Test ===" << std::endl;
std::cout << std::endl;
try {
// Sizes from params.h for DILITHIUM_MODE=3
const size_t pk_size = 1952; // CRYPTO_PUBLICKEYBYTES
const size_t sk_size = 4000; // CRYPTO_SECRETKEYBYTES
const size_t sig_size = 3309; // CRYPTO_BYTES
std::vector<unsigned char> pk(pk_size);
std::vector<unsigned char> sk(sk_size);
std::vector<unsigned char> sig(sig_size);
std::cout << "Testing key generation..." << std::endl;
int ret = qbtc_dilithium3_keypair(pk.data(), sk.data());
if (ret != 0) {
std::cout << "❌ Key generation failed: " << ret << std::endl;
return 1;
}
std::cout << "✅ Key generation successful" << std::endl;
// Test message
std::string message = "Hello, quantum world!";
std::cout << "Testing signature..." << std::endl;
size_t siglen = sig_size;
ret = qbtc_dilithium3_signature(sig.data(), &siglen,
reinterpret_cast<const unsigned char*>(message.c_str()),
message.length(),
nullptr, 0, sk.data());
if (ret != 0) {
std::cout << "❌ Signature failed: " << ret << std::endl;
return 1;
}
std::cout << "✅ Signature successful (size: " << siglen << " bytes)" << std::endl;
std::cout << "Testing verification..." << std::endl;
ret = qbtc_dilithium3_verify(sig.data(), siglen,
reinterpret_cast<const unsigned char*>(message.c_str()),
message.length(),
nullptr, 0, pk.data());
if (ret != 0) {
std::cout << "❌ Verification failed: " << ret << std::endl;
return 1;
}
std::cout << "✅ Verification successful" << std::endl;
// Display key statistics
std::cout << std::endl << "=== QBTC vs Bitcoin Key Size Comparison ===" << std::endl;
std::cout << "Component | Bitcoin | QBTC | Increase" << std::endl;
std::cout << "-----------------|------------|------------|----------" << std::endl;
std::cout << "Private Key | 32 bytes | " << std::setw(6) << sk_size << " bytes | "
<< std::setw(4) << (sk_size / 32) << "x" << std::endl;
std::cout << "Public Key | 33 bytes | " << std::setw(6) << pk_size << " bytes | "
<< std::setw(4) << (pk_size / 33) << "x" << std::endl;
std::cout << "Signature | ~72 bytes | " << std::setw(6) << siglen << " bytes | "
<< std::setw(4) << (siglen / 72) << "x" << std::endl;
std::cout << std::endl << "🔐 QBTC provides post-quantum security using CRYSTALS-Dilithium3" << std::endl;
std::cout << "🛡️ Protected against both classical and quantum computer attacks" << std::endl;
std::cout << "⚛️ NIST Level 3 security (192-bit equivalent)" << std::endl;
std::cout << std::endl << "✅ All tests passed! QBTC is working correctly." << std::endl;
return 0;
} catch (const std::exception& e) {
std::cout << "❌ Test failed with exception: " << e.what() << std::endl;
return 1;
}
}