Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/octra-labs/pvac_hfhe_cpp/llms.txt

Use this file to discover all available pages before exploring further.

Overview

This module provides global configuration settings for PVAC-HFHE, primarily focused on debug output control. The debug level can be configured via environment variables or programmatically.

Global variables

g_dbg

Global debug level variable.
inline int g_dbg;
value
int
Current debug level (0-2)
The debug level controls the verbosity of output:
0
Silent
No debug output
1
Normal
Standard debug output (default)
2
Verbose
Detailed debug output with additional information
The debug level is automatically initialized from environment variables on first use.

Functions

set_debug_level

Sets the global debug level programmatically.
void set_debug_level(int level);
level
int
Desired debug level (will be clamped to range [0, 2])
Example:
// Disable all debug output
set_debug_level(0);

// Enable verbose output
set_debug_level(2);

// Set to normal (default) level
set_debug_level(1);
Values outside the range [0, 2] are automatically clamped to the nearest valid value.

get_debug_level

Retrieves the current debug level.
int get_debug_level();
return
int
Current debug level (0-2)
Example:
int current_level = get_debug_level();
if (current_level >= 1) {
    std::cout << "Debug output is enabled" << std::endl;
}

Environment variables

PVAC_DBG

Primary environment variable for setting the debug level.
export PVAC_DBG=2  # Verbose output
export PVAC_DBG=1  # Normal output (default)
export PVAC_DBG=0  # Silent mode
This variable is checked first during initialization.

HFHE_DBG

Fallback environment variable for backward compatibility.
export HFHE_DBG=1
If PVAC_DBG is not set, HFHE_DBG will be used instead.

Initialization

The debug level is initialized automatically on first access using the following logic:
  1. Check if PVAC_DBG environment variable is set
  2. If not, check if HFHE_DBG environment variable is set
  3. If neither is set, default to level 1 (normal)
  4. Clamp the value to the range [0, 2]
Example:
# Run with verbose debug output
PVAC_DBG=2 ./my_program

# Run in silent mode
PVAC_DBG=0 ./my_program

# Use default (normal) level
./my_program

Usage patterns

Conditional debug output

if (get_debug_level() >= 1) {
    std::cout << "Generating keys..." << std::endl;
}

if (get_debug_level() >= 2) {
    std::cout << "Key generation details:" << std::endl;
    std::cout << "  m_bits: " << params.m_bits << std::endl;
    std::cout << "  n_bits: " << params.n_bits << std::endl;
}

Runtime configuration

// Save current level
int saved_level = get_debug_level();

// Temporarily disable debug output
set_debug_level(0);

// ... perform operations ...

// Restore previous level
set_debug_level(saved_level);

Library initialization

void initialize_library(int debug_level = 1) {
    set_debug_level(debug_level);
    
    if (get_debug_level() >= 1) {
        std::cout << "PVAC-HFHE initialized" << std::endl;
    }
}

Best practices

For library users:
  • Set the debug level early in your program’s initialization
  • Use environment variables for quick testing without recompilation
  • Set level 0 for production deployments
For library developers:
  • Use level 1 for important operations (key generation, encryption, etc.)
  • Use level 2 for detailed algorithmic steps
  • Always check the debug level before expensive string formatting

Thread safety

The debug level is stored in a global variable. Changing it from multiple threads without synchronization may result in race conditions. If thread safety is required, wrap calls to set_debug_level() in appropriate synchronization primitives.

Build docs developers (and LLMs) love