-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve RNG security (#9) * Fix insecure prng (#3) - Add RDSEED and RDRAND instruction check in compile time - Prioritize RDSEED/RDRAND based RNG to produce random big number * Add RNG support for non-RDRAND, non-RDSEED systems (#5) - Use IPP-Crypto pseudo random number generator if none of those instructions are supported * Removing seed setup and replacing rng function for PrimeGen_BN (#8) - Remove seed setup for prime number generator - Add support to TRNGen_RDSEED and PRNGen_RDRAND for prime number generator Co-authored-by: Pengfei Zhao <pengfei.zhao@intel.com> * Refactor apply obfuscator (#10) - Refactor apply_obfuscator - minor typo fix * Update version for 1.1.4 * Update ipp-crypto version to use ippcp_2021.6 (#12) - Minor update to use IPP-Crypto v2021.6 * 13 errors building installing questions about docs (#15) * Minor fixes - Fix gbenchmark build error on other platforms - Fixed IPCLTargets typo - Update version to 1.1.4 Co-authored-by: Pengfei Zhao <pengfei.zhao@intel.com>
- Loading branch information
1 parent
c9f4f4a
commit ea6aa26
Showing
10 changed files
with
158 additions
and
132 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
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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ set(IPCL_SRCS pri_key.cpp | |
plaintext.cpp | ||
ciphertext.cpp | ||
util.cpp | ||
common.cpp | ||
) | ||
|
||
|
||
|
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,56 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "ipcl/common.hpp" | ||
|
||
#include <crypto_mb/exp.h> | ||
|
||
#include "ipcl/util.hpp" | ||
|
||
namespace ipcl { | ||
|
||
IppStatus ippGenRandom(Ipp32u* rand, int bits, void* ctx) { | ||
#ifdef IPCL_RNG_INSTR_RDSEED | ||
return ippsTRNGenRDSEED(rand, bits, ctx); | ||
#elif defined(IPCL_RNG_INSTR_RDRAND) | ||
return ippsPRNGenRDRAND(rand, bits, ctx); | ||
#else | ||
return ippsPRNGen(rand, bits, ctx); | ||
#endif | ||
} | ||
|
||
IppStatus ippGenRandomBN(IppsBigNumState* rand, int bits, void* ctx) { | ||
#ifdef IPCL_RNG_INSTR_RDSEED | ||
return ippsTRNGenRDSEED_BN(rand, bits, ctx); | ||
#elif defined(IPCL_RNG_INSTR_RDRAND) | ||
return ippsPRNGenRDRAND_BN(rand, bits, ctx); | ||
#else | ||
return ippsPRNGen_BN(rand, bits, ctx); | ||
#endif | ||
} | ||
|
||
BigNumber getRandomBN(int bits) { | ||
IppStatus stat; | ||
int bn_buf_size; | ||
|
||
int bn_len = BITSIZE_WORD(bits); | ||
stat = ippsBigNumGetSize(bn_len, &bn_buf_size); | ||
ERROR_CHECK(stat == ippStsNoErr, | ||
"getRandomBN: get IppsBigNumState context error."); | ||
|
||
IppsBigNumState* pBN = | ||
reinterpret_cast<IppsBigNumState*>(alloca(bn_buf_size)); | ||
ERROR_CHECK(pBN != nullptr, "getRandomBN: big number alloca error"); | ||
|
||
stat = ippsBigNumInit(bn_len, pBN); | ||
ERROR_CHECK(stat == ippStsNoErr, | ||
"getRandomBN: init big number context error."); | ||
|
||
stat = ippGenRandomBN(pBN, bits, NULL); | ||
ERROR_CHECK(stat == ippStsNoErr, | ||
"getRandomBN: generate random big number error."); | ||
|
||
return BigNumber{pBN}; | ||
} | ||
|
||
} // namespace ipcl |
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
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
Oops, something went wrong.