mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, tytso@mit.edu, kees@kernel.org,
	linux@armlinux.org.uk, ydroneaud@opteya.com,
	gregkh@linuxfoundation.org, rdunlap@infradead.org
Subject: Re: [PATCH v3] random: add helpers for random numbers with given floor or range
Date: Thu, 17 Nov 2022 13:48:14 -0800	[thread overview]
Message-ID: <202211171347.92FDE65A6D@keescook> (raw)
In-Reply-To: <20221117192620.2304613-1-Jason@zx2c4.com>

On Thu, Nov 17, 2022 at 08:26:20PM +0100, Jason A. Donenfeld wrote:
> Now that we have get_random_u32_below(), it's nearly trivial to make
> inline helpers to compute get_random_u32_above() and
> get_random_u32_inclusive(), which will help clean up open coded loops
> and manual computations throughout the tree.
> 
> One snag is that in order to make get_random_u32_inclusive() operate on
> closed intervals, we have to do some (unlikely) special case handling if
> get_random_u32_interval(0, U32_MAX) is called. The least expensive way
> of doing this is actually to adjust the slowpath of
> get_random_u32_below() to have its undefined 0 result just return the
> output of get_random_u32(). We can make this basically free by calling
> get_random_u32() before the branch, so that the branch latency gets
> interleaved.
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

I really like these -- unambiguous! :) Thanks for adjusting this API.

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

-- 
Kees Cook

      reply	other threads:[~2022-11-17 21:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 16:35 [PATCH v2] " Jason A. Donenfeld
2022-11-17 16:41 ` Randy Dunlap
2022-11-17 19:26   ` [PATCH v3] " Jason A. Donenfeld
2022-11-17 21:48     ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202211171347.92FDE65A6D@keescook \
    --to=keescook@chromium.org \
    --cc=Jason@zx2c4.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=rdunlap@infradead.org \
    --cc=tytso@mit.edu \
    --cc=ydroneaud@opteya.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®