-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement secure_random() #727
Conversation
3rdparty/SConscript
Outdated
|
||
if not conf.CheckLibWithHeaderExt('ssl', 'openssl/rand.h', 'C', run=not is_crosscompiling): | ||
if not conf.CheckLibWithHeaderExt('ssl', 'openssl/rand.h', 'C', run=not is_crosscompiling) or not conf.CheckLibWithHeaderExt('crypto', 'openssl/crypto.h', 'C', run=not is_crosscompiling): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello!
it's enough to validate the presence of openssl/rand.h here; validating every single file's presence we use in the project is too redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't really get why, but this how i could get -lcrypto
to be linked.
This, on the other hand results in linkage errors :
conf.env.AddManualDependency(libs=['ssl','crypto'], prefix=ossl_prefix)
if not conf.CheckLibWithHeaderExt('ssl', 'openssl/rand.h', 'C', run=not is_crosscompiling): #or not conf.CheckLibWithHeaderExt('crypto', 'openssl/crypto.h', 'C', run=not is_crosscompiling):
env.Die("OpenSSL not found (see 'config.log' for details)") ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't really get why, but this how i could get
-lcrypto
to be linked.
Ah, sorry, you are checking a different library here. Then it's OK.
You can also make shorten the condition:
if not conf.CheckLibWithHeaderExt(['ssl', 'crypto'], ['openssl/rand.h', 'openssl/crypto.h'], 'C', run=not is_crosscompiling):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we have AddPkgConfigDependency('libssl')
, but don't have AddPkgConfigDependency('libcrypto')
, it should be added, because they're different packages in pkg-config:
pkg-config --cflags --libs libssl
-lssl
pkg-config --cflags --libs libcrypto
-lcrypto
And in this case it indeed makes sense to add a second check. openssl/rand.h
checks that libssl worked, and openssl/crypto.h
checks that lubcrypto worked.
i don't really get why, but this how i could get -lcrypto to be linked.
Likely CheckLibWithHeaderExt adds it, but we should no rely on it. Actually it's probably a bug that should be fixed (not in this PR of course).
Also please avoid long lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, i now have this. The AddPkgConfigDependency('libcrypto')
does it (even without CheckLib...) . is it ok ?
elif 'openssl' in system_dependencies:
ossl_prefix = None
# macOS: fallback to use a brew-installed openssl
if meta.platform == 'darwin' and not is_crosscompiling:
ossl_prefix = env.FindBrewPackage('openssl')
conf = Configure(env, custom_tests=env.CustomTests)
if not conf.AddPkgConfigDependency('libssl', '--cflags --libs', add_prefix=ossl_prefix):
conf.env.AddManualDependency(libs=['ssl'], prefix=ossl_prefix)
if not conf.AddPkgConfigDependency('libcrypto', '--cflags --libs', add_prefix=ossl_prefix):
conf.env.AddManualDependency(libs=['crypto'], prefix=ossl_prefix)
if not conf.CheckLibWithHeaderExt('ssl', 'openssl/rand.h', 'C', run=not is_crosscompiling) or \
not conf.CheckLibWithHeaderExt('crypto', 'openssl/crypto.h', 'C', run=not is_crosscompiling):
env.Die("OpenSSL not found (see 'config.log' for details)")
env = conf.Finish()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was not intended to remove the original fast_random version, so please just keep it
@@ -17,7 +17,6 @@ namespace core { | |||
namespace { | |||
|
|||
uint32_t rng_state; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
// Wrappers | ||
// To use for external calls | ||
|
||
uint32_t secure_random() { | ||
return fast_random(); | ||
}; | ||
|
||
uint32_t secure_random_range(uint32_t from, uint32_t to) { | ||
return fast_random_range(from, to); | ||
}; | ||
|
||
double secure_random_gaussian() { | ||
return fast_random_gaussian(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be implemented in target_nocsprng (as written in #683)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, i don't understand. That is target_nocsprng.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, the fast_random implementation should be the only in this file, and secure_random()
function implemented through calls to fast_random*()
is the only one to go to the target_nocsprng directory.
//! @file roc_core/fast_random.h | ||
//! @file roc_core/target_nocsprng/roc_core/secure_random.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original file should be kept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was asked by gavv : #683 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be changed; checkout the task description and revert other places please
Thanks for PR! Regarding my comment from matrix that you linked above: #683 (comment) I guess I was not very clear. The idea is:
That's what I tried to say in that comment, we don't need two separate implementations of tests for secure_random, however we still need separate tests for fast_random and secure_random. |
oh...i really misinterpreted it all. It will be fixed. |
🤖 The latest upstream change made this pull request unmergeable. Please resolve the merge conflicts. |
as asked by issue #683
secure_random()
fast_random()
in src, tests and benchmarks-lcrypto
linking