Skip to main content
IoT
PSUT Engineering StudioPrincess Sumaya University for Technology
V21.6.5 · Student / connected
Cyber Defense StudioIoT Security and PrivacyExperimentsWorkspaces
Home / IoT Security and Privacy / EC11
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
ESSENTIAL LABORATORY · EC11 · IoT SECURITY AND PRIVACY
IoT Security and Privacy

Hash security — Preimages, collisions, HMAC and keyed generation

Run actual bounded digest searches, construct HMAC from inner/outer hash pads and study keyed pseudo-random digit generation.

Design experiment & verify evidence →
EC11 · Laboratory mentorAsk about the current experiment, its algorithms or Python notebook.
Ask Dr. MohammadAdaptive practice
EC11 · Academic orientation

Scope and objectives

Scope of the experiment

Run actual bounded digest searches, construct HMAC from inner/outer hash pads and study keyed pseudo-random digit generation.

The focus of this experiment is to compare preimage, second-preimage and collision properties. Students then trace HMAC and keyed-generation inputs and outputs, and verify tags with controlled changes and distinguish hashes from encryption. 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

  • Compare preimage, second-preimage and collision properties.
  • Trace HMAC and keyed-generation inputs and outputs.
  • Verify tags with controlled changes and distinguish hashes from encryption.
  • 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 compare preimage, second-preimage and collision properties, trace HMAC and keyed-generation inputs and outputs, and verify tags with controlled changes and distinguish hashes from encryption.

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 verify tags with controlled changes and distinguish hashes from encryption. Separate predicted values from observations.

Prerequisite knowledge and related learning

Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to AES modes — ECB, CBC, padding, password derivation and encrypted files.

Environment and experimental methodology

The included teaching workstation and the listed Python/Colab or WSL implementation. Historical and small-number constructions are instructional, not deployment recommendations.

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.

How to investigate Hash security — Preimages, collisions, HMAC and keyed generation

Run actual bounded digest searches, construct HMAC from inner/outer hash pads and study keyed pseudo-random digit generation.

Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.

Experiment-specific guided practice

Objective: Run actual bounded digest searches, construct HMAC from inner/outer hash pads and study keyed pseudo-random digit generation.

  1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
  2. Truncated preimage and collision search — complete its numbered steps and record the requested evidence.
  3. Manual HMAC construction — complete its numbered steps and record the requested evidence.
  4. Keyed digit generator — complete its numbered steps and record the requested evidence.

Reference check: Suffix searches show actual digest matches. Manual HMAC equals library HMAC for identical key/message/algorithm and fails when either input differs.

Model boundary: Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser.

Independent task and submission evidence

2. Truncated preimage and collision search — complete its numbered steps and record the requested evidence. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.

Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.

TrialChanged settingFixed settingsPredicted resultActual observation / unitsEvidence / uncertainty
A: baselineReferenceRecordPredictRecordRecord
B: one changeRecordSame as APredictRecordRecord
A: repeatRestoreSame as APredictRecordRecord

Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.

Scientific concepts and engineering principles

Scientific architecture · EC11 · Hash security — Preimages, collisions, HMAC and keyed generation

Message padding, word schedule, 80 compression rounds, chaining and final digest.
Message padding, word schedule, 80 compression rounds, chaining and final digest.

Preimages and collisions

A preimage search seeks an input that produces a specified digest value; a collision seeks two distinct inputs with equal digests. Truncating the digest to a few hexadecimal digits makes both experiments tractable. Vary the truncation length and repeat trials because the number of attempts is random.

HMAC construction

Normalize the key to the hash block length B: hash long keys and zero-pad shorter keys. SHA-256 has B=64 bytes and SHA-512 has B=128 bytes. HMAC computes H((K′ XOR opad) || H((K′ XOR ipad) || message)), where the byte patterns 0x5c and 0x36 are repeated B times.

Keyed digit generation

An HMAC-based state or counter can generate a reproducible stream under a classroom key. For decimal digits use rejection sampling: accept bytes below 250 then reduce modulo 10. Compare counts over repeated trials. This exercise is not a validated production DRBG.

Prerequisites: EC10 and earlier foundations as applicable.

EC11 engineering diagram
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.

Engineering diagrams

Inner and outer hash inputs protect a keyed message.
Inner and outer hash inputs protect a keyed message.

Scientific foundations and worked examples

Security notions and work factors

For a fixed n-bit digest target, ideal preimage success after q independent attempts has probability 1−(1−\(2^{-n}\))^q; expected attempts are \(2^{n}\). A second-preimage task holds one original message fixed and seeks a different message with its digest. A collision allows both messages to vary; after q distinct messages its approximate probability is 1−exp(−q(q−1)/2^(n+1)). For an eight-bit suffix the average preimage effort is 256, while the 50% collision point is about 19 messages. Matching suffixes are not full SHA collisions.

SHA-512 preprocessing and schedule

Encode the message as bytes, append the 1 bit, then zeros until the length is 896 modulo 1024; append the original length as a 128-bit big-endian integer. Parse each padded block into sixteen 64-bit words \(W_{0}\)…\(W_{15}\). Expand to \(W_{79}\) using \(W_{t}\)=\(\sigma_{1}\)(\(W_{t-2}\))+\(W_{t-7}\)+\(\sigma_{0}\)(\(W_{t-15}\))+\(W_{t-16}\) modulo \(2^{64}\), where \(\sigma_{0}\)(x)=ROTR¹(x) XOR ROTR⁸(x) XOR SHR⁷(x), \(\sigma_{1}\)(x)=ROTR¹⁹(x) XOR ROTR⁶¹(x) XOR SHR⁶(x). SHA-512 processes 80 rounds per block using eight 64-bit working words.

