SecRandomCopyBytes in Sign with Apple #10732
-
Hi: I am reviewing sign with apple, and I notice that SecRandomCopyBytes is called multiple times (1 per byte) instead of fill the nonce bytes length at once. Is this related to something about the strength of the nonce? Thanks in advance for the clarification Extracted from https://firebase.google.com/docs/auth/ios/apple : let randoms: [UInt8] = (0 ..< 16).map { _ in
var random: UInt8 = 0
let errorCode = SecRandomCopyBytes(kSecRandomDefault, 1, &random)
if errorCode != errSecSuccess {
fatalError(
"Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)"
)
}
return random
} What I think that can be done let length = 32
let randomBytes = [Int8](repeating: 0, count: length)
let errorCode = SecRandomCopyBytes(kSecRandomDefault, length, &random)
if errorCode != errSecSuccess {
fatalError(
"Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)"
)
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @jesus-mg-ios, thanks for pointing that out. I can't find any documentation that specifies that calling In your simplified code snippet, I think the |
Beta Was this translation helpful? Give feedback.
Hi @jesus-mg-ios, thanks for pointing that out. I can't find any documentation that specifies that calling
SecRandomCopyBytes
multiple times (1 per byte) instead of once (with multiple bytes) results in nonces with different cryptographic strengths.In your simplified code snippet, I think the
length
should be16
to match that of the original snippet's number of bytes, right?