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/lib/math | |
parent | deef8ba63860efb14c45c5ee1cba2a3faaf8a719 (diff) |
Fix leading zero bytes in DSA, ECDSA, ECGDSA and ECKCDSA signatures
Diffstat (limited to 'src/lib/math')
-rw-r--r-- | src/lib/math/bigint/big_code.cpp | 11 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.h | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/math/bigint/big_code.cpp b/src/lib/math/bigint/big_code.cpp index 299fdc246..c8687715d 100644 --- a/src/lib/math/bigint/big_code.cpp +++ b/src/lib/math/bigint/big_code.cpp @@ -98,6 +98,17 @@ void BigInt::encode_1363(byte output[], size_t bytes, const BigInt& n) } /* +* Encode two BigInt, with leading 0s if needed, and concatenate +*/ +secure_vector<byte> BigInt::encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes) + { + secure_vector<byte> output(2 * bytes); + BigInt::encode_1363(output.data(), bytes, n1); + BigInt::encode_1363(output.data() + bytes, bytes, n2); + return output; + } + +/* * Decode a BigInt */ BigInt BigInt::decode(const byte buf[], size_t length, Base base) diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index 2963ba35d..a61bee39c 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -566,6 +566,15 @@ class BOTAN_DLL BigInt static void encode_1363(byte out[], size_t bytes, const BigInt& n); + /** + * Encode two BigInt to a byte array according to IEEE 1363 + * @param n1 the first BigInt to encode + * @param n2 the second BigInt to encode + * @param bytes the length of the encoding of each single BigInt + * @result a secure_vector<byte> containing the concatenation of the two encoded BigInt + */ + static secure_vector<byte> encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes); + private: secure_vector<word> m_reg; Sign m_signedness = Positive; |