|
|
|
@ -13,13 +13,13 @@ int main()
|
|
|
|
|
std::cout << "Test Nonce" << std::endl;
|
|
|
|
|
{
|
|
|
|
|
std::cout << "* Generates Random Nonce" << std::endl;
|
|
|
|
|
Nonce nonce;
|
|
|
|
|
Nonce nonce{};
|
|
|
|
|
|
|
|
|
|
std::cout << " - generated nonce: " << nonce.to_hex_string() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "* Copy Nonce" << std::endl;
|
|
|
|
|
Nonce nonce_copy(nonce);
|
|
|
|
|
Nonce nonce_copy{nonce};
|
|
|
|
|
|
|
|
|
|
std::cout << "* Increment Nonce" << std::endl;
|
|
|
|
|
nonce.increment();
|
|
|
|
@ -31,8 +31,85 @@ int main()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Test specialization for int" << std::endl;
|
|
|
|
|
// assert(ret == __cplusplus);
|
|
|
|
|
std::cout << "* Create self-initialized Nonce" << std::endl;
|
|
|
|
|
NonceData nd0{
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
};
|
|
|
|
|
NonceData ndFF{
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFE,
|
|
|
|
|
};
|
|
|
|
|
Nonce nonce0{nd00};
|
|
|
|
|
Nonce nonce{ndFF};
|
|
|
|
|
Nonce nonce_copy{ndFF};
|
|
|
|
|
|
|
|
|
|
std::cout << "* Copied nonce data are equal"
|
|
|
|
|
assert(nonce.nonce_data == nonce_copy.nonce_data);
|
|
|
|
|
|
|
|
|
|
std::cout << "* Different nonce data are not equal"
|
|
|
|
|
assert(nonce0.nonce_data != nonce.nonce_data);
|
|
|
|
|
assert(nonce0.nonce_data != nonce_copy.nonce_data);
|
|
|
|
|
|
|
|
|
|
nonce.increment();
|
|
|
|
|
std::cout << "* Self-initialized nonce increases idependently"
|
|
|
|
|
assert(nonce.nonce_data[31] == 0xFF);
|
|
|
|
|
assert(nonce.nonce_data != nonce_copy.nonce_data);
|
|
|
|
|
|
|
|
|
|
nonce.increment();
|
|
|
|
|
std::cout << "* Nonce rolls over properly on overflow"
|
|
|
|
|
assert(nonce.nonce_data == nonce0.nonce_data);
|
|
|
|
|
assert(nonce.nonce_data[30] == 0x00);
|
|
|
|
|
assert(nonce.nonce_data[15] == 0x00);
|
|
|
|
|
assert(nonce.nonce_data[31] == 0x00);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "Test PublicKey"
|
|
|
|
|
{
|
|
|
|
|
std::cout << "* Self-Initialize PublicKey" << std::endl;
|
|
|
|
|
KeyData kd1 = {
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
0x00. 0x00. 0x00. 0x01,
|
|
|
|
|
};
|
|
|
|
|
PublicKey pubkey{kd1};
|
|
|
|
|
|
|
|
|
|
std::cout << " - test public key: " << pubkey.to_hex_string() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "* Copy public key" << std::endl;
|
|
|
|
|
PublicKey pubkey_copy{pubkey};
|
|
|
|
|
|
|
|
|
|
std::cout << "* Copied public key data are equal" << std::endl;
|
|
|
|
|
assert(public_key.get_data() == public_key.get_data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "Test KeyPair"
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Test generate_keypair" << std::endl;
|
|
|
|
|
KeyPair kp = generate_keypair();
|
|
|
|
|
PublicKey pubkey = kp.first();
|
|
|
|
|
PrivateKey privkey = kp.second();
|
|
|
|
|
|
|
|
|
|
// keys are not equal
|
|
|
|
|
assert(pubkey.get_data() != privkey.get_data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "All tests passed" << std::endl;
|
|
|
|
|