[openssl/openssl] 63a89d: Add OSSL_FN greatest common divisor

"'Richard Levitte' via openssl-commits" <[email protected]> Mon, 27 Jul 2026 02:44:37 -0700
Newsgroups gmane.comp.encryption.openssl.cvs
Message-ID <openssl/openssl/push/refs/heads/feature/ossl_fn/[email protected]>
  Branch: refs/heads/feature/ossl_fn
  Home:   https://github.com/openssl/openssl
  Commit: 63a89d0f0e4287a386859b28970f2a491b740d3d
      https://github.com/openssl/openssl/commit/63a89d0f0e4287a386859b28970f2a491b740d3d
  Author: Richard Levitte <[email protected]>
  Date:   2026-07-24 (Fri, 24 Jul 2026)

  Changed paths:
    M crypto/fn/build.info
    A crypto/fn/fn_gcd.c
    M include/crypto/fn.h
    M test/fn_api_test.c

  Log Message:
  -----------
  Add OSSL_FN greatest common divisor

Add a fixed-size greatest-common-divisor operation for OSSL_FN values
and cover it with direct API tests.

The implementation is a faithful, constant-time translation of
BN_gcd()'s Bernstein-Yang-inspired binary GCD: loop conditions are
computed as masks, conditional swaps use a limb-wise XOR swap mirroring
BN_consttime_swap(), and value-branching zero shortcuts are avoided.
Its constant-time profile matches BN_gcd(); the iteration count and the
add/subtract selection in the signed elimination step leak exactly as in
the BN counterpart.

The tests exercise zero operands, gcd(1, a), common powers of two,
wider and narrower destinations (including a multi-limb truncation case
that drops a non-zero top limb), mixed operand widths, and result
aliasing for both single- and multi-limb results.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/2017
Assisted-by: Pi:openai/gpt-5.5
Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Jakub Zelenka <[email protected]>
Reviewed-by: Igor Ustinov <[email protected]>
MergeDate: Mon Jul 27 09:42:56 2026
(Merged from https://github.com/openssl/openssl/pull/31833)


  Commit: ff4f86bece813fa72ac60d32108a302e2830cd4e
      https://github.com/openssl/openssl/commit/ff4f86bece813fa72ac60d32108a302e2830cd4e
  Author: Richard Levitte <[email protected]>
  Date:   2026-07-24 (Fri, 24 Jul 2026)

  Changed paths:
    M test/fntest.c
    M test/recipes/11-test_fn.t

  Log Message:
  -----------
  Add OSSL_FN gcd stanza tests in fntest

Wire OSSL_FN_gcd() into the fntest stanza harness with a file_gcd()
handler mirroring file_product(): the operands are obtained as read-only
OSSL_FN views via bn_get_ossl_fn(), the result is acquired with
bn_acquire_ossl_fn(), and the OSSL_FN_CTX is sized with
OSSL_FN_gcd_ctx_size().  The result is compared against the expected
GCD from the stanza, exactly as bntest's file_gcd() compares BN_gcd().

Add bngcd.txt to the 11-test_fn.t recipe so the full 4327-vector gcd
corpus runs against OSSL_FN_gcd(), giving the stanza-driven BN-vs-OSSL_FN
parity coverage that the rest of fntest provides for add/mul/sqr/shift.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/2017
Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Jakub Zelenka <[email protected]>
Reviewed-by: Igor Ustinov <[email protected]>
MergeDate: Mon Jul 27 09:42:58 2026
(Merged from https://github.com/openssl/openssl/pull/31833)


Compare: https://github.com/openssl/openssl/compare/95b4936aa1d8...ff4f86bece81

To unsubscribe from these emails, change your notification settings at https://github.com/openssl/openssl/settings/notifications

-- 
You received this message because you are subscribed to the Google Groups "openssl-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/a/openssl.org/d/msgid/openssl-commits/openssl/openssl/push/refs/heads/feature/ossl_fn/95b493-ff4f86%40github.com.