Skip to content

Feature Request: Add small stack mode for wolfCOSE #14

@aidangarske

Description

@aidangarske

Feature Plan: wolfCOSE "Small Stack" Mode

The Problem: "Stack Exhaustion"

In many embedded environments (STM32, ESP32, or custom RTOS tasks), the stack is a precious, fixed resource. wolfCOSE, in its current "no-malloc" state, forces all buffers and structures onto the stack. For complex COSE objects (signatures + certs + payload), this can exceed the available stack depth, leading to hard faults.

Proposed Naming Options

Since we want this to sound functional but "cool," here are a few directions for the --enable flag and the macro:

  • --enable-small-stack (Simple, clear, user-centric)
  • --enable-heap-buffers (Technical, explicit about memory location)
  • --enable-low-stack-footprint (Professional)
  • WOLFCOSE_LOW_STACK (The internal macro)

Updated Phase 1: Logic & Naming

We will wrap the dynamic allocation logic specifically under a "Small Stack" umbrella.

  • Macro Logic:
    /* If the user wants to save stack, we default to heap usage */
    #if defined(WOLFCOSE_SMALL_STACK) || defined(WOLFCOSE_DYNAMIC_ALLOCATION)
        #define WC_COSE_USE_HEAP
    #endif

Updated Phase 4: Stack Auditing

Since the goal is to accommodate small stacks, we don't just add malloc—we also need to find where the current code is "stack-heavy."

  1. Identify Large Locals: Use the Fenrir Prompt (from our previous chat) to specifically target "Category B.4: Stack Minimization."
  2. Heap-Promotion: Any local array larger than, say, 128 bytes should be conditionally moved to the heap when WC_COSE_USE_HEAP is defined.
  3. The "Safety Valve": If WC_COSE_USE_HEAP is NOT defined and a function detects a payload larger than the static buffer, it must return a specific error code like BUFFER_TOO_SMALL_E rather than overflowing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeatureFeature additionwant to addFeature that you want to add or want added

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions