[PR #2416] [MERGED] Use u32 internally when randomizing case of labels #3025

Closed
opened 2026-03-16 11:21:13 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hickory-dns/hickory-dns/pull/2416
Author: @divergentdave
Created: 9/3/2024
Status: Merged
Merged: 9/3/2024
Merged by: @djc

Base: mainHead: david/case-randomization-u32


📝 Commits (1)

  • e7d8aed Use u32 internally when randomizing case of labels

📊 Changes

1 file changed (+5 additions, -5 deletions)

View changed files

📝 crates/proto/src/rr/domain/name.rs (+5 -5)

📄 Description

This is a follow-up to #2403 that changes how the case of labels is randomized. The temporary variable holding to-be-used random bits is changed from an i16 to an u32, and the update part of the loop is changed to match.

I changed from 16 to 32 bits because the rand crate's RNGs primarily deal in either u32s or u64s. The implementation of Distribution<u16> for Standard just calls rng.next_u32() and truncates, so this change will cut RNG calls in half for longer names.

I changed from a signed integer to an unsigned integer, and deleted the associated comment, because I could not reproduce this issue. My best guess is that there was an off-by-one issue in an earlier version of the code. Plus, I'd rather that the shift operation use zero extension, rather than sign extension, because our tests can catch a character that's never randomized, but they can't currently catch correlation between the case of two characters, which is just as bad for entropy.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hickory-dns/hickory-dns/pull/2416 **Author:** [@divergentdave](https://github.com/divergentdave) **Created:** 9/3/2024 **Status:** ✅ Merged **Merged:** 9/3/2024 **Merged by:** [@djc](https://github.com/djc) **Base:** `main` ← **Head:** `david/case-randomization-u32` --- ### 📝 Commits (1) - [`e7d8aed`](https://github.com/hickory-dns/hickory-dns/commit/e7d8aed7656b39003b77d952c4f4b08ed7c3f7af) Use u32 internally when randomizing case of labels ### 📊 Changes **1 file changed** (+5 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/proto/src/rr/domain/name.rs` (+5 -5) </details> ### 📄 Description This is a follow-up to #2403 that changes how the case of labels is randomized. The temporary variable holding to-be-used random bits is changed from an `i16` to an `u32`, and the update part of the loop is changed to match. I changed from 16 to 32 bits because the `rand` crate's RNGs primarily deal in either `u32`s or `u64`s. The implementation of `Distribution<u16> for Standard` just calls `rng.next_u32()` and truncates, so this change will cut RNG calls in half for longer names. I changed from a signed integer to an unsigned integer, and deleted the associated comment, because I could not reproduce this issue. My best guess is that there was an off-by-one issue in an earlier version of the code. Plus, I'd rather that the shift operation use zero extension, rather than sign extension, because our tests can catch a character that's never randomized, but they can't currently catch correlation between the case of two characters, which is just as bad for entropy. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-16 11:21:13 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#3025
No description provided.