-
Notifications
You must be signed in to change notification settings - Fork 14
Add ODoH cryptographic routine implementation #44
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
| let nonceSize = self.ct.aead.nonceByteCount | ||
| let keySize = self.ct.aead.keyByteCount | ||
| let responseNonceSize = max(nonceSize, keySize) | ||
| let responseNonce = Data((0..<responseNonceSize).map { _ in UInt8.random(in: 0...255) }) |
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 fairly slow way to generate random numbers: we should at least be generating them 64-bytes at a time.
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.
We are only generating 16 bytes at the moment. Did you mean generate random numbers using UInt64s?
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.
Sorry, yes, 64-bits at a time.
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.
Should be ready.
| // Generate 8 bytes at a time | ||
| for _ in 0..<fullChunks { | ||
| let chunk = UInt64.random(in: UInt64.min...UInt64.max) | ||
| data.append(contentsOf: Swift.withUnsafeBytes(of: chunk) { Data($0) }) |
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.
We don't need to create the intermediate Data if we flip the order:
Swift.withUnsafeBytes(of: chunk) {
data.append(contentsOf: $0) )
}| } | ||
|
|
||
| let finalChunk = UInt64.random(in: UInt64.min...UInt64.max) | ||
| let finalData = Swift.withUnsafeBytes(of: finalChunk) { Data($0) } |
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.
Similar note here, we can apply prefix to the UnsafeRawBufferPointer and avoid the need to create a new temporary Data.
Lukasa
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.
Very nice, LGTM.
Motivation:
This change implements the core cryptographic routine for Oblivious DNS over HTTPS (ODoH) as specified in RFC 9230.
Modifications:
ODoH.Routinestruct with client-side and server-side cryptographic operationsResult:
The library now provides RFC9230 compliant ODoH cryptographic functionality.