diff options
author | René Korthaus <[email protected]> | 2016-08-09 18:06:39 +0200 |
---|---|---|
committer | René Korthaus <[email protected]> | 2016-08-17 20:26:14 +0200 |
commit | 40a935209876b7c5360dadae85b0b26c2e13e0f5 (patch) | |
tree | 0adc0a99ce785ebe090d28e68e72fffd60238e85 /src/tests | |
parent | deef8ba63860efb14c45c5ee1cba2a3faaf8a719 (diff) |
Fix leading zero bytes in DSA, ECDSA, ECGDSA and ECKCDSA signatures
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_bigint.cpp | 27 | ||||
-rw-r--r-- | src/tests/unit_x509.cpp | 11 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index 6f3d603db..cee7b5b8b 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -30,6 +30,7 @@ class BigInt_Unit_Tests : public Test results.push_back(test_bigint_sizes()); results.push_back(test_random_integer()); + results.push_back(test_encode()); return results; } @@ -143,6 +144,32 @@ class BigInt_Unit_Tests : public Test return result; } + + Test::Result test_encode() + { + Test::Result result("BigInt encoding functions"); + + const BigInt n1(0xffff); + const BigInt n2(1023); + + Botan::secure_vector<byte> encoded_n1 = BigInt::encode_1363(n1, 256); + Botan::secure_vector<byte> encoded_n2 = BigInt::encode_1363(n2, 256); + Botan::secure_vector<byte> expected = encoded_n1; + expected += encoded_n2; + + Botan::secure_vector<byte> encoded_n1_n2 = BigInt::encode_fixed_length_int_pair(n1, n2, 256); + result.test_eq("encode_fixed_length_int_pair", encoded_n1_n2, expected); + + for (size_t i = 0; i < 256 - n1.bytes(); ++i) + { + if ( encoded_n1[i] != 0 ) + { + result.test_failure("encode_1363", "no zero byte"); + } + } + + return result; + } }; BOTAN_REGISTER_TEST("bigint_unit", BigInt_Unit_Tests); diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index 8bbad5028..5110c7d23 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -481,20 +481,17 @@ class X509_Cert_Unit_Tests : public Test std::vector<Test::Result> results; const std::vector<std::string> sig_algos { "RSA", "DSA", "ECDSA", "ECGDSA", "ECKCDSA" }; Test::Result cert_result("X509 Unit"); + Test::Result usage_result("X509 Usage"); + for(const auto& algo : sig_algos) { cert_result.merge(test_x509_cert(algo)); + usage_result.merge(test_usage(algo)); } results.push_back(cert_result); - results.push_back(test_x509_dates()); - - Test::Result usage_result("X509 Usage"); - for(const auto& algo : sig_algos) - { - usage_result.merge(test_usage(algo)); - } results.push_back(usage_result); + results.push_back(test_x509_dates()); return results; } |