Skip to content
Snippets Groups Projects
Commit 18a4efdd authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

implemented the mechanisim for a variable keying threshold.

parent e9f82d27
No related branches found
No related tags found
3 merge requests!117Release,!116Dev,!115Rekey threshold
......@@ -166,6 +166,7 @@ Flags:
--e2eMaxKeys uint Max keys used before blocking until a rekey completes (default 800)
--e2eMinKeys uint Minimum number of keys used before requesting rekey (default 500)
--e2eNumReKeys uint Number of rekeys reserved for rekey operations (default 16)
--e2eRekeyThreshold float64 Number between 0 an 1. Percent of keys used before a rekey is started
--forceHistoricalRounds Force all rounds to be sent to historical round retrieval
--forceMessagePickupRetry Enable a mechanism which forces a 50% chance of no message pickup, instead triggering the message pickup retry mechanism
-h, --help help for client
......
......@@ -573,6 +573,7 @@ func createClient() *api.Client {
netParams.E2EParams.MaxKeys = uint16(viper.GetUint("e2eMaxKeys"))
netParams.E2EParams.NumRekeys = uint16(
viper.GetUint("e2eNumReKeys"))
netParams.E2EParams.RekeyThreshold = viper.GetFloat64("e2eRekeyThreshold")
netParams.ForceHistoricalRounds = viper.GetBool("forceHistoricalRounds")
netParams.FastPolling = !viper.GetBool("slowPolling")
netParams.ForceMessagePickupRetry = viper.GetBool("forceMessagePickupRetry")
......@@ -596,6 +597,7 @@ func initClient() *api.Client {
netParams.E2EParams.MaxKeys = uint16(viper.GetUint("e2eMaxKeys"))
netParams.E2EParams.NumRekeys = uint16(
viper.GetUint("e2eNumReKeys"))
netParams.E2EParams.RekeyThreshold = viper.GetFloat64("e2eRekeyThreshold")
netParams.ForceHistoricalRounds = viper.GetBool("forceHistoricalRounds")
netParams.FastPolling = viper.GetBool(" slowPolling")
netParams.ForceMessagePickupRetry = viper.GetBool("forceMessagePickupRetry")
......@@ -1069,6 +1071,10 @@ func init() {
"", uint(defaultE2EParams.NumRekeys),
"Number of rekeys reserved for rekey operations")
viper.BindPFlag("e2eNumReKeys", rootCmd.Flags().Lookup("e2eNumReKeys"))
rootCmd.Flags().Float64P("e2eRekeyThreshold",
"", defaultE2EParams.RekeyThreshold,
"Number between 0 an 1. Percent of keys used before a rekey is started")
viper.BindPFlag("e2eRekeyThreshold", rootCmd.Flags().Lookup("e2eRekeyThreshold"))
rootCmd.Flags().String("profile-cpu", "",
"Enable cpu profiling to this file")
......
......@@ -10,7 +10,6 @@ package params
import (
"encoding/json"
"fmt"
"gitlab.com/elixxir/crypto/e2e"
)
type E2E struct {
......@@ -64,35 +63,37 @@ func (st SendType) String() string {
// Network E2E Params
// DEFAULT KEY GENERATION PARAMETERS
// Hardcoded limits for keys
// With 16 receiving states we can hold
// 16*64=1024 dirty bits for receiving keys
// With that limit, and setting maxKeys to 800,
// we need a Threshold of 224, and a scalar
// smaller than 1.28 to ensure we never generate
// more than 1024 keys
// With 1 receiving states for ReKeys we can hold
// 64 Rekeys
const (
minKeys uint16 = 500
maxKeys uint16 = 800
ttlScalar float64 = 1.2 // generate 20% extra keys
threshold uint16 = 224
numReKeys uint16 = 16
)
type E2ESessionParams struct {
// using the DH as a seed, both sides generate a number
// of keys to use before they must rekey because
// there are no keys to use.
MinKeys uint16
MaxKeys uint16
// the percent of keys before a rekey is attempted. must be <0
RekeyThreshold float64
// extra keys generated and reserved for rekey attempts. This
// many keys are not allowed to be used for sending messages
// in order to ensure there are extras for rekeying.
NumRekeys uint16
e2e.TTLParams
}
// DEFAULT KEY GENERATION PARAMETERS
// Hardcoded limits for keys
// sets the number of keys very high, but with a low rekey threshold. In this case, if the other party is online, you will read
const (
minKeys uint16 = 1000
maxKeys uint16 = 2000
rekeyThrshold float64 = 0.05
numReKeys uint16 = 16
)
func GetDefaultE2ESessionParams() E2ESessionParams {
return E2ESessionParams{
MinKeys: minKeys,
MaxKeys: maxKeys,
RekeyThreshold: rekeyThrshold,
NumRekeys: numReKeys,
}
}
......
......@@ -22,6 +22,7 @@ import (
"gitlab.com/xx_network/crypto/randomness"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"math"
"math/big"
"sync"
"testing"
......@@ -637,8 +638,8 @@ func (s *Session) generate(kv *versioned.KV) *versioned.KV {
int64(p.MaxKeys-p.MinKeys)),
s.baseKey.Bytes(), h).Int64() + int64(p.MinKeys))
// start rekeying when 75% of keys have been used
s.rekeyThreshold = (numKeys * 3) / 4
// start rekeying when enough keys have been used
s.rekeyThreshold = uint32(math.Ceil(s.e2eParams.RekeyThreshold*float64(numKeys)))
// the total number of keys should be the number of rekeys plus the
// number of keys to use
......
......@@ -263,12 +263,6 @@ func cmpSerializedFields(a *Session, b *Session) error {
if a.e2eParams.NumRekeys != b.e2eParams.NumRekeys {
return errors.New("NumRekeys differed")
}
if a.e2eParams.MinNumKeys != b.e2eParams.MinNumKeys {
return errors.New("minNumKeys differed")
}
if a.e2eParams.TTLScalar != b.e2eParams.TTLScalar {
return errors.New("ttlScalar differed")
}
if a.baseKey.Cmp(b.baseKey) != 0 {
return errors.New("baseKey differed")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment