1
1
module DecryptionProofs
2
2
3
3
using .. Serializer: Serializer, Path, load
4
- using .. SigmaProofs. Parser: Parser, Tree
4
+ using .. SigmaProofs. Parser: Parser, Tree, width_elgamal_vec
5
5
using .. SigmaProofs: Proposition, Verifier, Simulator
6
6
using .. ElGamal: ElGamalRow
7
7
using .. LogProofs: ChaumPedersenProof, LogEquality
@@ -162,27 +162,37 @@ end
162
162
163
163
Serializer. save (proof:: ChaumPedersenProof , :: Type{<:Decryption} , path:: Path ) = Serializer. save (proof, path; prefix= " Decryption" )
164
164
165
- function Serializer. load (:: Type{Decryption} , basedir:: Path )
165
+ function Serializer. load (:: Type{T} , basedir:: Path ) where T <: Decryption
166
+
167
+ _extract_group (:: Type{Decryption{G}} ) where G <: Group = G
168
+ _extract_group (:: Type{Decryption} ) = nothing
169
+
170
+ G = _extract_group (T)
166
171
167
172
publickey_tree = Parser. decode (read (joinpath (basedir, " publicKey.bt" )))
168
173
pk, g = Parser. unmarshal_publickey (publickey_tree; relative= true )
169
174
170
- G = typeof (g)
175
+ if isnothing (G)
176
+ G = typeof (g)
177
+ else
178
+ pk = convert (G, pk)
179
+ g = convert (G, g)
180
+ end
171
181
172
182
ciphertexts_tree = Parser. decode (read (joinpath (basedir, " Ciphertexts.bt" )))
173
183
plaintexts_tree = Parser. decode (read (joinpath (basedir, " Decryption.bt" )))
174
-
175
- N = 1 # ToDo: extract that from the tree
184
+
185
+ N = width_elgamal_vec (G, ciphertexts_tree)
176
186
177
187
ciphertexts = convert (Vector{ElGamalRow{G, N}}, ciphertexts_tree)
178
188
plaintexts = convert (Vector{NTuple{N, G}}, plaintexts_tree)
179
189
180
190
return Decryption (g, pk, ciphertexts, plaintexts)
181
191
end
182
192
183
- Serializer. load (:: Type{P} , :: Type{ Decryption} , path :: Path ) where P <: ChaumPedersenProof = Serializer . load (P, path; prefix = " Decryption " )
193
+ Serializer. load (:: Type{Decryption{G}} , basedir :: Path ) where G <: Group = load (Decryption, basedir; G )
184
194
185
- # ToDO
195
+ Serializer . load ( :: Type{P} , :: Type{Decryption} , path :: Path ) where P <: ChaumPedersenProof = Serializer . load (P, path; prefix = " Decryption " )
186
196
187
197
function Serializer. save (proposition:: DecryptionInv , dir:: Path )
188
198
@@ -199,17 +209,28 @@ end
199
209
200
210
Serializer. save (proof:: ChaumPedersenProof , :: Type{<:DecryptionInv} , path:: Path ) = Serializer. save (proof, path; prefix= " DecryptionInv" )
201
211
202
- function Serializer. load (:: Type{DecryptionInv} , basedir:: Path )
203
-
212
+
213
+ function Serializer. load (:: Type{T} , basedir:: Path ) where T <: DecryptionInv
214
+
215
+ _extract_group (:: Type{DecryptionInv{G}} ) where G <: Group = G
216
+ _extract_group (:: Type{DecryptionInv} ) = nothing
217
+
218
+ G = _extract_group (T)
219
+
204
220
publickey_tree = Parser. decode (read (joinpath (basedir, " publicKey.bt" )))
205
221
pk, g = Parser. unmarshal_publickey (publickey_tree; relative= true )
206
222
207
- G = typeof (g)
223
+ if isnothing (G)
224
+ G = typeof (g)
225
+ else
226
+ pk = convert (G, pk)
227
+ g = convert (G, g)
228
+ end
208
229
209
230
ciphertexts_tree = Parser. decode (read (joinpath (basedir, " Ciphertexts.bt" )))
210
231
plaintexts_tree = Parser. decode (read (joinpath (basedir, " DecryptionInv.bt" )))
211
232
212
- N = 1 # ToDo: extract that from the tree
233
+ N = width_elgamal_vec (G, ciphertexts_tree)
213
234
214
235
ciphertexts = convert (Vector{ElGamalRow{G, N}}, ciphertexts_tree)
215
236
plaintexts = convert (Vector{NTuple{N, G}}, plaintexts_tree)
0 commit comments