}
}
+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
}
}
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
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));
+}