lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1b8921d46f7d70c7467ea0940d60220f05cccc5d.camel@nvidia.com>
Date: Tue, 18 Feb 2025 20:51:06 +0000
From: Timur Tabi <ttabi@...dia.com>
To: Alexandre Courbot <acourbot@...dia.com>, "daniel.almeida@...labora.com"
	<daniel.almeida@...labora.com>
CC: John Hubbard <jhubbard@...dia.com>, "dri-devel@...ts.freedesktop.org"
	<dri-devel@...ts.freedesktop.org>, "rust-for-linux@...r.kernel.org"
	<rust-for-linux@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "nouveau@...ts.freedesktop.org"
	<nouveau@...ts.freedesktop.org>, "dakr@...nel.org" <dakr@...nel.org>,
	"airlied@...il.com" <airlied@...il.com>, Ben Skeggs <bskeggs@...dia.com>
Subject: Re: [PATCH RFC 1/3] rust: add useful ops for u64

On Tue, 2025-02-18 at 22:16 +0900, Alexandre Courbot wrote:
> > A proper struct with `high` and `low` might be more verbose, but
> > it rules out this issue.
> 
> Mmm indeed, so we would have client code looking like:
> 
>   let SplitU64 { high, low } = some_u64.into_u32();
> 
> instead of 
> 
>   let (high, low) = some_u64.into_u32();
> 
> which is correct, and
> 
>   let (low, high) = some_u64.into_u32();
> 
> which is incorrect, but is likely to not be caught.

I'm new to Rust, so let me see if I get this right.

struct SplitU64 {
  high: u32,
  low: u32
}

So if you want to extract the upper 32 bits of a u64, you have to do this:

let split = some_u64.into_u32s();
let some_u32 = split.high;

as opposed to your original design:

let (some_u32, _) = some_u64.into_u32s();

Personally, I prefer the latter.  The other advantage is that into_u32s and
from_u32s are reciprocal:

assert_eq!(u64::from_u32s(u64::into_u32s(some_u64)), some_u64);

(or something like that)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