[openssl/openssl] 12929d: OSSL_FN: Add the 'div' and 'mod' functions

"'Richard Levitte' via openssl-commits" <[email protected]> Fri, 24 Jul 2026 03:09:38 -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: 12929d385257f192265e094825ff8d253eb2e270
      https://github.com/openssl/openssl/commit/12929d385257f192265e094825ff8d253eb2e270
  Author: Richard Levitte <[email protected]>
  Date:   2026-07-24 (Fri, 24 Jul 2026)

  Changed paths:
    M crypto/err/openssl.txt
    M crypto/fn/build.info
    A crypto/fn/fn_div.c
    M crypto/fn/fn_err.c
    M include/crypto/fn.h
    M include/crypto/fnerr.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Add the 'div' and 'mod' functions

OSSL_FN_div() divides two numbers, and calculates the quotient and
the remainder.  The result OSSL_FNs may be of any size, and if they're
smaller than the results of dividing the operands, the results are
truncated to that size.

OSSL_FN_mod() is a very simple function that wraps around OSSL_FN_div()
and only returns the remainder.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/1852
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]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:13:58 2026
(Merged from https://github.com/openssl/openssl/pull/30822)


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

  Changed paths:
    M crypto/fn/fn_div.c
    M include/crypto/fn.h

  Log Message:
  -----------
  OSSL_FN: Add division context sizing

Add OSSL_FN_div_ctx_size() and make OSSL_FN_mod_ctx_size() a thin
inline wrapper around it.  The sizing remains conservative: it uses
allocated operand widths and does not duplicate the runtime scan that
trims the denominator to its highest non-zero limb.  Document both
helpers with Doxygen comments matching the mul/sqr ctx_size helpers.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/1852
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]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:14:00 2026
(Merged from https://github.com/openssl/openssl/pull/30822)


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

  Changed paths:
    M test/fntest.c

  Log Message:
  -----------
  OSSL_FN: Add div and mod stanza tests

Teach fntest to run the existing quotient/remainder stanzas through
OSSL_FN_div(), and additionally check the remainder against
OSSL_FN_mod().  fntest now runs all recognized stanzas from each
data file, so 11-test_fn.t passes the files directly without any
per-stanza filtering.  Also include crypto/fn.h before crypto/bn.h
in fntest so the OSSL_FN typedef is visible where bn.h uses it.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/1852
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]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:14:03 2026
(Merged from https://github.com/openssl/openssl/pull/30822)


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

  Changed paths:
    M crypto/fn/fn_shift.c
    M include/crypto/fn.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Add OSSL_FN right shifts

Add fixed-size right-shift operations for OSSL_FN values and cover them
with direct API tests.

The tests exercise bit and limb shifts, wider and narrower destinations,
aliasing, and invalid negative shift counts.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:15:39 2026
(Merged from https://github.com/openssl/openssl/pull/31830)


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

  Changed paths:
    M test/fntest.c

  Log Message:
  -----------
  OSSL_FN: Add OSSL_FN right-shift tests to fntest

The new file_rshift() handler is driven by the RShift stanzas already
in bnshift.txt, so no dedicated data file is added.  The N == 1
OSSL_FN_rshift1 cross-check and the file_lshift() round-trip mirror
bntest.c.

Issue: https://github.com/openssl/project/issues/2015
Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:15:41 2026
(Merged from https://github.com/openssl/openssl/pull/31830)


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

  Changed paths:
    M test/fntest.c

  Log Message:
  -----------
  OSSL_FN: Add lshift1 round-trip checks to fntest

file_lshift1() now mirrors bntest.c's file_lshift1() where OSSL_FN
primitives allow: it cross-checks LShift1 against A + A and A * 2,
then round-trips LShift1 >> 1 back to A with OSSL_FN_rshift1.

The LShift1 / 2, LShift1 % 2, and set-LSB rshift1-flooring checks
from bntest.c are deferred to a future commit: they need
OSSL_FN_div() and OSSL_FN_set_bit(), neither of which exists yet.

Issue: https://github.com/openssl/project/issues/2015
Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:15:42 2026
(Merged from https://github.com/openssl/openssl/pull/31830)


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

  Changed paths:
    M crypto/fn/fn_lib.c
    M include/crypto/fn.h

  Log Message:
  -----------
  OSSL_FN: Add OSSL_FN_is_bit_set()

Add OSSL_FN_is_bit_set(), the OSSL_FN counterpart of BN_is_bit_set().
The leak profile matches the BN counterpart: control flow branches only
on the operand's public width (dsize), not on limb values.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:09 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M crypto/fn/fn_lib.c
    M include/crypto/fn.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Add introspection helpers is_word, is_zero, is_one, is_odd

The OSSL_FN counterparts of the small BN predicates that the
modular-square-root operation (and other upcoming operations) lean on:

  - OSSL_FN_is_word() mirrors BN_is_word() and BN_abs_is_word(), which
    collapse into one here since OSSL_FN is unsigned (no sign to ignore);
    a separate OSSL_FN_abs_is_word is therefore not added.
  - OSSL_FN_is_zero() and OSSL_FN_is_one() are kept as named predicates
    for readability at call sites rather than written inline.
  - OSSL_FN_is_odd() mirrors BN_is_odd().

The leak profile matches the BN counterparts: control flow branches only
on the operand's public width (dsize), not on limb values; limb values
are combined with constant-time selects, as in OSSL_FN_cmp() and the
fixed-top BN helpers.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:10 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M crypto/fn/fn_addsub.c
    M include/crypto/fn.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Implement OSSL_FN_add_word / OSSL_FN_sub_word

The declarations of OSSL_FN_add_word() / OSSL_FN_sub_word() have been in
include/crypto/fn.h since the initial 'add'/'sub' commit, but no
implementation ever landed -- the symbols were simply absent, with no
caller noticing.  This adds them next to OSSL_FN_add() / OSSL_FN_sub().

While here, correct the signature: the word argument was declared
'const OSSL_FN_ULONG *w' (a pointer), which matches no BN counterpart;
it is now 'OSSL_FN_ULONG w' by value, mirroring BN_add_word() /
BN_sub_word().  Safe because there was no implementation and no caller.

These are the OSSL_FN counterparts of BN_add_word() / BN_sub_word().
The fixed-size unsigned semantics diverge where the BN counterpart grows
the BIGNUM (bn_wexpand) or records a sign (a->neg, storing w - a): OSSL_FN
instead truncates a carry/borrow past the last limb, and a borrow off the
top yields the 2's-complement wrap-around.

Both are non-constant-time, matching BN_add_word()/BN_sub_word(): the
carry/borrow loop stops early once exhausted, so the number of limbs
touched depends on the operand's value.

Tests cross-check every case against OSSL_FN_add() / OSSL_FN_sub() with
a single-limb operand.  Verified on both 64-bit (linux-x86_64) and 32-bit
(linux-x86) limb widths.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:12 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M crypto/fn/fn_lib.c
    M include/crypto/fn.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Add assignment helpers set_word, one, zero

The OSSL_FN counterparts of the small BN assignment helpers that the
modular-square-root operation (and other upcoming operations) lean on:
OSSL_FN_set_word(), OSSL_FN_one(), and OSSL_FN_zero() mirror
BN_set_word(), BN_one(), and BN_zero().

The fixed-size semantics diverge where BN_set_word() grows the BIGNUM
(bn_wexpand(a, 1)) to guarantee room: OSSL_FN cannot grow, so a
zero-width destination fails with OSSL_FN_R_RESULT_ARG_TOO_SMALL
instead.

OSSL_FN_set_word() is constant-time with respect to w's value, unlike
BN_set_word() (which sets a->top = (w ? 1 : 0)); OSSL_FN has no top, so
the full dsize array always holds the value and the only branch is on
the public width.

OSSL_FN_zero() is a plain value assignment, not a secure wipe;
OSSL_FN_clear() (OPENSSL_cleanse()) is the secure-wipe counterpart,
mirroring the BN_zero() / BN_clear() split.

Tests cross-check set_word against the internal ossl_fn_set_words() and
cover the dsize == 0 error path.  Verified on both 64-bit (linux-x86_64)
and 32-bit (linux-x86) limb widths.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:14 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M crypto/err/openssl.txt
    M crypto/fn/build.info
    M crypto/fn/fn_err.c
    A crypto/fn/fn_rand.c
    M include/crypto/fn.h
    M include/crypto/fnerr.h
    M test/fn_api_test.c

  Log Message:
  -----------
  OSSL_FN: Add random-number functions rand / priv_rand / range

Add OSSL_FN_rand(), OSSL_FN_priv_rand(), OSSL_FN_rand_range(), and
OSSL_FN_priv_rand_range(), the OSSL_FN counterparts of the BN_rand_ex() /
BN_priv_rand_ex() / BN_rand_range_ex() / BN_priv_rand_range_ex() family
from crypto/bn/bn_rand.c -- the first OSSL_FN random-number helpers.

The BN counterparts take a BN_CTX only to recover the library context
(via ossl_bn_get_libctx()); the OSSL_FN peers take an OSSL_LIB_CTX
directly, and per the OSSL_FN naming convention the BN _ex / _ex{n}
suffixes are dropped.

ossl_fn_rand() departs from the BN counterpart's byte-buffer mechanics:
bnrand() draws into a heap big-endian buffer and shapes via BN_bin2bn(),
whereas OSSL_FN limbs are fixed-size, so random bytes are drawn straight
into rnd->d and the top/bottom/mask shaping is done as limb value
operations (endian-neutral).  A destination too small for |bits| is an
error (OSSL_FN_R_RESULT_ARG_TOO_SMALL), not an implicit expansion.

The range variants port bnrand_range() faithfully; the range->neg
rejection is dropped (OSSL_FN is unsigned).  The leak profile matches the
BN counterpart: control flow branches on bits/top/bottom (caller-chosen,
public) and the byte-draw return value, never on the random bytes
themselves; the range loop count leaks the magnitude of |range| and the
rejection probability.  The TESTING mangle variant (BN_bntest_rand) is
deferred; a TODO(FIXNUM) marks the spot.

New error reasons: OSSL_FN_R_BITS_TOO_SMALL, OSSL_FN_R_INVALID_RANGE,
OSSL_FN_R_TOO_MANY_ITERATIONS.

Tests are property-based (random values cannot be value-compared) and
verify the bit-width, top/bottom constraints, zero-padding, and
0 <= r < range, on both 64-bit and 32-bit limb widths.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:16 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M crypto/fn/fn_rand.c
    M include/crypto/fn.h

  Log Message:
  -----------
  OSSL_FN: Make RAND top selector count-based

Renumber OSSL_FN_RAND_TOP_ANY / _ONE / _TWO from -1 / 0 / 1 to
0 / 1 / 2, so each value is the number of high bits the result is
forced to set.  This matches the already-count-based
OSSL_FN_RAND_BOTTOM_* (0 = unconstrained, 1 = force the low bit),
making the whole selector family read the same way.

This is a deliberate departure from the BN counterpart: BN_RAND_TOP_*
stays -1 / 0 / 1, but OSSL_FN_RAND_TOP_* has no legacy tier and no
need for a sentinel, so the values are the counts themselves.
Callers that use the symbolic macros are unaffected; only raw-literal
callers would notice, and there are none in tree.

Assisted-by: Pi:z-ai/glm-5.2
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Thu Jul 23 14:17:18 2026
(Merged from https://github.com/openssl/openssl/pull/31959)


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

  Changed paths:
    M test/bntest.c
    M test/recipes/10-test_bn.t
    A test/recipes/10-test_bn_data/bnmodinv.txt

  Log Message:
  -----------
  [test] bntest: add ModInv file tests

Add file_modinv() to bntest.c, driven by a new bnmodinv.txt corpus and
wired into 10-test_bn.t.
- Positive tests assert equalBN and a mult sanity check
- Negative tests assert NULL return plus the BN_R_NO_INVERSE error
Corpus covers:
- in-range A
- out-of-range A
- positive and negative A for both of the above
- degenerate moduli M = 0 and M = 1
- RFC 4754 sourced KATs
- RFC 7091 sourced KATs

Assisted-by: Claude:claude-opus-4-8

Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
MergeDate: Thu Jul 23 14:20:08 2026
(Merged from https://github.com/openssl/openssl/pull/31985)


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

  Changed paths:
    M crypto/fn/fn_addsub.c
    M include/crypto/fn_intern.h

  Log Message:
  -----------
  OSSL_FN: implement internal 'ossl_fn_add_words' and 'ossl_fn_add_words'

These functions fulfill the same purpose as 'bn_add_words' and
'bn_sub_words', but adapted to OSSL_FN_ULONG arrays with varying
sizes.  They are useful for partial calculations where carry and
borrow are of interest, but also fulfill a purpose when that's not
interesting.

Assisted-by: Pi:openai/gpt-5.5
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Jakub Zelenka <[email protected]>
Reviewed-by: Igor Ustinov <[email protected]>
MergeDate: Thu Jul 23 15:02:33 2026
(Merged from https://github.com/openssl/openssl/pull/31479)


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

  Changed paths:
    M crypto/err/openssl.txt
    M crypto/fn/build.info
    M crypto/fn/fn_err.c
    A crypto/fn/fn_mod.c
    M include/crypto/fn.h
    M include/crypto/fnerr.h

  Log Message:
  -----------
  OSSL_FN: Add the modular arithmetic functions

- OSSL_FN_mod_add
- OSSL_FN_mod_add_quick
- OSSL_FN_mod_sub
- OSSL_FN_mod_sub_quick
- OSSL_FN_mod_mul
- OSSL_FN_mod_sqr
- OSSL_FN_mod_lshift
- OSSL_FN_mod_lshift_quick
- OSSL_FN_mod_lshift1
- OSSL_FN_mod_lshift1_quick

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

Reviewed-by: Jakub Zelenka <[email protected]>
Reviewed-by: Igor Ustinov <[email protected]>
MergeDate: Thu Jul 23 15:02:35 2026
(Merged from https://github.com/openssl/openssl/pull/31479)


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

  Changed paths:
    M test/fn_api_test.c

  Log Message:
  -----------
  Add unit tests for OSSL_FN modular arithmetic functions

Assisted-by: Pi:moonshotai/kimi-k2.6
Assisted-by: Pi:openai/gpt-5.5
Signed-off-by: Richard Levitte <[email protected]>

Reviewed-by: Jakub Zelenka <[email protected]>
Reviewed-by: Igor Ustinov <[email protected]>
MergeDate: Thu Jul 23 15:02:37 2026
(Merged from https://github.com/openssl/openssl/pull/31479)


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

  Changed paths:
    M crypto/fn/fn_mod.c
    M include/crypto/fn.h

  Log Message:
  -----------
  OSSL_FN: Add modular context sizing

The modular OSSL_FN operations are layered on top of each other, but
the sizing of the required OSSL_FN_CTX arena was not available as
operation-specific helpers, mirroring OSSL_FN_div_ctx_size(),
OSSL_FN_mul_ctx_size(), and OSSL_FN_sqr_ctx_size().

Add ctx-size helpers for the modular operations and compose them from
lower-level helpers.  Each helper returns arena payload bytes, accounts
for its own live temporaries, and adds the maximum nested requirement
while those temporaries are live.

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: Thu Jul 23 15:02:39 2026
(Merged from https://github.com/openssl/openssl/pull/31479)


  Commit: 95b4936aa1d825c687e8347a1793ec9730812424
      https://github.com/openssl/openssl/commit/95b4936aa1d825c687e8347a1793ec9730812424
  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:
  -----------
  OSSL_FN: Add mod_mul and mod_sqr stanza tests

Add file_modmul() and file_modsqr() to test/fntest.c, using the
existing bntest.c counterparts as a template.  The ModMul and ModSqr
stanzas in bnmod.txt now exercise OSSL_FN_mod_mul() and
OSSL_FN_mod_sqr() through the stanza-driven test harness, providing a
real call site for the new modular operations.

Because OSSL_FN is unsigned, the operands are passed as absolute values
(via bn_get_ossl_fn()).  For mod_mul, if the operands have different
signs, the non-negative modular residue is recovered with BN_sub(ret,
m, ret) after release, keeping the sign logic at the BIGNUM boundary.
No sign fixup is needed for mod_sqr since squaring is always
non-negative.

Include bnmod.txt in 11-test_fn.t so the mod stanzas are run as part
of the regular test suite.

Related-to: doc/designs/fixed-size-large-numbers.md
Issue: https://github.com/openssl/project/issues/1932
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: Thu Jul 23 15:02:40 2026
(Merged from https://github.com/openssl/openssl/pull/31479)


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

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/ef1795-95b493%40github.com.