DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: Kai Ji <kai.ji@intel.com>, <dev@dpdk.org>,
	<stephen@networkplumber.org>, <gakhil@marvell.com>,
	<konstantin.ananyev@huawei.com>, <thomas@monjalon.net>
Subject: Re: [dpdk-dev v5 1/2] eal: introduce rte_timingsafe_memcmp() based on OpenBSD API
Date: Thu, 2 Oct 2025 09:09:56 +0100	[thread overview]
Message-ID: <aN4zVGzxTDI5Ch8g@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35F6548B@smartserver.smartshare.dk>

On Wed, Oct 01, 2025 at 08:57:02PM +0200, Morten Brørup wrote:
> > From: Kai Ji [mailto:kai.ji@intel.com]
> > Sent: Wednesday, 1 October 2025 17.33
> > 
> > Bugzilla ID: 1773
> > https://bugs.dpdk.org/show_bug.cgi?id=1773
> > 
> > Signed-off-by: Kai Ji <kai.ji@intel.com>
> > ---
> >  lib/eal/include/rte_memory.h | 38 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 38 insertions(+)
> > 
> > diff --git a/lib/eal/include/rte_memory.h
> > b/lib/eal/include/rte_memory.h
> > index dcc0e69cfe..6939c1caad 100644
> > --- a/lib/eal/include/rte_memory.h
> > +++ b/lib/eal/include/rte_memory.h
> > @@ -746,6 +746,44 @@ __rte_experimental
> >  void
> >  rte_memzero_explicit(void *dst, size_t sz);
> > 
> > +/**
> > + * @warning
> > + * @b EXPERIMENTAL: this API may change without prior notice.
> > + *
> > + * Constant-time memory comparison.
> > + *
> > + * This function compares two memory regions in constant time, making
> > it
> > + * resistant to timing side-channel attacks. The execution time
> > depends only
> > + * on the length parameter, not on the actual data values being
> > compared.
> > + *
> > + * This is particularly important for cryptographic operations where
> > timing
> > + * differences could leak information about secret keys, passwords, or
> > other
> > + * sensitive data.
> > + *
> > + * @param a
> > + *   Pointer to the first memory region to compare
> > + * @param b
> > + *   Pointer to the second memory region to compare
> > + * @param n
> > + *   Number of bytes to compare
> > + * @return
> > + *   0 if the memory regions are identical, non-zero if they differ
> > + */
> > +__rte_experimental
> > +static inline int
> > +rte_timingsafe_memcmp(const void *a, const void *b, size_t n)
> > +{
> > +	const volatile uint8_t *pa = (const volatile uint8_t *)a;
> > +	const volatile uint8_t *pb = (const volatile uint8_t *)b;
> > +	uint8_t result = 0;
> > +	size_t i;
> > +
> > +	for (i = 0; i < n; i++)
> > +		result |= pa[i] ^ pb[i];
> > +
> > +	return result;
> > +}
> > +
> >  #ifdef __cplusplus
> >  }
> >  #endif
> > --
> > 2.34.1
> 
> NAK.
> This returns (binary) non-equality only. It does not return (tri-state) <0, 0, or >0, so it's not like memcmp or FreeBSD timingsafe_memcmp.
> 
> Also, please put the function ("memeq") first in the name, and then the extra property ("timingsafe") last, like rte_memzero_explicit.
> Like this:
> __rte_experimental
> static inline bool
> rte_memeq_timingsafe(const void *a, const void *b, size_t n)
> {
> 	const volatile uint8_t *pa = (const volatile uint8_t *)a;
> 	const volatile uint8_t *pb = (const volatile uint8_t *)b;
> 	uint8_t result = 0;
> 	size_t i;
> 
> 	for (i = 0; i < n; i++)
> 		result |= pa[i] ^ pb[i];
> 
> 	return result == UINT8_C(0);
> }
> 
> Stephen, agree?
> 

Not sure I agree with you on the naming. I'd rather see us adopt the BSD
function (present on multiple BSDs) rather than rolling our own completely
new function with new behaviour.

/Bruce

  reply	other threads:[~2025-10-02  8:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-25 10:22 [dpdk-dev v1] cryptodev: introduce constant-time memory comparison Kai Ji
2025-09-25 10:33 ` [EXTERNAL] " Akhil Goyal
2025-09-25 20:47   ` Thomas Monjalon
2025-09-26  7:55     ` Bruce Richardson
2025-09-26  7:58       ` Bruce Richardson
2025-09-26 12:34       ` Morten Brørup
2025-09-26  8:13     ` Konstantin Ananyev
2025-09-26  8:16       ` Konstantin Ananyev
2025-09-26 15:49 ` [dpdk-dev v2 1/2] eal: Add rte_consttime_memsq() to prevent timing attacks memcmp Kai Ji
2025-09-26 15:49   ` [dpdk-dev v2 2/2] crypto/ipsec-mb: use constant-time memory comparison Kai Ji
2025-09-26 16:02   ` [dpdk-dev v3 1/2] eal: Add rte_consttime_memneq() to prevent timing attacks memcmp Kai Ji
2025-09-26 16:02     ` [dpdk-dev v3 2/2] crypto/ipsec-mb: use constant-time memory comparison Kai Ji
2025-09-26 18:12     ` [dpdk-dev v3 1/2] eal: Add rte_consttime_memneq() to prevent timing attacks memcmp Stephen Hemminger
2025-09-26 19:17     ` Morten Brørup
2025-09-26 20:15       ` Stephen Hemminger
2025-09-29 14:50     ` [dpdk-dev v4 1/2] eal: Add mem equal and non-equal " Kai Ji
2025-09-29 14:50       ` [dpdk-dev v4 2/2] crypto/ipsec-mb: use constant-time memory comparison Kai Ji
2025-09-29 23:54         ` Stephen Hemminger
2025-09-29 16:32       ` [dpdk-dev v4 1/2] eal: Add mem equal and non-equal to prevent timing attacks memcmp Stephen Hemminger
2025-09-29 17:48       ` Morten Brørup
2025-09-29 22:48         ` Stephen Hemminger
2025-09-30  6:16           ` Morten Brørup
2025-10-01 15:32       ` [dpdk-dev v5 1/2] eal: introduce rte_timingsafe_memcmp() based on OpenBSD API Kai Ji
2025-10-01 15:32         ` [dpdk-dev v5 2/2] crypto/ipsec-mb: use constant-time memory comparison Kai Ji
2025-10-01 17:26         ` [dpdk-dev v5 1/2] eal: introduce rte_timingsafe_memcmp() based on OpenBSD API Bruce Richardson
2025-10-01 18:57         ` Morten Brørup
2025-10-02  8:09           ` Bruce Richardson [this message]
2025-10-02  8:37             ` Morten Brørup
2025-10-02  8:40               ` Bruce Richardson
2025-10-02 15:32         ` [dpdk-dev v6 1/2] eal: introduce rte_memeq_timingsafe() based on FreeBSD API Kai Ji
2025-10-02 15:32           ` [dpdk-dev v6 2/2] crypto/ipsec-mb: use constant-time memory comparison Kai Ji
2025-09-26 18:07   ` [dpdk-dev v2 1/2] eal: Add rte_consttime_memsq() to prevent timing attacks memcmp Stephen Hemminger
2025-09-29  7:39     ` Bruce Richardson
2025-09-29 23:43   ` Stephen Hemminger

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=aN4zVGzxTDI5Ch8g@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=kai.ji@intel.com \
    --cc=konstantin.ananyev@huawei.com \
    --cc=mb@smartsharesystems.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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;
as well as URLs for NNTP newsgroup(s).