public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [Question] Redundant ternary operators in nhpoly1305/sha256 digest functions?
@ 2026-01-14 15:38 Jang Ingyu
  2026-01-14 22:32 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Jang Ingyu @ 2026-01-14 15:38 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, linux-crypto, linux-kernel, Ingyu Jang

From: Ingyu Jang <ingyujang25@korea.ac.kr>

Hi,

I noticed that in arch/x86/crypto/, several digest functions use
the ternary operator (?:) to chain function calls:

In nhpoly1305-avx2-glue.c and nhpoly1305-sse2-glue.c:

  return crypto_nhpoly1305_init(desc) ?:
         nhpoly1305_xxx_update(desc, src, srclen) ?:
         crypto_nhpoly1305_final(desc, out);

In sha256_ssse3_glue.c (sha256_ssse3_digest, sha256_avx_digest,
sha256_avx2_digest, sha256_ni_digest):

  return sha256_base_init(desc) ?:
         sha256_xxx_finup(desc, data, len, out);

However, all the functions being checked always return 0:
  - crypto_nhpoly1305_init() always returns 0
  - nhpoly1305_xxx_update() always returns 0
  - crypto_nhpoly1305_final() always returns 0
  - sha256_base_init() always returns 0

This makes the short-circuit evaluation of ?: unnecessary.

Is this intentional defensive coding for potential future changes,
or could this be cleaned up?

Thanks,
Ingyu Jang

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-14 22:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 15:38 [Question] Redundant ternary operators in nhpoly1305/sha256 digest functions? Jang Ingyu
2026-01-14 22:32 ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox