This library provides two critical cryptographic and security-related modules:
- AES Core: A hardware implementation of the Advanced Encryption Standard (AES-128)
- True Random Number Generator: A hardware-based entropy source for generating high-quality random numbers
The AES Core is a fully synthesizable Verilog implementation of the AES-128 encryption/decryption algorithm. It supports both encryption and decryption operations with a 128-bit key and 128-bit data block.
- Supports both encryption and decryption modes
- Fully pipelined architecture
- Configurable through module parameters
- Implements standard AES-128 round operations
module aes_core (
input wire clk, // Clock input
input wire rst_n, // Active-low reset
input wire start, // Start operation
input wire encrypt, // 1 for encrypt, 0 for decrypt
output reg done, // Operation complete
output reg busy, // Core is processing
input wire [31:0] data_in[0:3], // Input data (128-bit)
input wire [31:0] key[0:3], // Key input (128-bit)
output reg [31:0] data_out[0:3] // Output data (128-bit)
);- S-Box Transformation: Non-linear substitution of bytes
- Key Expansion: Generates round keys for each encryption round
- State Transformation: Implements core AES encryption/decryption steps
- SubBytes: Byte substitution using S-Box
- ShiftRows (implicit in implementation)
- MixColumns (implicit in implementation)
- AddRoundKey
- Rounds: 10 (standard for AES-128)
- Latency: Approximately 10 clock cycles
- Throughput: One 128-bit block per 10 clock cycles
A hardware-based true random number generator that leverages physical entropy sources to generate high-quality random numbers.
- Configurable data width (default 32-bit)
- Multiple entropy sources
- Ring Oscillator (optional)
- Linear Feedback Shift Registers (LFSRs)
- Advanced entropy collection and mixing techniques
- Health monitoring and validation
module true_random_generator #(
parameter DATA_WIDTH = 32,
parameter USE_RINGOSCILLATOR = 1
)(
input wire clk,
input wire rst_n,
input wire enable,
input wire read_next,
output wire data_valid,
output wire [DATA_WIDTH-1:0] random_data,
output wire entropy_low,
output wire test_failed
);-
Ring Oscillator Method
- Uses an odd number of inverters in a loop
- Generates unpredictable oscillations
- Samples oscillator state for entropy
-
LFSR (Linear Feedback Shift Register)
- Multiple LFSRs with different tap configurations
- Provides additional entropy sources
- Uses complex feedback polynomials
- Multiple entropy pools
- Complex bit mixing algorithms
- Cross-pool XOR operations
- Byte and half-word swapping
- Entropy collection counter
- State machine for controlled generation
- Configurable test and validation stages
- No external seed input: The TRNG does not accept a user-provided seed. Instead, it internally initializes entropy pools to non-zero values and derives randomness from hardware behavior.
- Non-zero internal initialization:
entropy_poolinitializes to...001on reset to avoid the all-zero stateentropy_pool2initializes to all ones on reset- Auxiliary
lfsr_reginitializes to32'hABCDE971
- Entropy sources and modes:
- With
USE_RINGOSCILLATOR = 1(default): samples a ring oscillator and mixes samples into entropy pools. This mode is non-deterministic across runs and platforms. - With
USE_RINGOSCILLATOR = 0: disables the ring oscillator and falls back to LFSR-based collection and mixing only. This mode is deterministic for a given build/reset sequence.
- With
- Mixing and output:
- Multiple pools (
entropy_pool,entropy_pool2, andlfsr_reg) are XOR-mixed with byte/half-word permutations to improve bit distribution before producingrandom_datain the READY state.
- Multiple pools (
- Health and validity:
entropy_lowasserts while collecting if insufficient samples have been accumulatedtest_failedflags trivial patterns (all-zeros or all-ones) as a basic sanity checkdata_validindicates when a fresh mixed value is available (READY state)
Guidance:
- For cryptographic-quality non-determinism, use the default
USE_RINGOSCILLATOR=1configuration. - For reproducible testing or CI, set
USE_RINGOSCILLATOR=0to use deterministic LFSR-only behavior under the same reset conditions.
- Ensure proper clock and reset management
- For AES:
- Provide 128-bit data and key
- Assert
startandencrypt/decryptsignals - Wait for
donesignal
- For Random Generator:
- Enable module
- Check
data_validbefore reading - Use
read_nextto request new random data
- Secure communication systems
- Cryptographic key generation
- Hardware security modules
- Random number-dependent algorithms
- Verified with Verilator
- Synthesis directives for ring oscillator
- Parameterizable for different FPGA/ASIC technologies
- Performance varies with implementation technology
- Actual randomness depends on physical entropy sources
- Recommend additional post-processing for cryptographic applications
- NIST SP 800-90A (Random Number Generation)
- FIPS 197 (AES Specification)
- "Hardware-based Cryptography" by Cetin K. Koc