IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
CRYPTOGRAPHY ENGINEERING · CR32 · RANDOMNESS
IoT Security and Privacy
AES-OFB and CTR · deterministic bit generation
OFB: next state E(K,V); CTR: output E(K,V), increment V.
CR32 · Laboratory mentorAsk about the current operation and its intermediate values.
CR32 · Academic orientation
Scope and objectives
Scope of the experiment
A deterministic generator expands internal state; it does not create entropy. OFB and CTR demonstrate recurrence and counter independence, not full standardized DRBG operation.
The focus of this experiment is to trace AES output-feedback and counter-based deterministic generation. Students then compare state progression and output extraction under fixed parameters, and explain seed and counter requirements and distinguish demonstration from a full DRBG. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.
Learning objectives
Trace AES output-feedback and counter-based deterministic generation.
Compare state progression and output extraction under fixed parameters.
Explain seed and counter requirements and distinguish demonstration from a full DRBG.
Record the relevant inputs, intermediate states and final verification result before changing the reference configuration.
Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.
Expected learning outcomes
On completion, students can trace AES output-feedback and counter-based deterministic generation, compare state progression and output extraction under fixed parameters, and explain seed and counter requirements and distinguish demonstration from a full DRBG.
Required deliverables
Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing explain seed and counter requirements and distinguish demonstration from a full DRBG. Separate predicted values from observations.
Prerequisite knowledge and related learning
Use the curriculum sequence and the Concepts section for prerequisite terminology. After completion, continue to Entropy · bias, conditioning and OS randomness.
Environment and experimental methodology
A standard browser and the experiment-specific Python implementation or Colab notebook. Where the practical uses a protocol model, model results are distinguished from actual local cryptographic operations.
Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.
01 · Experiment overview
CR32 · AES-OFB and CTR · deterministic bit generation
This experiment compares two deterministic AES stream constructions with an explicit initial state, fixed key and zero input. OFB updates V to E(K,V), while CTR emits E(K,V) then increments V. These are educational deterministic generators, not standardized DRBGs with approved instantiate, update and reseed procedures.
Before starting
Environment: standard computer, browser and Python/WSL.
Simulation: Editable JavaScript calculation
Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.
Complete the six stages in order. Use the same experiment inputs when comparing manual, browser and Python results.
02 · Concepts and mathematical foundations
This experiment compares two deterministic AES stream constructions with an explicit initial state, fixed key and zero input. OFB updates V to E(K,V), while CTR emits E(K,V) then increments V. These are educational deterministic generators, not standardized DRBGs with approved instantiate, update and reseed procedures.
Learning objectives
Calculate the named operation, inspect its intermediate values, reproduce the result in Python, and explain one controlled change. Prerequisites: binary/hexadecimal arithmetic; complete preceding labs in the same topic where applicable.
Before starting
Environment: standard computer, browser and Python/WSL.
Simulation: Editable JavaScript calculation
Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.
Block-cipher-based generation
1 · Principles and purpose
A deterministic generator expands internal state; it does not create entropy. OFB and CTR demonstrate recurrence and counter independence, not full standardized DRBG operation.
2 · Mathematical and algorithmic foundations
OFB: \(O_{i}\)=E_K(\(O_{i-1}\)). CTR: \(O_{i}\)=E_K(\(T_{i}\)), where T increments. Standard DRBG designs additionally specify entropy input, instantiation, state update, reseed and request limits.
3 · Worked teaching example
If the same seed/key and starting state are used, a deterministic generator repeats its sequence. Keep generation and reseeding distinct; use OS or approved library RNG in applications.
Captured earlier local execution. Randomized values and timing can differ; compare the invariant.
4 · Verification and experimental interpretation
Step through the following visualization and compare the named operation with the corresponding computed state. Check the mathematical invariant, inverse operation or protocol acceptance condition. Change one input at a time; distinguish a measured output from a prediction.
Mathematical representation and interpretation
OFB keystream
The next feedback state depends on the previous state, not ciphertext. For a partial final block use only the required keystream bytes.
Each counter block T_i must be unique for the key, including across messages. CTR supports independent block processing; confidentiality alone does not authenticate data.
Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.
Step 1 of 8 · OFB Block/segment 1
OFB Block/segment 1
step
OFB Block/segment 1
input
00000000000000000000000000000000
register
000102030405060708090A0B0C0D0E0F
cipher_input
00000000000000000000000000000000
keystream
0A940BB5416EF045F1C39458C653EA5A
output
0A940BB5416EF045F1C39458C653EA5A
next_register
0A940BB5416EF045F1C39458C653EA5A
OFB Block/segment 3
step
OFB Block/segment 3
input
00000000000000000000000000000000
register
AEE71EA541D7AE4BEB60BECC593FB663
cipher_input
00000000000000000000000000000000
keystream
80B3F97AC05E83BAE3A4416846E64015
output
80B3F97AC05E83BAE3A4416846E64015
next_register
80B3F97AC05E83BAE3A4416846E64015
OFB Block/segment 6
step
OFB Block/segment 6
input
00000000000000000000000000000000
register
AAA2E272996CAA766CFFB13350C1DAD2
cipher_input
00000000000000000000000000000000
keystream
CEAA960CD352368CC9D52314076E4C61
output
CEAA960CD352368CC9D52314076E4C61
next_register
CEAA960CD352368CC9D52314076E4C61
OFB Block/segment 8
step
OFB Block/segment 8
input
00000000000000000000000000000000
register
7728BD97152252862A2EA8ECE5669A02
cipher_input
00000000000000000000000000000000
keystream
B78504330D4578CAAB0629CDBF436E5C
output
B78504330D4578CAAB0629CDBF436E5C
next_register
B78504330D4578CAAB0629CDBF436E5C
CTR Block/segment 2
step
CTR Block/segment 2
input
00000000000000000000000000000000
register
000102030405060708090A0B0C0D0E10
cipher_input
00000000000000000000000000000000
keystream
0263EC94661872969ADAFD0F4BA40FDC
output
0263EC94661872969ADAFD0F4BA40FDC
next_register
000102030405060708090A0B0C0D0E11
CTR Block/segment 4
step
CTR Block/segment 4
input
00000000000000000000000000000000
register
000102030405060708090A0B0C0D0E12
cipher_input
00000000000000000000000000000000
keystream
4D0BABD2995F9F076223246847B5D30E
output
4D0BABD2995F9F076223246847B5D30E
next_register
000102030405060708090A0B0C0D0E13
CTR Block/segment 7
step
CTR Block/segment 7
input
00000000000000000000000000000000
register
000102030405060708090A0B0C0D0E15
cipher_input
00000000000000000000000000000000
keystream
F783C1ADB02C0CCC7302718EBECDF211
output
F783C1ADB02C0CCC7302718EBECDF211
next_register
000102030405060708090A0B0C0D0E16
CTR metrics
step
CTR metrics
ones
490
n
1024
fraction
0.478516
runs
504
entropy
0.998668
adjacent_match
0.508309
Teaching example only; inspect live calculations or real practical evidence separately.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research
Verified baseline reference — use the live workstation below to explore steps and compare inputs.
Edit the fields and choose Recompute. Use step controls to inspect real calculated states. Hexadecimal byte fields are written without 0x; numeric fields accept decimal or 0x notation.
Select a step to inspect the current calculation. The blue workbench matches the established instrument palette. Exact numeric values are also listed in the trace; scroll diagrams horizontally on narrow displays.
Use the baseline inputs shown above. Predict a result, advance one operation at a time, inspect the intermediate state, then change only the parameter specified in the Experiments view. Export the trace and compare it with your manual derivation.
OFB: next state E(K,V); CTR: output E(K,V), increment V. The lecture compares bit balance and adjacent block similarity. This fixed-seed model lacks instantiate/update/reseed procedures required for SP 800-90A DRBG compliance.
Predict the baseline result before revealing the calculated state. A controlled comparison changes the named input while keeping the other conditions fixed. Record an observed value separately from an expected value.
Part A · Independent theoretical exercises
Complete each question before running the simulator or Python. Show calculations or protocol traces. The teaching example is a method, not a substitute for the assigned values.
01 · Application and derivation
Application and derivation · Independent work
Draw three consecutive OFB generator states and three CTR generator inputs. Given one toy output block, distinguish the returned bytes from the state used for the next block. Explain why neither diagram alone constitutes a standardized DRBG.
Application and derivation — OFB: \(O_{i}\)=E_K(\(O_{i-1}\)). CTR: \(O_{i}\)=E_K(\(T_{i}\)), where T increments. Standard DRBG designs additionally specify entropy input, instantiation, state update, reseed and request limits. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Architecture analysis
Architecture analysis · Independent work
If an OFB generator state repeats and its key is unchanged, what happens to subsequent outputs? Contrast CTR with distinct counter blocks.
Architecture analysis — Review the defining equations and compare the input restrictions and state transitions in Concepts. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Required evidence: state the expected invariant or acceptance condition; record hand-derived results, compare with the simulator or Python trace, and explain the first discrepancy. Do not report a predicted value as a measurement.
Expanded independent theoretical exercise bank
Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.
Intermediate · Interpret a computation state
Independent theoretical exercise · CR32-01
A teaching trace for AES-OFB and CTR · deterministic bit generation contains step: OFB Block/segment 2; input: 00000000000000000000000000000000; register: 0A940BB5416EF045F1C39458C653EA5A; cipher_input: 00000000000000000000000000000000; keystream: AEE71EA541D7AE4BEB60BECC593FB663. Explain the role of next_register (recorded value AEE71EA541D7AE4BEB60BECC593FB663) and identify the rule or input that determines it. Distinguish an intermediate state from the final result.
Advanced · Identify a terminal invariant
Independent theoretical exercise · CR32-02
The first teaching trace contains step: OFB Block/segment 1; input: 00000000000000000000000000000000; register: 000102030405060708090A0B0C0D0E0F; cipher_input: 00000000000000000000000000000000; keystream: 0A940BB5416EF045F1C39458C653EA5A; output: 0A940BB5416EF045F1C39458C653EA5A; next_register: 0A940BB5416EF045F1C39458C653EA5A; the last contains step: CTR metrics; ones: 490; n: 1024; fraction: 0.478516; runs: 504; entropy: 0.998668; adjacent_match: 0.508309. Identify one distinction between the initial operation and completion. What additional condition must hold to use the result?
Use AES-128 with key 00112233445566778899aabbccddeeff and the initial 128-bit value 00000000000000000000000000000010. For OFB, use the AES output as the next input. For CTR, increment the 128-bit counter by one in big-endian order. Calculate two output blocks from each generator (use the lab AES implementation for the primitive), write the two AES inputs and outputs for each, and identify the first position at which their state sequences differ.
OFB feeds its previous cipher output back; CTR feeds a distinct incremented counter. Use the same AES key in both comparisons.
A CTR-based teaching generator has a fixed 96-bit nonce and a 32-bit unsigned counter starting at hexadecimal FFFFFFFE. Each output block is 16 bytes. A request asks for 48 bytes. How many distinct counter blocks remain before wrap, how many bytes may be emitted, and how should the request be handled?
Counter space is finite; each AES input must be unique for a given key. Count inclusively from the starting value to the maximum.
In a one-byte illustrative XOR experiment, P1=3A, C1=91, and C2=BC. Both messages used the same keystream byte. Calculate the keystream byte, recover P2 and verify your result. What design constraint prevents this failure in the CTR-based generator?
XOR is its own inverse; the teaching example models the effect of a repeated keystream, not a complete security protocol.
Two identical devices are initialized with the same key and state, and both output 64 bytes after reboot. A third device uses a separate initialization value but no entropy health checks. Predict what happens for the identical devices and propose a defensible initialization, reseeding and request-limit policy. Explain why a histogram test cannot establish unpredictability.
A deterministic generator is a state machine. A DRBG additionally needs a well-specified entropy and state lifecycle.
Part B · Guided simulation and practical procedure
Before starting — tools and setup
Standard computer; extract the WSL toolkit into a new directory. For the browser activity, use the integrated workstation. Editable browser calculation
Install Python dependencies only if required by the selected toolkit README. Use its requirements file and virtual environment instructions.
Compare your baseline with the verified reference output below; for runtime-dependent results, compare invariants and report actual measurements instead of expecting identical timing or randomly generated values.
Evidence to record
Initial and next states, first two output blocks, generated bit count, ones fraction and adjacent-match rate.
Part D · Controlled experiment — Compare AES-OFB and CTR deterministic streams
Change the first state byte to 80 while keeping key/count fixed. Restore state and reduce count to 4. Compare output length, first blocks, runs and balance.
Record all fixed settings and complete the trial table.
Measure Initial and next states, first two output blocks, generated bit count, ones fraction and adjacent-match rate. Compare against the baseline and explain the mechanism.
Part E/F · Independent Python verification and deliverables
Download the notebook or toolkit and run the default example.
Run each assigned trial in the notebook or edit a copy of example-input.json and use python3 lab.py --params example-input.json. Compare the exact corresponding states.
Complete the independent assessment below without copying the worked baseline. Explain discrepancies and distinguish mathematical results from security claims.
Additional investigation instructions
A controlled comparison changes one independent input while holding other inputs fixed, then measures its effect on the dependent output. A baseline is the unmodified run. Evidence-based reasoning means citing the actual observed values, not merely asserting that an algorithm is secure.
Run the supplied default values and record the first and final state.
Predict the effect before changing anything. Change change one state byte and then block count 8 to 4. First verified alternate: {"count": "4"}.
Keep key, algorithm and other seed bytes.
Measure output blocks, ones fraction and matching adjacent bits.
Restore the baseline and repeat with another valid input. Locate the first differing calculation.
Submit a comparison table, a trace JSON or screenshots of relevant steps, and a short conclusion with an explicit limitation.
Trial
Changed input
Fixed conditions
Prediction
Measured value
Reason / limitation
Baseline
None
Default
Student prediction
Record trace
Explain
Trial 1
Specified change
Unchanged inputs
Student prediction
Record trace
Explain
Part C · Python, Google Colab and WSL
The standalone implementation uses the same synthetic baseline and calculations as the browser. In Colab, download the notebook, open Colab and upload it using File → Upload notebook. Run all cells in order.
Use Ubuntu or Kali WSL, not PowerShell. Download the toolkit above to your computer. If Python, venv or unzip is missing, install these prerequisites once (requires administrator permission and network access).
In WSL, enter the actual downloaded ZIP path when prompted (for example, a file under /mnt/c/Users/…/Downloads). Extract to a new, dedicated directory. If this directory already exists from a previous extraction, use the existing verified toolkit or choose a clean directory rather than overwriting it.
Step 1 · Extract · bash
read -r -p "Full path to PSUT_V22_9_9_Cryptography_WSL.zip: " ZIP
DEST="$HOME/psut-crypto-v22.9.9"
if [ -f "$ZIP" ] && [ ! -e "$DEST" ]; then
mkdir "$DEST" && unzip "$ZIP" -d "$DEST"
else
echo "Check ZIP path and use a fresh destination."
fi
Create the isolated environment in the extracted toolkit root, activate it, then enter this experiment’s actual folder. Install only its declared dependencies. A comment-only requirements file requires no third-party packages.
Step 2 · Activate and install · bash
cd ~/psut-crypto-v22.9.9
python3 -m venv .venv
source .venv/bin/activate
cd CR32
ls
python -m pip install -r requirements.txt
Execute the default run and save the genuine program output. Then run the supplied regression test and the baseline fixture through the explicit input interface.
To change inputs, copy example-input.json, edit the copy in a text editor and run the command below. The original fixture is preserved.
Step 4 · Change an input · bash
cp example-input.json my-input.json
# Edit my-input.json with your preferred editor.
python lab.py --params my-input.json
These scripts terminate normally. Use Ctrl+C to stop a long-running calculation if needed. When finished, leave the isolated virtual environment; no global service cleanup is required for these local examples.
Step 5 · Finish · bash
deactivate
Declared dependencies: # Standard library only for core experiment
Expected terminal output — captured local execution
This excerpt contains the actual first trace step and final result from python lab.py, followed by the actual regression test output. Full stdout is in CR32/verified-output.txt inside the toolkit. Timing, random signatures, keys, certificate fields and implementation-dependent sizes can vary; compare the invariant and record your own observations.
Check the output JSON and the test exit status. An assertion error means the expected invariant was not met. If Python reports a missing module, activate the environment and install the experiment’s requirements file; if a file is missing, check pwd and ls.
Both encrypt the same initial state under the same key.
Is this a standards-compliant DRBG?
No; reseeding and other required state procedures are absent.
Does deterministic expansion create new entropy?
No.
06 · Knowledge assessment
Formative check
Which state update distinguishes OFB from CTR?
Responses are for instructor review; no grading key is provided here.
Independent assessment
Generate four blocks in both modes; change only the final seed byte from 0F to 10, compare first-block and adjacent-block bit fractions, and explain why the model is not a reseeding DRBG. Use an additional valid trial, a calculation or a counterexample to support your reasoning. Submit evidence from both runtimes and explain what the experiment does not establish.
Part F · Engineering evidence record
Record the baseline, prediction, changed input, observed result, discrepancy and limitation. Save locally or export with the displayed result. This is not an official submission.