Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yash25198 committed Dec 28, 2024
1 parent 5bff36f commit 3ee6705
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
Circomkit template
# HKDF Circuit Implementation

## Overview

Implementation of HKDF (HMAC-based Key Derivation Function) using SHA-256 in Circom 2.1.8. The circuit follows [RFC 5869](https://www.rfc-editor.org/rfc/rfc5869.html)'s extract-then-expand paradigm.


## Components

### 1. HKDFSha256 Template
Main template that combines Extract and Expand operations.

```circom
template HKDFSha256(s, i, k, m, n)
```

Parameters:
- `s`: Salt length
- `i`: Info length
- `k`: Input key length
- `m`: Number of output keys
- `n`: Output key length

Signals:
- Input: `salt[s]`, `info[i]`, `key[k]`
- Output: `out[m][n]`

### 2. Extract Template
Implements HKDF-Extract using HMAC-SHA256.

```circom
template Extract(s, k)
```

Parameters:
- `s`: Salt length
- `k`: Key length

Signals:
- Input: `salt[s]`, `key[k]`
- Output: `out[32]` (fixed 32-byte SHA-256 output)

### 3. Expand Template
Implements HKDF-Expand using HMAC-SHA256.

```circom
template Expand(i, k, m, n)
```

Parameters:
- `i`: Info length
- `k`: Key length (PRK)
- `m`: Number of output keys
- `n`: Length per output key

Signals:
- Input: `info[i]`, `key[k]`
- Output: `out[m][n]`

## Implementation Details

### Extract Operation
1. Uses HmacSha256 component
2. Sets input key material as message
3. Uses salt as HMAC key
4. Produces 32-byte PRK (Pseudorandom Key)

### Expand Operation
1. Calculates required rounds: `rounds = ceil((m*n)/32)`
2. First round:
- Message = info || 0x01
- Key = PRK
3. Subsequent rounds:
- Message = prev_hash || info || counter
- Key = PRK
- Counter increments each round
4. Output mapping:
- Maps expanded keys to output array
- Uses byte-wise indexing for proper output arrangement

### Signal Flow
```
Input Key Material → Extract → PRK → Expand → Output Key Material
↑ ↑ ↑ ↑
Salt HMAC Info HMAC[rounds]
```

## Dependencies

- HMAC circuit (`./hmac/circuits/hmac.circom`)
- Circom 2.1.8 or higher

0 comments on commit 3ee6705

Please sign in to comment.