module ECDSA::Format::PointOctetString
Public Class Methods
decode(string, group)
click to toggle source
# File lib/schnorr/ec_point_ext.rb, line 27 def self.decode(string, group) string = string.dup.force_encoding('BINARY') raise DecodeError, 'Point octet string is empty.' if string.empty? if string.bytesize == 32 decode_from_x(string, group) else case string[0].ord when 0 check_length string, 1 return group.infinity when 2 decode_compressed string, group, 0 when 3 decode_compressed string, group, 1 when 4 decode_uncompressed string, group else raise DecodeError, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord end end end
decode_from_x(x_string, group)
click to toggle source
decode from x coordinate. @param (String) x_string X-coordinate binary string @param (ECDSA::Group) group A group of elliptic curves to use. @return (ECDSA::Point
) decoded point.
# File lib/schnorr/ec_point_ext.rb, line 55 def self.decode_from_x(x_string, group) x = ECDSA::Format::FieldElementOctetString.decode(x_string, group.field) y_sq = group.field.mod(x.pow(3, group.field.prime) + 7) y = y_sq.pow((group.field.prime + 1)/4, group.field.prime) raise DecodeError, 'Public key not on the curve.' unless y.pow(2, group.field.prime) == y_sq finish_decode(x, y.even? ? y : group.field.prime - y, group) end