[openssl/openssl] 2108bf: Add OSSL_FN_CTX_peak_usage() for arena usage instr...

"'Richard Levitte' via openssl-commits" <[email protected]>
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: 2108bf6891cdc04549fab54e99cded7da072a609
      https://github.com/openssl/openssl/commit/2108bf6891cdc04549fab54e99cded7da072a609
  Author: Richard Levitte <[email protected]>
  Date:   2026-06-14 (Sun, 14 Jun 2026)

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

  Log Message:
  -----------
  Add OSSL_FN_CTX_peak_usage() for arena usage instrumentation

Track the maximum number of frames, numbers and limbs ever consumed
from an OSSL_FN_CTX arena during its lifetime.  This allows callers
to empirically size their contexts instead of predicting precise
max_n_frames / max_n_numbers / max_n_limbs ahead of time.

These peak usages are updated whenever a frame is started or an OSSL_FN
is obtained.  They never decrease, reflecting the worst-case simultaneous
allocation across all nested frames.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Sun Jun 14 08:40:38 2026
(Merged from https://github.com/openssl/openssl/pull/31431)


  Commit: 0228b1303f0667f8e8b7a612cb7134d31b6e44d7
      https://github.com/openssl/openssl/commit/0228b1303f0667f8e8b7a612cb7134d31b6e44d7
  Author: Richard Levitte <[email protected]>
  Date:   2026-06-14 (Sun, 14 Jun 2026)

  Changed paths:
    M test/fn_internal_test.c

  Log Message:
  -----------
  Add test for OSSL_FN_CTX_peak_usage

Verify that peak_usage starts at zero, rises after frame start and
allocation, and never decreases after a frame is ended.

Also correct misleading comments that claimed OSSL_FN_CTX_new()
takes a size in bytes -- the last parameter is actually max_n_limbs.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Sun Jun 14 08:40:40 2026
(Merged from https://github.com/openssl/openssl/pull/31431)


  Commit: 1bd960ea71fd55606ee51422f70327aa5c49eb9f
      https://github.com/openssl/openssl/commit/1bd960ea71fd55606ee51422f70327aa5c49eb9f
  Author: Richard Levitte <[email protected]>
  Date:   2026-06-14 (Sun, 14 Jun 2026)

  Changed paths:
    M crypto/fn/fn_ctx.c
    M crypto/fn/fn_local.h

  Log Message:
  -----------
  Expose OSSL_FN_CTX internals via fn_local.h

Move struct ossl_fn_ctx_st and struct ossl_fn_ctx_frame_st from
fn_ctx.c to fn_local.h, making them accessible to internal code in
the bn/ directory and elsewhere.  Also expose
ossl_fn_ctx_calculate_arena_size() as an inline helper so callers
can determine the required arena size without duplicating the formula.

This is groundwork for BN_CTX integration.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Sun Jun 14 08:40:42 2026
(Merged from https://github.com/openssl/openssl/pull/31431)


  Commit: 4fec2aafd89c73889f320b054fbf76818bb38b25
      https://github.com/openssl/openssl/commit/4fec2aafd89c73889f320b054fbf76818bb38b25
  Author: Richard Levitte <[email protected]>
  Date:   2026-06-14 (Sun, 14 Jun 2026)

  Changed paths:
    M crypto/bn/bn_ctx.c
    M include/crypto/bn.h
    M test/bn_internal_test.c

  Log Message:
  -----------
  Add OSSL_FN_CTX integration with BN_CTX

Add an OSSL_FN_CTX * pointer to struct bignum_ctx, allowing a BN_CTX
to cache an OSSL_FN_CTX for use by BIGNUM wrapper functions.  The
pointer is freed automatically when BN_CTX_free() is called.

Also add bn_ctx_acquire_ossl_fn_ctx() and bn_ctx_release_ossl_fn_ctx():
- acquire creates (or reuses if large enough) an OSSL_FN_CTX inside
  the BN_CTX, sizing it according to the caller's needs.
- release checks that no frames remain in the cached OSSL_FN_CTX.

The acquire function respects BN_FLG_SECURE: if the BN_CTX was created
with BN_CTX_secure_new(), the OSSL_FN_CTX is also allocated in secure
memory.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Sun Jun 14 08:40:44 2026
(Merged from https://github.com/openssl/openssl/pull/31431)


  Commit: e183d91627bf433a15df2ad249dfd8a7ed248649
      https://github.com/openssl/openssl/commit/e183d91627bf433a15df2ad249dfd8a7ed248649
  Author: Richard Levitte <[email protected]>
  Date:   2026-06-14 (Sun, 14 Jun 2026)

  Changed paths:
    M crypto/bn/bn_mul.c
    M crypto/bn/bn_sqr.c

  Log Message:
  -----------
  Use BN_CTX cached OSSL_FN_CTX in BN_mul() and BN_sqr()

The previous commit added bn_ctx_acquire_ossl_fn_ctx() and
bn_ctx_release_ossl_fn_ctx() to cache an OSSL_FN_CTX inside a BN_CTX.
However, BN_mul() and BN_sqr() were still creating and freeing their own
temporary OSSL_FN_CTX on every call, ignoring the passed-in BN_CTX entirely.

Update both functions to acquire the OSSL_FN_CTX from the BN_CTX and release
it afterwards, allowing the cached context to be reused across calls.

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

Reviewed-by: Igor Ustinov <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Sun Jun 14 08:40:47 2026
(Merged from https://github.com/openssl/openssl/pull/31431)


Compare: https://github.com/openssl/openssl/compare/b4847e73de6e...e183d91627bf

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/b4847e-e183d9%40github.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.