Class: Oqs::SIG
- Inherits:
-
Object
- Object
- Oqs::SIG
- Defined in:
- lib/oqs/sig.rb
Class Method Summary collapse
Instance Method Summary collapse
- #algo_version ⇒ Object
- #cleanup ⇒ Object
- #free(obj) ⇒ Object
- #genkeypair ⇒ Object
-
#initialize(name) ⇒ SIG
constructor
A new instance of SIG.
- #intrinsic_name ⇒ Object
- #method_missing(mtd, *args, &block) ⇒ Object
- #sign(message, privKey) ⇒ Object
- #verify(message, signature, pubKey) ⇒ Object
Constructor Details
#initialize(name) ⇒ SIG
Returns a new instance of SIG.
24 25 26 27 28 29 |
# File 'lib/oqs/sig.rb', line 24 def initialize(name) @algo = name oqsSig = SIGWrapper.OQS_SIG_new(@algo) raise Error, "Unable to create object '#{@algo}'. It is either the algorithm not supported or it is disabled at compile time." if oqsSig.null? @struct = OQS_SIG.new(oqsSig) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mtd, *args, &block) ⇒ Object
47 48 49 |
# File 'lib/oqs/sig.rb', line 47 def method_missing(mtd, *args, &block) @struct.send(mtd) if not @struct.nil? and @struct.respond_to?(mtd) end |
Class Method Details
.supported_signature_algo ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/oqs/sig.rb', line 9 def self.supported_signature_algo ttl = SIGWrapper.OQS_SIG_alg_count supported = [] (0...ttl).each do |i| pName = SIGWrapper.OQS_SIG_alg_identifier(i) name = pName.to_s st = SIGWrapper.OQS_SIG_alg_is_enabled(name) if st supported << name end end supported end |
Instance Method Details
#algo_version ⇒ Object
43 44 45 |
# File 'lib/oqs/sig.rb', line 43 def algo_version @struct.algo_version.to_s end |
#cleanup ⇒ Object
31 32 33 |
# File 'lib/oqs/sig.rb', line 31 def cleanup SIGWrapper.OQS_SIG_free(@struct) if not @struct.nil? end |
#free(obj) ⇒ Object
35 36 37 |
# File 'lib/oqs/sig.rb', line 35 def free(obj) obj.free if not (obj.nil? and obj.null?) end |
#genkeypair ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/oqs/sig.rb', line 51 def genkeypair pubKey = Fiddle::Pointer.malloc(@struct.length_public_key, Fiddle::RUBY_FREE) raise Error, "Unable to allocate memory for public key size #{@struct.length_public_key}" if pubKey.null? privKey = Fiddle::Pointer.malloc(@struct.length_secret_key, Fiddle::RUBY_FREE) raise Error, "Unable to allocate memory for secret key size #{@struct.length_secret_key}" if privKey.null? rv = SIGWrapper.OQS_SIG_keypair(@struct, pubKey, privKey) raise Error, "Error in generation of keypair" if rv != Oqs::OQS_SUCCESS [pubKey, privKey] end |
#intrinsic_name ⇒ Object
39 40 41 |
# File 'lib/oqs/sig.rb', line 39 def intrinsic_name @struct.intrinsic_name.to_s end |
#sign(message, privKey) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/oqs/sig.rb', line 74 def sign(, privKey) raise Error, "Private key cannot be nil" if privKey.nil? signature = Fiddle::Pointer.malloc(@struct.length_signature, Fiddle::RUBY_FREE) raise Error, "Unable to allocate memory for signature size #{@struct.length_signature}" if signature.null? signLen = Fiddle::Pointer.malloc(Fiddle::SIZEOF_SIZE_T, Fiddle::RUBY_FREE) raise Error, "Unable to allocate memory for signature length size #{Fiddle::SIZEOF_SIZE_T}" if signLen.null? pMessage = Fiddle::Pointer.to_ptr() rv = SIGWrapper.OQS_SIG_sign(@struct, signature, signLen, pMessage, .length, privKey) raise Error, "Error in signing" if rv != Oqs::OQS_SUCCESS signBin = signature[0, signLen.ptr.to_i] signLen.free signature.free signBin end |
#verify(message, signature, pubKey) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/oqs/sig.rb', line 63 def verify(,signature,pubKey) pMessage = Fiddle::Pointer.to_ptr() pSignature = Fiddle::Pointer.to_ptr(signature) rv = SIGWrapper.OQS_SIG_verify(@struct, pMessage, .length, pSignature, signature.length, pubKey) rv == Oqs::OQS_SUCCESS end |