Class: Paillier::ZKP::ZKPCommit
- Inherits:
-
Object
- Object
- Paillier::ZKP::ZKPCommit
- Defined in:
- lib/paillier/zkp.rb
Overview
Wrapper class used for containing the components of the ZKP commitment
Instance Attribute Summary collapse
-
#a_s ⇒ Object
readonly
:nodoc:.
-
#e_s ⇒ Object
readonly
:nodoc:.
-
#z_s ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.from_s(string) ⇒ Object
Deserializes a commitment.
Instance Method Summary collapse
-
#==(y) ⇒ Object
operator overload to compare two ZKP commit objects.
-
#initialize(a_s, e_s, z_s) ⇒ ZKPCommit
constructor
:nodoc:.
-
#to_s ⇒ Object
Serializes a commitment .
Constructor Details
#initialize(a_s, e_s, z_s) ⇒ ZKPCommit
:nodoc:
219 220 221 222 223 |
# File 'lib/paillier/zkp.rb', line 219 def initialize(a_s, e_s, z_s) # :nodoc: @a_s = a_s @e_s = e_s @z_s = z_s end |
Instance Attribute Details
#a_s ⇒ Object (readonly)
:nodoc:
217 218 219 |
# File 'lib/paillier/zkp.rb', line 217 def a_s @a_s end |
#e_s ⇒ Object (readonly)
:nodoc:
217 218 219 |
# File 'lib/paillier/zkp.rb', line 217 def e_s @e_s end |
#z_s ⇒ Object (readonly)
:nodoc:
217 218 219 |
# File 'lib/paillier/zkp.rb', line 217 def z_s @z_s end |
Class Method Details
.from_s(string) ⇒ Object
Deserializes a commitment
Example:
>> commit = Paillier::ZKP::ZKPCommit.from_s(commitment_string) => #<Paillier::ZKP::ZKPCommit: @a_s=[<a1>,<a2>, .. ,<an>], @e_s=[<e1>,<e2>, .. ,<en>], @z_s=[<z1>,<z2>, .. ,<zn>]>
Arguments: commitment_string: Serialization of a commitment (String)
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/paillier/zkp.rb', line 249 def ZKPCommit.from_s(string) # these will hold the final result from string-parsing a_s = Array.new e_s = Array.new z_s = Array.new # separate at the semicolons a_s_string, e_s_string, z_s_string = string.split(";") # separate at the commas a_s_strings = a_s_string.split(",") e_s_strings = e_s_string.split(",") z_s_strings = z_s_string.split(",") # convert into arrays of bignums for a in a_s_strings do a_s.push(OpenSSL::BN.new(a)) end for e in e_s_strings do e_s.push(OpenSSL::BN.new(e)) end for z in z_s_strings do z_s.push(OpenSSL::BN.new(z)) end # create the object with these arrays return ZKPCommit.new(a_s, e_s, z_s) end |
Instance Method Details
#==(y) ⇒ Object
operator overload to compare two ZKP commit objects
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/paillier/zkp.rb', line 279 def ==(y) #:nodoc: # if the array sizes don't match return false if @a_s.size != y.a_s.size return false end if @e_s.size != y.e_s.size return false end if @z_s.size != y.z_s.size return false end # if the corresponding elements in the arrays don't math return false for i in (0 .. (@a_s.size - 1)) do if(@a_s[i] != y.a_s[i]) return false end end for i in (0 .. (@e_s.size - 1)) do if(@e_s[i] != y.e_s[i]) return false end end for i in (0 .. (@z_s.size - 1)) do if(@z_s[i] != y.z_s[i]) return false end end # else return true return true end |
#to_s ⇒ Object
Serializes a commitment
Example:
>> myZKP = Paillier::ZKP.new(key, 65, [23, 38, 52, 65, 77, 94]) => [#<@p = plaintext>, #<@pubkey = <key>>, #<@ciphertext = <ciphertext>>, #<@cyphertext = <ciphertext>>, #<@commitment = <commitment>>] >> myZKP.commitment.to_s => “<a1>,<a2>,<a3>,<a4>,<a5>,<a6>,;<e1>,<e2>,<e3>,<e4>,<e5>,;<z1>,<z2>,<z3>,<z4>,<z5>,”
233 234 235 236 237 238 |
# File 'lib/paillier/zkp.rb', line 233 def to_s() a_s_string = @a_s.join(',') e_s_string = @e_s.join(',') z_s_string = @z_s.join(',') return "#{a_s_string};#{e_s_string};#{z_s_string}" end |