Metadata-Version: 2.4
Name: sgcp
Version: 0.1.2
Summary: State Graph Cryptographic Protocol (SGCP) — IETF draft implementation
Author-email: Sripad Karthik <sripadkarthik@gmail.com>
Project-URL: Homepage, https://datatracker.ietf.org/doc/draft-sgcp-state-graph-cryptographic-protocol/
Project-URL: Repository, https://github.com/sripad2020/SGCP
Project-URL: Bug Tracker, https://github.com/sripad2020/SGCP
Project-URL: Documentation, https://pypi.org/project/sgcp/
Project-URL: PyPI, https://pypi.org/project/sgcp/
Project-URL: IETF Draft, https://datatracker.ietf.org/doc/draft-sgcp-state-graph-cryptographic-protocol/
Keywords: sgcp,cryptography,protocol,state-graph,ecdh,aead,key-derivation,replay-protection,epoch,x509,media-transfer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=41.0
Requires-Dist: pycryptodome>=3.20
Requires-Dist: typing-extensions>=4.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Dynamic: license-file

# sgcp-protocol

**State Graph Cryptographic Protocol (SGCP)** — Python PyPI package.

Implements draft-sgcp-state-graph-cryptographic-protocol-00 in full.

## Install

```bash
pip install sgcp
```

Or from source:

```bash
cd sgcp-protocol
pip install -e ".[dev]"
```

## Protocol Stack

```
SGCP
 ├── X.509 Certificates   (§4)  — identity binding via cryptography library
 ├── ECDH / X25519        (§5.4) — shared secret establishment
 ├── HKDF (SHA-256)       (§8)  — Root Secret → Epoch Key → Packet Key
 ├── SGCP State Graph     (§7)  — nodes + hash chain + authenticated edges
 └── Packet Protection    (§5.8/§5.9) — AES-256-GCM + XOR transform
```

## Quick Start

```python
from sgcp.crypto.ecdh import X25519KeyPair, generate_nonce
from sgcp.crypto.kdf  import (
    derive_root_secret_classic, derive_session_id, compute_context_binding
)
from sgcp.packet.data import create_data_packet, receive_data_packet, DataPacket
from sgcp.constants   import Direction

# --- Phase 4: ECDH ---
client_dh = X25519KeyPair()
server_dh = X25519KeyPair()
dh_secret = client_dh.exchange(server_dh.public_bytes)

# --- Phase 4/8.1: Root Secret ---
cn = generate_nonce(32)   # Client_Nonce
sn = generate_nonce(32)   # Server_Nonce
ch = generate_nonce(32)   # Client_Cert_Hash (SHA-256 of client.crt)
sh = generate_nonce(32)   # Server_Cert_Hash

root_secret = derive_root_secret_classic(dh_secret, cn, sn, ch, sh)

# --- Phase 5: Session_ID ---
session_id = derive_session_id(root_secret, cn, sn)

# --- Phase 6: Context Binding ---
ctx = compute_context_binding(1, "client-device-01", 6, 443, 12345,
                               b"socket-cookie-01", session_id)

# --- Phase 8: Send ---
plaintext = b"Hello from SGCP client!"
pkt = create_data_packet(
    plaintext=plaintext, session_id=session_id, root_secret=root_secret,
    epoch=0, sequence=0,
    direction=Direction.CLIENT_TO_SERVER,
    context_binding=ctx,
)
wire = pkt.to_wire()

# --- Phase 9: Receive ---
from sgcp.packet.data import DataPacket
received = DataPacket.from_wire(wire)
recovered, tag = receive_data_packet(received, session_id, root_secret, ctx)
assert recovered == plaintext
print("Decrypted:", recovered)
```

## MP3 Full-Duplex Transfer Example (§14)

```python
from sgcp.media.transfer import segment_file, reassemble_file

# Sender: segment 7 MB MP3
with open("song.mp3", "rb") as f:
    data = f.read()

segments = list(segment_file(data, segment_size=8192))
# → 896 segments, each protected by a unique per-packet key

# Receiver: reassemble (verifies SHA-256 File_Hash automatically)
reassembled = reassemble_file(segments)
assert reassembled == data
```

## Modules

| Module | Draft section |
|---|---|
| `sgcp.constants` | §2.2, §6.1, §8.5 |
| `sgcp.exceptions` | throughout |
| `sgcp.x509_integration` | §4 |
| `sgcp.crypto.kdf` | §8.1–§8.5 |
| `sgcp.crypto.aead` | §5.8/§5.9 |
| `sgcp.crypto.ecdh` | §5.4 |
| `sgcp.crypto.transform` | §9 |
| `sgcp.session.replay` | §5.11 |
| `sgcp.session.context` | §5.2, §5.6, §5.12 |
| `sgcp.session.epoch` | §10 |
| `sgcp.session.state` | §5.5, §5.10, §15 |
| `sgcp.graph.node` | §7.1 |
| `sgcp.graph.edge` | §7.2 |
| `sgcp.graph.state_graph` | §7.3, §7.4 |
| `sgcp.packet.header` | §6.1 |
| `sgcp.packet.handshake` | §5.3, §6.2 |
| `sgcp.packet.data` | §5.8, §5.9, §6.3 |
| `sgcp.packet.media` | §6.3, §14 |
| `sgcp.protocol.handshake` | §5.1–§5.5, §4.5 |
| `sgcp.protocol.client` | §5.1–§5.12 |
| `sgcp.protocol.server` | §5.9–§5.12 |
| `sgcp.protocol.transition` | §11, §5.12 |
| `sgcp.protocol.recovery` | §12 |
| `sgcp.media.transfer` | §14 |

## Run Tests

```bash
pip install -e ".[dev]"
pytest tests/ -v
```

## Author

Sripad Karthik <sripadkarthik@gmail.com>

## License

BSD 2-Clause
