Skip to content

This repository contains a Circom implementation of a hybrid encryption scheme combining ECDSA, AES-CTR, and HMAC-SHA256 for secure message encryption and authentication.

Notifications You must be signed in to change notification settings

crema-labs/ecies-circom

Repository files navigation

ECIES Encryption

This repository contains a Circom implementation of a hybrid encryption scheme combining ECDSA, AES-CTR, and HMAC-SHA256 for secure message encryption and authentication.

Overview

The hybrid encryption scheme provides confidentiality and authenticity by combining:

  • ECDH (Elliptic Curve Diffie-Hellman) for key exchange
  • HKDF-SHA256 for key derivation
  • AES-CTR for encryption
  • HMAC-SHA256 for authentication

The implementation follows cryptographic standards and best practices for hybrid encryption schemes.

Circuit Implementation

The main circuit components are:

Encrypt Template

The primary encryption template that orchestrates the entire encryption process:

template Encrypt(npt, ns1, ns2)

Parameters:

  • npt: Length of plaintext
  • ns1: Length of first salt (for key derivation)
  • ns2: Length of second salt (for authentication)

GenSharedKey Template

Implements ECDH key exchange using secp256k1:

template GenSharedKey()

Generates a shared secret from:

  • Private key (r)
  • Public key coordinates (px, py)

KeyGen Template

Derives encryption and HMAC keys using HKDF-SHA256:

template KeyGen(ni)

Parameters:

  • ni: Length of info/salt for key derivation

Dependencies

Security Properties

The circuit provides:

  1. Confidentiality: Using AES-CTR encryption
  2. Authentication: Using HMAC-SHA256
  3. Forward Secrecy: Using ephemeral ECDH key exchange
  4. Public Key Authentication: Including sender's public key

Message Format

The encrypted message format is:

pubkey.x | pubkey.y | iv | ciphertext | hmac

Where:

  • pubkey: Sender's public key (for verification)
  • iv: 16-byte initialization vector
  • ciphertext: AES-CTR encrypted message
  • hmac: Authentication tag

Test Results

Test Case Constraints Plaintext Size Salt1 Size Salt2 Size
Basic 2177825 32 0 0

Usage

To run the tests:

yarn test

References :

About

This repository contains a Circom implementation of a hybrid encryption scheme combining ECDSA, AES-CTR, and HMAC-SHA256 for secure message encryption and authentication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •