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 theBitVec structure for efficient storage and manipulation of binary vectors. BitVec is used extensively in LPN-based encryption and noise generation.
Structure
BitVec
Compact representation of a binary vector using packed 64-bit words.Number of bits in the vector
Storage array where each uint64_t holds 64 bits
Bits are packed into 64-bit words for efficient storage and operations. A vector of n bits uses ceil(n/64) words.
Construction
make
Creates a new BitVec initialized to all zeros.Number of bits in the vector
New BitVec with n bits, all initialized to 0
Operations
xor_with
Performs in-place XOR with another BitVec.Vector to XOR with
If the vectors have different sizes, only the overlapping portion (minimum size) is affected.
popcnt
Counts the number of 1-bits in the vector (Hamming weight).Number of bits set to 1
Uses the compiler’s
__builtin_popcountll intrinsic for efficient population count on 64-bit words.Utility functions
parity64
Computes the parity (XOR of all bits) of a 64-bit word in constant time.Input word
0 if an even number of bits are set, 1 if odd
This function uses constant-time XOR shifts to compute parity, making it suitable for cryptographic applications where timing side-channels must be avoided.
Implementation details
Bit packing
Bits are stored in little-endian order within each 64-bit word:- Bit 0 is the LSB of
w[0] - Bit 63 is the MSB of
w[0] - Bit 64 is the LSB of
w[1] - And so on…
Memory layout
For a BitVec withnbits bits:
- Number of words:
(nbits + 63) / 64 - Memory usage:
8 * ((nbits + 63) / 64)bytes (plus overhead)
Usage patterns
LPN secret vector
Combining vectors
Computing inner product
Performance considerations
Optimization tips:
- BitVec operations work on 64-bit words, providing 64x speedup over bit-by-bit operations
- XOR operations are memory-bandwidth limited; keep vectors aligned
- Population count (
popcnt) uses hardware instructions on modern CPUs - Parity computation is constant-time for security
Constant-time operations
Theparity64 function is implemented in constant time to prevent timing side-channels:
Related
- Types - BitVec usage in cryptographic structures
- Random generation - Generating random bit vectors
- Constant-time operations - Side-channel resistant arithmetic