forked from vuvuzela/vuvuzela
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noise.go
57 lines (51 loc) · 1.55 KB
/
noise.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package vuvuzela
import (
"encoding/binary"
. "github.com/davidlazar/vuvuzela/internal"
"github.com/davidlazar/vuvuzela/onionbox"
"github.com/davidlazar/vuvuzela/rand"
)
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
}
})
}
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
}
})
}
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
}
})
}