Commit 4f6e47f9 authored by Ankit Shah's avatar Ankit Shah Committed by Facebook Github Bot

Getters and setters for ECDSA_SIG

Summary:
Added getters and setters for ECDSA_SIG to allow for compatibility
between OpenSSL 1.1.0 and 1.0.2

Reviewed By: knekritz

Differential Revision: D5408934

fbshipit-source-id: 7a3d9df774728c81270cc4da34c75202018e430d
parent 520e20a8
......@@ -333,6 +333,30 @@ void RSA_get0_crt_params(
}
}
int ECDSA_SIG_set0(ECDSA_SIG* sig, BIGNUM* r, BIGNUM* s) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (r == nullptr || s == nullptr) {
return 0;
}
BN_clear_free(sig->r);
BN_clear_free(sig->s);
sig->r = r;
sig->s = s;
return 1;
}
void ECDSA_SIG_get0(
const ECDSA_SIG* sig,
const BIGNUM** pr,
const BIGNUM** ps) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (pr != nullptr) {
*pr = sig->r;
}
if (ps != nullptr) {
*ps = sig->s;
}
}
#endif
}
}
......
......@@ -164,6 +164,8 @@ void RSA_get0_crt_params(
const BIGNUM** dmp1,
const BIGNUM** dmq1,
const BIGNUM** iqmp);
int ECDSA_SIG_set0(ECDSA_SIG* sig, BIGNUM* r, BIGNUM* s);
void ECDSA_SIG_get0(const ECDSA_SIG* sig, const BIGNUM** pr, const BIGNUM** ps);
#endif
#if FOLLY_OPENSSL_IS_110
......
......@@ -59,3 +59,19 @@ TEST(OpenSSLPortabilityTest, TestRSASetter) {
EXPECT_FALSE(BN_cmp(n_public, n_public_actual));
EXPECT_FALSE(BN_cmp(e_public, e_public_actual));
}
TEST(OpenSSLPortabilityTest, TestEcdsaSigPortability) {
EcdsaSigUniquePtr ecdsa(ECDSA_SIG_new());
BIGNUM* r = BN_new();
BIGNUM* s = BN_new();
BIGNUM* r_actual;
BIGNUM* s_actual;
EXPECT_TRUE(BN_set_bit(r, 1));
EXPECT_TRUE(BN_set_bit(s, 2));
EXPECT_TRUE(ECDSA_SIG_set0(ecdsa.get(), r, s));
ECDSA_SIG_get0(
ecdsa.get(), (const BIGNUM**)&r_actual, (const BIGNUM**)&s_actual);
// BN_cmp returns 0 if the two BIGNUMs are equal
EXPECT_FALSE(BN_cmp(r, r_actual));
EXPECT_FALSE(BN_cmp(s, s_actual));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment