2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/portability/GTest.h>
18 #include <folly/portability/OpenSSL.h>
20 using namespace folly;
21 using namespace testing;
23 TEST(OpenSSLPortabilityTest, TestRSASetter) {
25 RSA* public_key = RSA_new();
29 const BIGNUM* n_actual = BN_new();
30 const BIGNUM* e_actual = BN_new();
31 const BIGNUM* d_actual = BN_new();
32 EXPECT_TRUE(BN_set_bit(n, 1));
33 EXPECT_TRUE(BN_set_bit(e, 3));
34 EXPECT_TRUE(BN_set_bit(d, 2));
35 RSA_set0_key(r, n, e, d);
36 RSA_get0_key(r, &n_actual, &e_actual, &d_actual);
37 // BN_cmp returns 0 if the two BIGNUMs are equal
38 EXPECT_FALSE(BN_cmp(n, n_actual));
39 EXPECT_FALSE(BN_cmp(e, e_actual));
40 EXPECT_FALSE(BN_cmp(d, d_actual));
42 RSA_set0_key(public_key, n, e, nullptr);
43 const BIGNUM* n_public = BN_new();
44 const BIGNUM* e_public = BN_new();
45 RSA_get0_key(public_key, &n_public, &e_public, nullptr);
46 EXPECT_FALSE(BN_cmp(n, n_public));
47 EXPECT_FALSE(BN_cmp(e, e_public));