Coder Social home page Coder Social logo

markkurossi / mpc Goto Github PK

View Code? Open in Web Editor NEW
93.0 5.0 22.0 9.85 MB

Secure Multi-Party Computation (MPC) with Go. This project implements secure two-party computation with Garbled circuit protocol.

Home Page: https://www.markkurossi.com/mpcl/index.html

License: MIT License

Go 99.34% Makefile 0.14% C 0.53%
multi-party-computation golang go mpc yao-millionaires garbled-circuit logical-circuits oblivious-transfer sha-256 sha-512

mpc's Introduction

mpc's People

Contributors

hextrust-0 avatar markkurossi avatar rozag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mpc's Issues

Why the evaluator can use the original boolean circuit?

Hello developer,
From my understanding, the garbler only sends the garbled circuit, encoding information, and decoding information to the evaluator.
However, in evaluator.go and eval.go the evaluator directly uses the original circuit to compute the output.
Is there any template I can use to modify the algorithm?

help: Possible to implement 3 party MPC?

Is it possible to implement a solution with a setup of one garbler and two evaluator, where each garbler has a 2-pc connection with each of the two evaluators, with the help of this library?

Can you give some insight on this?

String Type in mpcl

I am trying to convert a byte array to a hex string in mpcl. Here is the code from Sha256 HMAC. I saw a type defined as type stringSize string but didn't get any tests on this.

In the code below I want to convert the variable key to a string and pass it to HMAC
hmac.SumSHA256([]byte("message"), []byte("abc"))
such that it looks like this:
hmac.SumSHA256([]byte("message"), []byte(string_key))

package main


import (
	"crypto/hmac"
)

type Garbler struct {
	msg      [32]byte
	keyShare [64]byte
}

func main(g Garbler, eKeyShare [64]byte) []byte {
	var key [64]byte

	for i := 0; i < len(key); i++ {
		key[i] = g.keyShare[i] ^ eKeyShare[i]
	}

This was the code I wrote to convert byte array to hex string:
package main


import "fmt"

func main() {
	byteArray := []byte{0x48, 0x65, 0x6C, 0x6C, 0x6F} // Example byte array

	// Convert the byte array to a hexadecimal string
	var hexString string
	for _, b := range byteArray {
		hexString += byteToHexString(b)
	}

	fmt.Println(hexString)
}

func byteToHexString(b byte) string {
	hexChars := "0123456789ABCDEF"
	high := b >> 4
	low := b & 0x0F
	return string(hexChars[high]) + string(hexChars[low])
}
	

but string is not accepted by mpcl. Can we write a package that handles this conversion?

undefined variable 'break'

Hello

I am going to implement modular add function.
I am facing an error regarding undefined variable 'break'
Any idea how to break the loop?

How to run HMAC ?

I am new to this repo. I want to run the HMAC circuit. Can you guide how to run it?

Help: possible to scale?

Is it possible to have potentially thousands of clients garble their shares, send it to 2 nodes to perform the mpc calculations? I would like to create a demo showing 10000 homes provide their occupancy in order to know the city's total occupancy without knowing each individual home's occupancy. Would it be possible for each home to garble their secret (occupancy - unsigned integer - and send it to 2 mpc nodes to perform the aggregation function?

`p2p.Conn.Stats` is not goroutine safe

Issue

I've been inspecting my project with go's race detector and stumbled upon a data race caused by p2p package.

Severity

It seems that the core functionality of the library is not affected by the race, but it makes it a bit harder to inspect apps that use the lib for data races because of a lot of "false positives", so to speak.

How to reproduce

Let's start with the basic garbled example:

  1. Shell 1:
    cd apps/garbled
    go run --race . -e -i 800000 examples/millionaire.mpcl
  2. Shell 2:
    cd apps/garbled
    go run --race . -i 750000 examples/millionaire.mpcl
  3. Output in Shell 1:
     - In1: a{1,0}i64:int64
     + In2: b{1,0}i64:int64
     - Out: %_{0,1}b1:bool1
     -  In: [800000]
    Listening for connections at :8080
    New connection from 127.0.0.1:61520
    p2p.NewConn
    ==================
    WARNING: DATA RACE
    Read at 0x00c00037e0e8 by main goroutine:
      github.com/markkurossi/mpc/circuit.Evaluator()
          /Users/rozag/workspace/mpc/circuit/evaluator.go:115 +0xf44
      main.evaluatorMode()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:359 +0x28d
      main.main()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:311 +0x2ce6
    
    Previous write at 0x00c00037e0e8 by goroutine 14:
      github.com/markkurossi/mpc/p2p.(*Conn).writer()
          /Users/rozag/workspace/mpc/p2p/protocol.go:94 +0x244
      github.com/markkurossi/mpc/p2p.NewConn.func1()
          /Users/rozag/workspace/mpc/p2p/protocol.go:80 +0x39
    
    Goroutine 14 (running) created at:
      github.com/markkurossi/mpc/p2p.NewConn()
          /Users/rozag/workspace/mpc/p2p/protocol.go:80 +0x304
      main.evaluatorMode()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:358 +0x244
      main.main()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:311 +0x2ce6
    ==================
    Result[0]: false
    
  4. Output in Shell 2:
     + In1: a{1,0}i64:int64
     - In2: b{1,0}i64:int64
     - Out: %_{0,1}b1:bool1
     -  In: [750000]
    p2p.NewConn
    ==================
    WARNING: DATA RACE
    Read at 0x00c000424178 by main goroutine:
      github.com/markkurossi/mpc/circuit.Garbler()
          /Users/rozag/workspace/mpc/circuit/garbler.go:139 +0xb24
      main.garblerMode()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:381 +0x13b
      main.main()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:318 +0x2eb5
    
    Previous write at 0x00c000424178 by goroutine 14:
      github.com/markkurossi/mpc/p2p.(*Conn).writer()
          /Users/rozag/workspace/mpc/p2p/protocol.go:94 +0x244
      github.com/markkurossi/mpc/p2p.NewConn.func1()
          /Users/rozag/workspace/mpc/p2p/protocol.go:80 +0x39
    
    Goroutine 14 (running) created at:
      github.com/markkurossi/mpc/p2p.NewConn()
          /Users/rozag/workspace/mpc/p2p/protocol.go:80 +0x304
      main.garblerMode()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:378 +0xb3
      main.main()
          /Users/rozag/workspace/mpc/apps/garbled/main.go:318 +0x2eb5
    ==================
    Result[0]: false
    Found 1 data race(s)
    

The root cause

It seems that the problem is that we read and write to p2p.Conn.Stats.(Sent|Recvd) without any synchronization from multiple goroutines. And one of the goroutines is the one we start in p2p.NewConn.

Proposed solution

Leverage sync/atomic.Uint64 instead of raw uint64 in p2p.IOStats.

In hmac hmacsha-256.mpcl the generated result is not same as the one genearted online using same credentials

while trying the code.
i used the key given in the example ie - b598163d740b0973b8b312881bfe6601e031d33d9f15be97b0cc8898ae570932fd755ced0af309f7625f531ab01cdc0ba7130ae14b561b905f53777255174170

and the message - Hello, world!...................
the Hmac sha256 output i got online is - 8b8252a526ca8b895cd3d7749124b9d801f654fa8a4a9d515b101468de48edde which does not matches with the one result[0] in the docs
expected result - Result[0]: 60d27dbd14f1e351f20069171fead00ef557d17ac9a41d02baa488ca4b90171a

notes-
site used for computing sha256
https://www.devglan.com/online-tools/hmac-sha256-online

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.