aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_bigint.cpp
diff options
context:
space:
mode:
authorRenĂ© Korthaus <[email protected]>2016-08-09 18:06:39 +0200
committerRenĂ© Korthaus <[email protected]>2016-08-17 20:26:14 +0200
commit40a935209876b7c5360dadae85b0b26c2e13e0f5 (patch)
tree0adc0a99ce785ebe090d28e68e72fffd60238e85 /src/tests/test_bigint.cpp
parentdeef8ba63860efb14c45c5ee1cba2a3faaf8a719 (diff)
Fix leading zero bytes in DSA, ECDSA, ECGDSA and ECKCDSA signatures
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r--src/tests/test_bigint.cpp27
1 files changed, 27 insertions, 0 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);