-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[embedded] Make RNG APIs available on embedded Swift #70458
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
Conversation
kubamracek
commented
Dec 14, 2023
- Make SystemRandomNumberGenerator, .random(), .random(in: ...), .randomElement() APIs available in embedded Swift.
- Add tests exercising those.
- Add a test that checks the symbol dependencies of program that use the random APIs, the only added dependency should be on a (relatively standard and commmon) arc4random_buf.
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.
are these functions weak? e.g. if I implement swift_stdlib_random in a platform definition to a non-cryptographic-secure-pseudo-random source but want to not claim arc4random_buf is implemented would that work?
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 is a good point, and I was previously thinking that we would just have Embedded Swift have a small fixed set of well-known basically-always-present-anyway dependencies, but I do see your point that it would really be useful to have more influence and control over things like this.
I don't think Swift has a notion of weak / override-able functions... does it? Though TBH even if it did, the linker based weak function replacement is arguably quite non-obvious and "too magical". I was thinking that an explicit solution would be better, something along the lines of:
public enum EmbeddedConfiguration {
// default is arc4random_buf...
public static var randomnessSource: (@convention(c) (UnsafeMutableRawPointer, Int) -> ()) = arc4random_buf
}
public func swift_stdlib_random(_ buf: UnsafeMutableRawPointer, _ nbytes: Int) {
EmbeddedConfiguration.randomnessSource(buf, nbytes)
}
// ...but the user can change it by simply doing this in the firmware startup code:
EmbeddedConfiguration.randomnessSource = my_other_randomness_provider
1dd82e3 to
0a55f36
Compare
|
@swift-ci please test |
1 similar comment
|
@swift-ci please test |
922b43b to
26c1067
Compare
|
@swift-ci please test |
rauhul
left a 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.
good enough for now, I'd like the link time error to be missing "swift_stdllib_random" but we can improve this later
|
@swift-ci please test |