diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-04-24 17:39:58 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-02 12:24:10 +0200 |
commit | e015ffd5f0812b102fc4c6435a42229f4fe838c5 (patch) | |
tree | 7b660364a384046d12d1471f39ad1f53783f3d45 /Libraries | |
parent | 05e2c7d9cf529c4b635f762fc1b5683c076cb00e (diff) | |
download | serenity-e015ffd5f0812b102fc4c6435a42229f4fe838c5.zip |
LibCrypto: Ensure that EME padding does not contain zeros
With this fix, we can now reliably open TLS connections!
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibCrypto/PK/RSA.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibCrypto/PK/RSA.cpp b/Libraries/LibCrypto/PK/RSA.cpp index 90e0d8098e..9fae5047bd 100644 --- a/Libraries/LibCrypto/PK/RSA.cpp +++ b/Libraries/LibCrypto/PK/RSA.cpp @@ -233,6 +233,12 @@ void RSA_PKCS1_EME::encrypt(const ByteBuffer& in, ByteBuffer& out) u8 ps[ps_length]; arc4random_buf(ps, ps_length); + // since arc4random can create zeros (shocking!) + // we have to go through and un-zero the zeros + for (size_t i = 0; i < ps_length; ++i) + if (!ps[i]) + ps[i] = 0xfe; + u8 paddings[] { 0x00, 0x02 }; out.overwrite(0, paddings, 2); |