Compression round and feed-forward

Define Ch(e,f,g)=(e AND f) XOR (NOT e AND g), Maj(a,b,c)=(a AND b) XOR (a AND c) XOR (b AND c). \(\Sigma_{0}\)(x)=ROTR²⁸(x) XOR ROTR³⁴(x) XOR ROTR³⁹(x), \(\Sigma_{1}\)(x)=ROTR¹⁴(x) XOR ROTR¹⁸(x) XOR ROTR⁴¹(x). At round t compute \(T_{1}\)=h+\(\Sigma_{1}\)(e)+Ch(e,f,g)+\(K_{t}\)+\(W_{t}\) and \(T_{2}\)=\(\Sigma_{0}\)(a)+Maj(a,b,c). Set (a,b,c,d,e,f,g,h)=(\(T_{1}\)+\(T_{2}\),a,b,c,d+\(T_{1}\),e,f,g), with additions modulo \(2^{64}\). After round 79 add the eight working words to the previous chaining value; the final digest concatenates the eight resulting words. The first block begins with the standardized IV; subsequent blocks use the previous feed-forward state.

HMAC and keyed generation

HMAC authenticates a message using a secret key and nested hashing. For SHA-512 the normalized key is 128 bytes; a 16-byte laboratory key receives 112 zero bytes. XOR the block with repeated 0x36 and 0x5C. The inner digest is 64 bytes, then the outer hash produces a 64-byte tag. Keys longer than the block are hashed before padding. A receiver independently computes the tag and compares it in constant time in real applications. For the classroom generator, HMAC(key,counter) produces deterministic bytes; hexadecimal symbols are direct nibbles, decimal digits require rejection of bytes 250–255 to avoid modulo bias. Uniform counts alone do not validate a cryptographic DRBG. Authentication does not supply confidentiality or replay protection.

SHA-512 message padding, schedule, compression and feed-forward diagram
SHA-512 architecture: from the padded 1024-bit block to the 512-bit digest.
PropertySHA-256SHA-512
Block length512 bits1024 bits
Word length32 bits64 bits
Compression rounds6480
Digest length256 bits512 bits
HMAC block length64 bytes128 bytes

For abc, W0 = 6162638000000000 and W15 = 0000000000000018. The final SHA-512 digest is ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f.

Engineering principles · additional worked teaching example

A digest is unkeyed; HMAC authenticates data with a secret. For an ideal b-bit digest, expected collision-search scale is 2^(b/2) while preimage scale is 2^b. A toy 12-bit digest has 4096 possible outputs; birthday scale64.

From theory to experiment

Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.

Worked engineering reasoning and boundary conditions

Preimage resistance, second-preimage resistance and collision resistance have different challenges. For ideal n-bit output, generic collision search is about 2^(n/2) work, preimage about 2^n. HMAC keys the digest construction.

Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.

Concept animation · operation pathway

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.

Hash security — Preimages, collisions, HMAC and keyed generation: operation pathwayMessagepublic telemetryHashunkeyed digestHMACsecret key +messageVerificationrecompute tag;enforce freshnessRead the active operation, then inspect the accumulated state.

Step 1 of 4 · Message

Message

Message
public telemetry

Teaching example only; inspect live calculations or real practical evidence separately.

Interactive flashcards

Self-rated study progress is stored locally, not used for official grades.

Browse all explanations
What is a preimage?

An input producing a specified digest.

What is a collision?

Distinct inputs with equal digests.

What does HMAC bind?

Message and secret key.

Why use truncated hashes in a search demo?

To make the search feasible; not production security.

Why truncate a digest for classroom experiments?

To make search demonstrations feasible without claiming a break of the full hash.

What is the expected work scale for an n-bit ideal preimage?

About 2^n trials.

What is the birthday collision work scale?

About 2^(n/2) trials.

What does HMAC add to hashing?

A secret key and structured inner/outer hashing.

What is the SHA-256 HMAC block size?

64 bytes.

What is the SHA-512 HMAC block size?

128 bytes.

What are the HMAC inner and outer pad constants?

0x36 and 0x5c respectively.

What should happen when a verification key changes?

Authentication should fail unless the resulting tag happens to match.

A receiver recomputes HMAC using a different key. What is expected?

Verification fails except for an extremely unlikely accidental tag match. Compare with a correct-key positive control.

For a 16-bit truncated digest, approximately how many random inputs give a 50% collision chance?

About sqrt(2 ln 2 × \(2^{16}\)) ≈301 distinct inputs under a uniform independent hash model.

What must be checked in addition to HMAC to reject a replayed packet?

A freshness policy such as an authenticated sequence number or nonce and a receiver replay window.

How many rounds does SHA-512 use per padded block?

80, operating on eight 64-bit working words.

How many bits encode the original message length in SHA-512 padding?

128, big-endian. The complete padded block length is a multiple of 1024.

What happens at 112 input bytes?

A second block is required because the 1-bit marker and 128-bit length field do not fit in the first block.

What are the two main temporary words in a SHA-512 compression round?

T1 combines h, Σ1, Ch, Kt and Wt; T2 combines Σ0 and Maj. All additions are modulo 2^64.

How is the new chaining value obtained?

Add each final working word to its corresponding incoming chaining word modulo 2^64.

For a 16-byte HMAC-SHA-512 key, how many zero bytes are appended?

112, bringing the normalized key to the 128-byte block length.

Does a collision in two hex digits imply a full SHA-512 collision?

No; it establishes only equality of the selected eight output bits.

Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research