Skip to content

Conversation

@yigityazicilar
Copy link
Contributor

Motivation:

This change implements the core cryptographic routine for Oblivious DNS over HTTPS (ODoH) as specified in RFC 9230.

Modifications:

  • Added complete ODoH.Routine struct with client-side and server-side cryptographic operations
  • Added comprehensive usage documentation with complete client and server examples
  • Created full roundtrip test validating end-to-end encryption/decryption flow

Result:

The library now provides RFC9230 compliant ODoH cryptographic functionality.

@josephnoir josephnoir added the 🆕 semver/minor Adds new public API. label Sep 9, 2025
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) })
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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) })
Copy link
Contributor

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) }
Copy link
Contributor

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.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, LGTM.

@Lukasa Lukasa merged commit 9e16b96 into apple:main Sep 15, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants