@@ -21,19 +21,20 @@ namespace detail {
2121
2222Botan::BigInt decode_flip (std::span<std::uint8_t > val) {
2323 std::ranges::reverse (val);
24- return Botan::BigInt::decode ( val.data (), val.size ());
24+ return Botan::BigInt::from_bytes (std::span< const uint8_t >( val.data (), val.size () ));
2525}
2626
2727SmallVec encode_flip (const Botan::BigInt& val) {
2828 SmallVec res (val.bytes (), boost::container::default_init);
29- val.binary_encode ( res.data (), res.size ());
29+ val.serialize_to (std::span< uint8_t >( res.data (), res.size () ));
3030 std::ranges::reverse (res);
3131 return res;
3232}
3333
3434SmallVec encode_flip_1363 (const Botan::BigInt& val, std::size_t padding) {
3535 SmallVec res (padding, boost::container::default_init);
36- Botan::BigInt::encode_1363 (res.data (), res.size (), val);
36+ std::fill (res.begin (), res.end (), 0 ); // 1363 style padding
37+ val.serialize_to ({ res.data () + res.size () - val.bytes (), val.bytes () });
3738 std::ranges::reverse (res);
3839 return res;
3940}
@@ -69,15 +70,15 @@ Botan::BigInt scrambler(const Botan::BigInt& A, const Botan::BigInt& B, std::siz
6970 auto hasher = Botan::HashFunction::create_or_throw (" SHA-1" );
7071 BOOST_ASSERT_MSG (SHA1_LEN == hasher->output_length (), " Bad hash length" );
7172 std::array<std::uint8_t , SHA1_LEN> hash_out;
72- SmallVec vec (padding, boost::container::default_init);
73+ SmallVec vec (padding, 0 ); // 1363 style padding
7374
7475 if (mode == Compliance::RFC5054) {
75- Botan::BigInt::encode_1363 (vec.data (), vec.size (), A );
76+ A. serialize_to (std::span< uint8_t > (vec.data (), vec.size ()) );
7677 hasher->update (vec.data (), vec.size ());
77- Botan::BigInt::encode_1363 (vec.data (), vec.size (), B );
78+ B. serialize_to (std::span< uint8_t > (vec.data (), vec.size ()) );
7879 hasher->update (vec.data (), vec.size ());
7980 hasher->final (hash_out.data ());
80- return Botan::BigInt::decode ( hash_out.data (), hash_out.size ());
81+ return Botan::BigInt::from_bytes (std::span< const uint8_t >( hash_out.data (), hash_out.size () ));
8182 } else {
8283 const auto & a_enc = encode_flip_1363 (A, padding);
8384 const auto & b_enc = encode_flip_1363 (B, padding);
@@ -93,10 +94,14 @@ Botan::BigInt compute_k(const Botan::BigInt& g, const Botan::BigInt& N) {
9394 std::array<std::uint8_t , SHA1_LEN> hash;
9495 auto hasher = Botan::HashFunction::create_or_throw (" SHA-1" );
9596 BOOST_ASSERT_MSG (SHA1_LEN == hasher->output_length (), " Bad hash length" );
96- hasher->update (Botan::BigInt::encode (N));
97- hasher->update (Botan::BigInt::encode_1363 (g, N.bytes ()));
97+ std::vector<uint8_t > n_buf (N.bytes (), 0 ); // 1363 style padding
98+ N.serialize_to ({ n_buf.data () + n_buf.size () - N.bytes (), N.bytes () });
99+ std::vector<uint8_t > g_buf (N.bytes (), 0 ); // 1363 style padding
100+ g.serialize_to ({ g_buf.data () + g_buf.size () - g.bytes (), g.bytes () });
101+ hasher->update (n_buf.data (), n_buf.size ());
102+ hasher->update (g_buf.data (), g_buf.size ());
98103 hasher->final (hash.data ());
99- return Botan::BigInt::decode ( hash.data (), hash.size ());
104+ return Botan::BigInt::from_bytes (std::span< const uint8_t >( hash.data (), hash.size () ));
100105}
101106
102107Botan::BigInt compute_x (std::string_view identifier, std::string_view password,
@@ -123,7 +128,7 @@ Botan::BigInt compute_x(std::string_view identifier, std::string_view password,
123128 hasher->final (hash.data ());
124129
125130 if (mode == Compliance::RFC5054) {
126- return Botan::BigInt::decode ( hash.data (), hash.size ());
131+ return Botan::BigInt::from_bytes (std::span< const uint8_t >( hash.data (), hash.size () ));
127132 } else {
128133 return detail::decode_flip (hash);
129134 }
@@ -194,4 +199,4 @@ Botan::BigInt generate_verifier(std::string_view identifier, std::string_view pa
194199 return detail::generate (identifier, password, generator, salt, mode);
195200}
196201
197- } // srp6, ember
202+ } // srp6, ember
0 commit comments