Skip to content

Commit 12f8f7a

Browse files
committed
Moves to AES for blinding vectors
1 parent c5ec807 commit 12f8f7a

File tree

3 files changed

+31
-87
lines changed

3 files changed

+31
-87
lines changed

crypto/polynomials.go

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package crypto
22

33
import (
4+
"crypto/aes"
45
"crypto/rand"
6+
"crypto/sha3"
57
"encoding/binary"
68
"math/big"
79
)
@@ -48,57 +50,41 @@ func NevilleInterpolation(xs []*big.Int, ys []*big.Int, x *big.Int, fieldOrder *
4850
return result
4951
}
5052

51-
// SharedSecretsGenerator computes a PRF-based generator from shared secrets and round number.
52-
// The generator is used to derive deterministic pseudo-random values.
53-
func SharedSecretsGenerator(sharedSecrets []SharedKey, round *big.Int, fieldOrder *big.Int) *big.Int {
54-
el := new(big.Int)
55-
secretElementGenerator := new(big.Int).Set(prfSeed)
56-
for _, sse := range sharedSecrets {
57-
// Probably insecure
58-
el.SetBytes(sse)
59-
el.Add(el, round)
60-
el.Mul(el, prfSeed)
61-
el.Mod(el, fieldOrder)
62-
secretElementGenerator.Add(secretElementGenerator, el)
63-
secretElementGenerator.Mod(secretElementGenerator, fieldOrder)
64-
}
65-
return secretElementGenerator
66-
}
67-
68-
// DeriveBlindingVector generates a vector of blinding factors from shared secrets.
69-
// The blinding factors are deterministically derived for the given round and can be
70-
// used to blind and unblind values in the ADCNet protocol.
53+
// DeriveBlindingVector deterministically generates a vector of blinding elements from shared secrets for the given round.
7154
func DeriveBlindingVector(sharedSecrets []SharedKey, round uint32, nEls int32, fieldOrder *big.Int) []*big.Int {
72-
buf := make([]big.Int, nEls)
55+
bytesPerElement := (fieldOrder.BitLen()+7)/8
56+
srcBytesBuf := make([]byte, int(nEls)*bytesPerElement)
57+
dstBytesBuf := make([]byte, int(nEls)*bytesPerElement)
58+
elBuf := make([]big.Int, nEls)
7359
res := make([]*big.Int, nEls)
7460
for i := range res {
75-
res[i] = &buf[i]
61+
res[i] = &elBuf[i]
7662
}
7763

78-
bigRound := big.NewInt(int64(round))
64+
// Assumes all shared secrets are the same length
65+
roundKeyBuf := make([]byte, 4+len(sharedSecrets[0]))
66+
binary.BigEndian.PutUint32(roundKeyBuf[:4], uint32(round))
7967

80-
secretElementGenerator := SharedSecretsGenerator(sharedSecrets, bigRound, fieldOrder)
81-
// Note: we can chunk and parallelize. Be careful with the generator though.
82-
DeriveBlindingVectorInplace(res, secretElementGenerator, bigRound, 0, len(res), fieldOrder)
83-
return res
84-
}
68+
workingEl := big.NewInt(0)
69+
70+
for _, sharedSecret := range sharedSecrets {
71+
copy(roundKeyBuf[4:], sharedSecret)
72+
roundSharedKey := sha3.Sum256(roundKeyBuf)
8573

86-
// DeriveBlindingVectorInplace computes blinding factors in-place for a range of indices.
87-
// This is used internally by DeriveBlindingVector and can be parallelized by chunking.
88-
func DeriveBlindingVectorInplace(res []*big.Int, secretElementGenerator *big.Int, round *big.Int, start int, end int, fieldOrder *big.Int) {
89-
nonceBuf := make([]byte, 8)
90-
binary.BigEndian.PutUint32(nonceBuf, uint32(round.Int64()))
91-
nonce := new(big.Int)
92-
el := new(big.Int).Exp(secretElementGenerator, big.NewInt(int64(start)), fieldOrder)
93-
94-
for i := start; i < end; i++ {
95-
binary.BigEndian.PutUint32(nonceBuf[4:], uint32(i))
96-
nonce.SetBytes(nonceBuf)
97-
res[i].Mul(res[i], nonce.Mod(nonce, nonce.Mul(nonce, prfSeed)))
98-
res[i].Mod(res[i], fieldOrder)
99-
el.Mul(el, secretElementGenerator)
100-
el.Mod(el, fieldOrder)
74+
block, err := aes.NewCipher(roundSharedKey[:])
75+
if err != nil {
76+
panic(err.Error())
77+
}
78+
79+
block.Encrypt(dstBytesBuf, srcBytesBuf)
80+
81+
for i := 0; i < int(nEls); i++ {
82+
workingEl.SetBytes(dstBytesBuf[i*bytesPerElement:(i+1)*bytesPerElement])
83+
FieldAddInplace(res[i], workingEl, fieldOrder)
84+
}
10185
}
86+
87+
return res
10288
}
10389

10490
// RandomPolynomialEvals generates a random polynomial of given degree that evaluates

crypto/shared_secrets.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

protocol/routines.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func (c *ClientMessager) SecretShareMessage(currentRound int, messageElements []
244244
}
245245
slices.Sort(serverIDs) // Ensure deterministic order
246246

247+
// Note: we prepare the blinding vector before secret sharing the messages. The order doesn't matter from cryptographic standpoint, but we avoid a round of allocation and initialization this way.
248+
247249
auctionVectors := make(map[int32][]*big.Int, len(c.SharedSecrets))
248250
for _, sId := range serverIDs {
249251
sharedSecret := c.SharedSecrets[sId]

0 commit comments

Comments
 (0)