Class: MooTool::Models::ECIESEncryption

Inherits:
Object
  • Object
show all
Includes:
Helpers::IMG4
Defined in:
lib/mootool/models/ecies_encryption.rb

Overview

Elliptic Curve Integrated Encryption Scheme Encryption

Constant Summary

Constants included from Helpers::IMG4

Helpers::IMG4::DECODE_TAGS, Helpers::IMG4::FIRMWARE_TAGS, Helpers::IMG4::HASH_LENGTHS, Helpers::IMG4::KEY_INSTANCE_TAGS, Helpers::IMG4::KVP_TAGS, Helpers::IMG4::OCTET_TAGS, Helpers::IMG4::SEQUENCE_TAGS, Helpers::IMG4::SIGNATURE_TAGS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::IMG4

#construct, #construct_object, #decode_construct, parse_4cc

Constructor Details

#initialize(input, nonce) ⇒ ECIESEncryption

Returns a new instance of ECIESEncryption.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mootool/models/ecies_encryption.rb', line 11

def initialize(input, nonce)
  # Recall that uncompressed points start with 0x04 to indicate that they are uncompressed
  # To get the proper X / Y we must trip this off first, then divide the string in half
  hex = input.to_octet_string(:uncompressed)[1..]
  pair = hex[0..(hex.length / 2)], hex[(hex.length / 2)..]
  @point = input
  @e_x = Models::Digest.create pair[0]
  @e_y = Models::Digest.create pair[1]

  @nonce = Models::Digest.create(nonce)
end

Instance Attribute Details

#nonceObject (readonly)

Returns the value of attribute nonce.



9
10
11
# File 'lib/mootool/models/ecies_encryption.rb', line 9

def nonce
  @nonce
end

#pointObject (readonly)

Returns the value of attribute point.



9
10
11
# File 'lib/mootool/models/ecies_encryption.rb', line 9

def point
  @point
end

Class Method Details

.from_der(data) ⇒ Object



23
24
25
# File 'lib/mootool/models/ecies_encryption.rb', line 23

def self.from_der(data)
  OpenSSL::ASN1.decode(data)
end

Instance Method Details

#groupObject



38
39
40
# File 'lib/mootool/models/ecies_encryption.rb', line 38

def group
  @point.group.curve_name
end

#inspectObject



46
47
48
# File 'lib/mootool/models/ecies_encryption.rb', line 46

def inspect
  to_h.ai
end

#parse_point_any(point) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/mootool/models/ecies_encryption.rb', line 27

def parse_point_any(point)
  mappings = %w[prime256v1 secp384r1].map do |group|
    group = OpenSSL::PKey::EC::Group.new(group)
    OpenSSL::PKey::EC::Point.new(group, point)
  rescue StandardError
    nil
  end

  mappings.compact.first
end

#to_hObject



42
43
44
# File 'lib/mootool/models/ecies_encryption.rb', line 42

def to_h
  { e_x: @e_x.shasum, e_y: @e_y.shasum, n: @nonce.shasum }
end