From: Stefan Berger <stefanb@linux.ibm.com>
To: Fabian <fabianblatter09@gmail.com>
Cc: lukas@wunner.de, ignat@linux.win, herbert@gondor.apana.org.au,
davem@davemloft.net, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ecc - Optimize vli additive operations using compiler builtins
Date: Wed, 10 Jun 2026 10:52:13 -0400 [thread overview]
Message-ID: <af632d11-baea-4314-ac17-d81502240a5c@linux.ibm.com> (raw)
In-Reply-To: <CAGtAT=nJOAxecN+eYVwkzQAUcr2BaBhAO=ni9hWqdRKUQ06=fA@mail.gmail.com>
On 6/9/26 4:51 PM, Fabian wrote:
> On Tue, 9 Jun 2026 at 20:58, Stefan Berger <stefanb@linux.ibm.com> wrote:
>>
>>
>>
>> On 6/7/26 7:24 AM, Fabian Blatter wrote:
>>> Replace the software carry flag emulation with compiler builtins.
>>>
>>> Even the newest compilers struggle with taking advantage of the
>>> hardware carry flag. Compiler builtins allow the compiler to
>>> much more easily achieve this while still remaining constant-time.
>>
>> It looks like you made vli_usub and vli_uadd constant-time now because
>> otherwise the loops could be ended early once borrow == 0 or carry == 0
>> respectively. Are all the other functions that operate on the private
>> keys constant-time?
>>
>
> Thanks for the reply,
>
> My primary goal with this patch was performance optimization.
> I did not add early exiting because the original version didn't either.
>
> To answer your question: No, some other functions in ecc.c
> are not constant-time. For example, vli_is_zero and vli_cmp both
> contain early exits.
> > My patch does remove the branches in the inner loop,
> however, the original ones were already constant-time in practice,
> because the compiler replaces the branches with cmov's.
> > I am happy to make any changes to this patch if you like.
ecrdsa calls ecc_is_pubkey_valid_partial -> vli_mod_square_fast ->
vli_mmod_fast and then may call vli_usub or vli_uadd via
vli_mmod_special2 or vli_mmod_barret.
ecc_point_mult operates on a private key and will call vli_mmod_fast and
for some non-NIST keys it may call either one of vli_usub or vli_uadd
via vli_mmod_special2 or vli_mmod_barret.
Due to the private key operations it's probably better to keep the
functions constant-time for now.
> I could also look into making `vli_cmp` and `vli_is_zero`,
> or others constant-time in a future patch.
I wonder whether it would be practical to suffix constant-time functions
with _ct so that it becomes visible whether the call paths of functions
operation on private keys only call _ct functions? Sometimes one could
optimize functions shared by private and public key operations for
performance -- call them with 'bool ct' in this case and suffix them
with _oct (o=optimized + ct) indicating that they support both variants?
next prev parent reply other threads:[~2026-06-10 14:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 11:24 Fabian Blatter
2026-06-09 18:58 ` Stefan Berger
2026-06-09 20:51 ` Fabian
2026-06-10 14:52 ` Stefan Berger [this message]
2026-06-10 16:57 ` Fabian
2026-06-10 17:25 ` Stefan Berger
2026-06-23 13:37 ` Lukas Wunner
2026-06-23 19:10 ` Fabian
2026-07-05 5:32 ` Herbert Xu
2026-08-03 8:32 ` Fabian
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=af632d11-baea-4314-ac17-d81502240a5c@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=davem@davemloft.net \
--cc=fabianblatter09@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@linux.win \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
/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®