Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1369091 - check that e > 2 and odd in RSA_NewKey, r=franziskus
Summary: Patch for bug 1369091 Reviewers: franziskus Reviewed By: franziskus Bug #: 1369091 Differential Revision: https://phabricator.services.mozilla.com/D165 --HG-- extra : amend_source : 849b90486eedd57ecda4f2c0e95791e53aa1f7da
- Loading branch information
Jonas Allmann
committed
Nov 7, 2017
1 parent
0563d9e
commit 01c31d8
Showing
3 changed files
with
83 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include <stdint.h> | ||
|
||
#include "blapi.h" | ||
#include "secitem.h" | ||
|
||
template <class T> | ||
struct ScopedDelete { | ||
void operator()(T* ptr) { | ||
if (ptr) { | ||
PORT_FreeArena(ptr->arena, PR_TRUE); | ||
} | ||
} | ||
}; | ||
|
||
typedef std::unique_ptr<RSAPrivateKey, ScopedDelete<RSAPrivateKey>> | ||
ScopedRSAPrivateKey; | ||
|
||
class RSANewKeyTest : public ::testing::Test { | ||
protected: | ||
RSAPrivateKey* CreateKeyWithExponent(int keySizeInBits, | ||
unsigned char publicExponent) { | ||
SECItem exp = {siBuffer, 0, 0}; | ||
unsigned char pubExp[1] = {publicExponent}; | ||
exp.data = pubExp; | ||
exp.len = 1; | ||
|
||
return RSA_NewKey(keySizeInBits, &exp); | ||
} | ||
}; | ||
|
||
TEST_F(RSANewKeyTest, expOneTest) { | ||
ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x01)); | ||
ASSERT_TRUE(key == nullptr); | ||
} | ||
TEST_F(RSANewKeyTest, expTwoTest) { | ||
ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x02)); | ||
ASSERT_TRUE(key == nullptr); | ||
} | ||
TEST_F(RSANewKeyTest, expFourTest) { | ||
ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x04)); | ||
ASSERT_TRUE(key == nullptr); | ||
} | ||
TEST_F(RSANewKeyTest, WrongKeysizeTest) { | ||
ScopedRSAPrivateKey key(CreateKeyWithExponent(2047, 0x03)); | ||
ASSERT_TRUE(key == nullptr); | ||
} | ||
|
||
TEST_F(RSANewKeyTest, expThreeTest) { | ||
ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x03)); | ||
ASSERT_TRUE(key != nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters