mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
stdlib: add the swift_clearSensitive runtime function
This commit is contained in:
@@ -338,3 +338,16 @@ func arc4random_buf(buf: UnsafeMutableRawPointer, nbytes: Int)
|
||||
public func swift_stdlib_random(_ buf: UnsafeMutableRawPointer, _ nbytes: Int) {
|
||||
arc4random_buf(buf: buf, nbytes: nbytes)
|
||||
}
|
||||
|
||||
@_cdecl("swift_clearSensitive")
|
||||
@inline(never)
|
||||
public func swift_clearSensitive(buf: UnsafeMutableRawPointer, nbytes: Int) {
|
||||
// TODO: use memset_s if available
|
||||
// Though, it shouldn't make too much difference because the `@inline(never)` should prevent
|
||||
// the optimizer from removing the loop below.
|
||||
let bytePtr = buf.assumingMemoryBound(to: UInt8.self)
|
||||
for i in 0..<nbytes {
|
||||
bytePtr[i] = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user