Documentation improvements, code cleaned up #2

Merged
pdyraga merged 31 commits from master-with-bson into master 2018-06-05 19:08:37 -04:00
2 changed files with 12 additions and 15 deletions
Showing only changes of commit e43575684d - Show all commits

No files matched your search

+4 -11
View File
@@ -57,7 +57,6 @@ type dbThresholdKey struct {
V string V string
Vi []string Vi []string
N string N string
G string
} }
func (this *dbThresholdKey) FromThresholdKey(key *ThresholdKey) { func (this *dbThresholdKey) FromThresholdKey(key *ThresholdKey) {
@@ -65,7 +64,6 @@ func (this *dbThresholdKey) FromThresholdKey(key *ThresholdKey) {
this.Threshold = key.Threshold this.Threshold = key.Threshold
this.V = fmt.Sprintf("%x", key.V) this.V = fmt.Sprintf("%x", key.V)
this.N = fmt.Sprintf("%x", key.N) this.N = fmt.Sprintf("%x", key.N)
this.G = fmt.Sprintf("%x", key.G)
this.Vi = make([]string, len(key.Vi)) this.Vi = make([]string, len(key.Vi))
for i, vi := range key.Vi { for i, vi := range key.Vi {
this.Vi[i] = fmt.Sprintf("%x", vi) this.Vi[i] = fmt.Sprintf("%x", vi)
@@ -75,10 +73,9 @@ func (this *dbThresholdKey) FromThresholdKey(key *ThresholdKey) {
func (this *dbThresholdKey) ToThresholdKey(key *ThresholdKey) error { func (this *dbThresholdKey) ToThresholdKey(key *ThresholdKey) error {
key.TotalNumberOfDecryptionServers = this.TotalNumberOfDecryptionServers key.TotalNumberOfDecryptionServers = this.TotalNumberOfDecryptionServers
key.Threshold = this.Threshold key.Threshold = this.Threshold
oks := make([]bool, 3) oks := make([]bool, 2)
key.V, oks[0] = new(big.Int).SetString(this.V, 16) key.V, oks[0] = new(big.Int).SetString(this.V, 16)
key.N, oks[1] = new(big.Int).SetString(this.N, 16) key.N, oks[1] = new(big.Int).SetString(this.N, 16)
key.G, oks[2] = new(big.Int).SetString(this.G, 16)
if !all(oks) { if !all(oks) {
return errors.New("not hexadecimal") return errors.New("not hexadecimal")
} }
@@ -110,7 +107,6 @@ func (this *ThresholdKey) SetBSON(raw bson.Raw) error {
type dbPrivateKey struct { type dbPrivateKey struct {
N string `bson:",omitempty"` N string `bson:",omitempty"`
G string `bson:",omitempty"`
Lambda string `bson:",omitempty"` Lambda string `bson:",omitempty"`
Mu string `bson:",omitempty"` Mu string `bson:",omitempty"`
} }
@@ -154,7 +150,6 @@ type dbPartialDecryptionZKP struct {
E string `json:"e"` E string `json:"e"`
C string `json:"c"` C string `json:"c"`
V string `json:"v"` V string `json:"v"`
G string `json:"g"`
N string `json:"n"` N string `json:"n"`
Vi []string `json:"vi"` Vi []string `json:"vi"`
Decryption string `json:"decryption"` Decryption string `json:"decryption"`
@@ -169,7 +164,6 @@ func (this *dbPartialDecryptionZKP) FromPartialDecryptionZKP(pd *PartialDecrypti
this.Threshold = pd.Key.Threshold this.Threshold = pd.Key.Threshold
this.Z = fmt.Sprintf("%x", pd.Z) this.Z = fmt.Sprintf("%x", pd.Z)
this.E = fmt.Sprintf("%x", pd.E) this.E = fmt.Sprintf("%x", pd.E)
this.G = fmt.Sprintf("%x", pd.Key.G)
this.N = fmt.Sprintf("%x", pd.Key.N) this.N = fmt.Sprintf("%x", pd.Key.N)
this.C = fmt.Sprintf("%x", pd.C) this.C = fmt.Sprintf("%x", pd.C)
this.V = fmt.Sprintf("%x", pd.Key.V) this.V = fmt.Sprintf("%x", pd.Key.V)
@@ -183,7 +177,7 @@ func (this *dbPartialDecryptionZKP) FromPartialDecryptionZKP(pd *PartialDecrypti
func (this *dbPartialDecryptionZKP) ToPartialDecryptionZKP(pd *PartialDecryptionZKP) error { func (this *dbPartialDecryptionZKP) ToPartialDecryptionZKP(pd *PartialDecryptionZKP) error {
pd.Key = new(ThresholdKey) pd.Key = new(ThresholdKey)
var oks = make([]bool, 7) var oks = make([]bool, 6)
pd.Id = this.Id pd.Id = this.Id
pd.Key.TotalNumberOfDecryptionServers = this.TotalNumberOfDecryptionServers pd.Key.TotalNumberOfDecryptionServers = this.TotalNumberOfDecryptionServers
@@ -192,9 +186,8 @@ func (this *dbPartialDecryptionZKP) ToPartialDecryptionZKP(pd *PartialDecryption
pd.E, oks[1] = new(big.Int).SetString(this.E, 16) pd.E, oks[1] = new(big.Int).SetString(this.E, 16)
pd.C, oks[2] = new(big.Int).SetString(this.C, 16) pd.C, oks[2] = new(big.Int).SetString(this.C, 16)
pd.Key.V, oks[3] = new(big.Int).SetString(this.V, 16) pd.Key.V, oks[3] = new(big.Int).SetString(this.V, 16)
pd.Key.G, oks[4] = new(big.Int).SetString(this.G, 16) pd.Key.N, oks[4] = new(big.Int).SetString(this.N, 16)
pd.Key.N, oks[5] = new(big.Int).SetString(this.N, 16) pd.Decryption, oks[5] = new(big.Int).SetString(this.Decryption, 16)
pd.Decryption, oks[6] = new(big.Int).SetString(this.Decryption, 16)
if !all(oks) { if !all(oks) {
fmt.Println(oks) fmt.Println(oks)
+8 -4
View File
@@ -85,14 +85,13 @@ func TestPartialDecryptionZKPJsonification(t *testing.T) {
pd.Key.Threshold = 98 pd.Key.Threshold = 98
pd.Key.TotalNumberOfDecryptionServers = 230 pd.Key.TotalNumberOfDecryptionServers = 230
pd.Id = 1 pd.Id = 1
pd.Key.Vi = []*big.Int{b(77), b(67)} // vi is 67 pd.Key.Vi = []*big.Int{b(77), b(67)}
pd.Key.N = b(131) pd.Key.N = b(131)
pd.Key.V = b(101) pd.Key.V = b(101)
pd.Decryption = b(171) pd.Decryption = b(171)
pd.E = b(112) pd.E = b(112)
pd.C = b(99) pd.C = b(99)
pd.Key.N = b(345) pd.Key.N = b(345)
pd.Key.G = b(99)
pd.Z = b(88) pd.Z = b(88)
AssertJSONIsGood(pd, new(PartialDecryptionZKP), t) AssertJSONIsGood(pd, new(PartialDecryptionZKP), t)
@@ -111,13 +110,18 @@ func TestPartialDecryptionZKPBSONification(t *testing.T) {
pd.E = b(112) pd.E = b(112)
pd.C = b(99) pd.C = b(99)
pd.Key.N = b(345) pd.Key.N = b(345)
pd.Key.G = b(99)
pd.Z = b(88) pd.Z = b(88)
AssertBSONIsGood(pd, new(PartialDecryptionZKP), t) AssertBSONIsGood(pd, new(PartialDecryptionZKP), t)
} }
func TestThresholdKeyBSON(t *testing.T) { func TestThresholdKeyBSON(t *testing.T) {
key := &ThresholdKey{PublicKey{b(9)}, 7, 6, b(3), []*big.Int{b(2), b(34)}, b(8)} key := &ThresholdKey{
PublicKey: PublicKey{b(9)},
TotalNumberOfDecryptionServers: 7,
Threshold: 6,
V: b(3),
Vi: []*big.Int{b(2), b(34)},
}
AssertBSONIsGood(key, new(ThresholdKey), t) AssertBSONIsGood(key, new(ThresholdKey), t)
} }