Example #1
0
func FillWithFakeDoubles(dest [][]byte, nonce *[24]byte, nextKeys []*[32]byte) {
	ParallelFor(len(dest)/2, func(p *P) {
		for i, ok := p.Next(); ok; i, ok = p.Next() {
			var exchange1 [SizeConvoExchange]byte
			var exchange2 [SizeConvoExchange]byte
			rand.Read(exchange1[:])
			copy(exchange2[0:16], exchange1[0:16])
			rand.Read(exchange2[16:])
			onion1, _ := onionbox.Seal(exchange1[:], nonce, nextKeys)
			onion2, _ := onionbox.Seal(exchange2[:], nonce, nextKeys)
			dest[i*2] = onion1
			dest[i*2+1] = onion2
		}
	})
}
Example #2
0
func (srv *ConvoService) Get(args *ConvoGetArgs, result *ConvoGetResult) error {
	log.WithFields(log.Fields{"service": "convo", "rpc": "Get", "round": args.Round, "count": args.Count}).Debug()

	round, err := srv.getRound(args.Round, convoRoundClosed)
	if err != nil {
		return err
	}

	nonce := BackwardNonce(args.Round)
	outgoingOnionSize := srv.PKI.OutgoingOnionOverhead(srv.ServerName) + SizeEncryptedMessage

	result.Onions = make([][]byte, args.Count)
	for k := range result.Onions {
		i := args.Offset + k

		if v := round.incomingIndex[i]; v > -1 {
			reply := round.replies[v]
			onion := box.SealAfterPrecomputation(nil, reply, nonce, round.sharedKeys[i])
			result.Onions[k] = onion
		}
		if len(result.Onions[k]) != outgoingOnionSize {
			onion := make([]byte, outgoingOnionSize)
			rand.Read(onion)
			result.Onions[k] = onion
		}
	}

	return nil
}
Example #3
0
func FillWithFakeSingles(dest [][]byte, nonce *[24]byte, nextKeys []*[32]byte) {
	ParallelFor(len(dest), func(p *P) {
		for i, ok := p.Next(); ok; i, ok = p.Next() {
			var exchange [SizeConvoExchange]byte
			rand.Read(exchange[:])
			onion, _ := onionbox.Seal(exchange[:], nonce, nextKeys)
			dest[i] = onion
		}
	})
}
Example #4
0
func laplace(mu, b float64) float64 {
	var r [8]byte
	if _, err := rand.Read(r[:]); err != nil {
		panic(err)
	}

	x := binary.BigEndian.Uint64(r[:])
	u := float64(x)/float64(^uint64(0)) - .5

	var abs, sign float64
	if u < 0 {
		abs = -u
		sign = -1
	} else {
		abs = u
		sign = 1
	}

	return mu - b*sign*math.Log(1-2*abs)
}
Example #5
0
func FillWithFakeIntroductions(dest [][]byte, noiseCounts []int, nonce *[24]byte, nextKeys []*[32]byte) {
	buckets := make([]int, len(dest))
	idx := 0
	for b, count := range noiseCounts {
		for i := 0; i < count; i++ {
			buckets[idx] = b
			idx++
		}
	}

	ParallelFor(len(dest), func(p *P) {
		for i, ok := p.Next(); ok; i, ok = p.Next() {
			var exchange [SizeDialExchange]byte
			binary.BigEndian.PutUint32(exchange[0:4], uint32(buckets[i]))
			rand.Read(exchange[4:])
			onion, _ := onionbox.Seal(exchange[:], nonce, nextKeys)
			dest[i] = onion
		}
	})
}