Correlated Oblivious Transfer (COT) based 2-party multiplication over secp256k1.
This project contains:
- Alice / Server: C++ (
Boost.Asio+trezor-crypto) - Bob / Client: TypeScript (
Node.js+protobufjs)
The protocol computes additive shares
where
This codebase is a practical, readable implementation of COT-style share conversion from multiplicative shares to additive shares. It is designed for:
- protocol experimentation,
- interoperability between languages (C++ and TypeScript),
- and correctness verification in a local/dev environment.
⚠️ Security noticeThis repository is currently focused on protocol correctness and developer testing. It is not production-hardened: no authenticated transport, no TLS, and no advanced session hardening.
For each bit
- Server samples round scalar
$a_i$ and sends$A_i = a_iG$ . - Client uses choice bit
$c_i = y_i$ and replies with:-
$B_i = b_iG$ if$c_i = 0$ -
$B_i = b_iG + A_i$ if$c_i = 1$
-
- Server derives two keys from EC shared points and encrypts:
$m_{0,i} = U_i$ $m_{1,i} = U_i + x$
- Client decrypts only
$m_{c_i,i}$ .
After all rounds:
and both parties verify:
src/main.cpp— creates random server sharex, starts TCP server on port12345src/server.cpp— protocol orchestration, message exchange, final verificationsrc/ot_session.cpp— OT round state, encrypted pair generation, additive share computationsrc/crypto_utils.cpp— secp256k1 operations, hashing, AES wrappers, scalar mathsrc/proto_utils.cpp— protobuf-compatible framing and message encode/decode
src/index.ts— end-to-end protocol execution and verificationsrc/client.ts— framed TCP socket helpersrc/ot_session.ts— choice-bit logic, decrypt path, additive share accumulationsrc/crypto_utils.ts— secp256k1, AES, scalar arithmetic utilitiessrc/proto_utils.ts— protobufjs message encoding/decoding helpers
proto/cot.proto— message schema and payload definitions
- Envelope type:
CotMessage - Discriminator field:
message_type - Payload:
oneof payload - TCP framing:
- 4-byte big-endian length prefix
- protobuf-encoded message bytes
- Curve:
secp256k1 - Shared secret: x-coordinate of EC point multiplication
- KDF:
SHA-256 - Symmetric encryption:
AES-256-CBC(IV prepended in ciphertext blob) - Scalar arithmetic: modulo secp256k1 order
$n$
- Git
- Internet access during first CMake configure (to fetch
trezor-crypto)
- CMake
>= 3.16 - C++17 compiler (MSVC is expected on Windows)
- Boost headers (
>= 1.70)
Top-level CMakeLists.txt sets:
BOOST_ROOT = C:/boost_1_82_0
If your Boost path differs, override BOOST_ROOT during configure.
- Node.js
>= 20 - npm
Use two terminals.
From repository root:
- Configure CMake (source
.and build dirbuild) - Build target
cot_serverin your preferred configuration (Debug/Release)
Expected executable (Visual Studio multi-config):
build/server/Release/cot_server.exe
From client/:
- Install dependencies (
npm install) - Compile (
npm run build)
Expected output:
client/dist/index.js
- Terminal A: run
cot_server.exe - Terminal B (in
client/): runnpm start(ornpm run dev)
Expected logs include:
- both sides print their multiplicative shares
- progress every 64 rounds
- verification section
Result : PASS ✓when successful
- Keep protocol message compatibility between:
proto/cot.protoserver/src/proto_utils.cppclient/src/proto_utils.ts
- If changing round logic, update both:
server/src/ot_session.cppclient/src/ot_session.ts
- Rebuild both server and client after protocol changes.
- Boost not found during configure
- set
BOOST_ROOTto your local Boost installation path.
- set
- Port 12345 already in use
- stop the previous process, or change host/port on both sides.
- Client cannot load protobuf schema
- verify
proto/cot.protoexists at expected runtime path relative to client build output.
- verify
- Verification fails (
FAIL ✗)- clean and rebuild both sides to avoid stale mixed binaries.
For maintainers and contributors, see:
CONTRIBUTING.mdfor contribution workflowCODE_OF_CONDUCT.mdfor community standardsSECURITY.mdfor vulnerability reportingLICENSEfor Apache 2.0 licensing terms
Licensed under the Apache License 2.0. See LICENSE.