Skip to content

Commit 90d28e6

Browse files
authored
Zeroize data in private key construction (#4562)
1 parent c4dc73b commit 90d28e6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/PrivateKey.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ PrivateKey::PrivateKey(const Data& data, TWCurve curve) {
5555
_impl = Rust::wrapTWPrivateKey(privkey);
5656
}
5757

58+
PrivateKey::PrivateKey(const std::string& data, TWCurve curve) {
59+
auto bytes = TW::data(data);
60+
*this = PrivateKey(bytes, curve);
61+
memzero(bytes.data(), bytes.size());
62+
}
63+
5864
PrivateKey::PrivateKey(
5965
const Data& key1, const Data& extension1, const Data& chainCode1,
6066
const Data& key2, const Data& extension2, const Data& chainCode2,

src/PrivateKey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PrivateKey {
5050

5151
/// Initializes a private key from a string of bytes and a curve.
5252
/// Signing functions will throw an exception if the provided curve is different from the one specified.
53-
explicit PrivateKey(const std::string& data, TWCurve curve) : PrivateKey(TW::data(data), curve) {}
53+
explicit PrivateKey(const std::string& data, TWCurve curve);
5454

5555
/// Initializes a Cardano style key with a specified curve.
5656
/// Signing functions will throw an exception if the provided curve is different from the one specified.

0 commit comments

Comments
 (0)