Module: JOSE::JWA::X25519_RbNaCl
Instance Method Summary collapse
- #curve25519(k, u) ⇒ Object
- #keypair(sk = nil) ⇒ Object
- #shared_secret(pk, sk) ⇒ Object
- #sk_to_pk(sk) ⇒ Object
- #x25519(sk, pk) ⇒ Object
- #x25519_base(sk) ⇒ Object
Instance Method Details
#curve25519(k, u) ⇒ Object
5 6 7 8 9 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 5 def curve25519(k, u) k = JOSE::JWA::X25519.coerce_scalar_bytes!(k) if not k.respond_to?(:bytesize) u = RbNaCl::GroupElements::Curve25519.new(JOSE::JWA::X25519.coerce_coordinate_bytes!(u)) if not u.is_a?(RbNaCl::GroupElements::Curve25519) return u.mult(k) end |
#keypair(sk = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 20 def keypair(sk = nil) sk ||= RbNaCl::Random.random_bytes(JOSE::JWA::X25519::C_bytes) sk = JOSE::JWA::X25519.clamp_scalar(sk) pk = sk_to_pk(sk) return pk, sk.to_bytes(JOSE::JWA::X25519::C_bits) end |
#shared_secret(pk, sk) ⇒ Object
27 28 29 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 27 def shared_secret(pk, sk) return x25519(sk, pk) end |
#sk_to_pk(sk) ⇒ Object
31 32 33 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 31 def sk_to_pk(sk) return x25519_base(sk) end |
#x25519(sk, pk) ⇒ Object
11 12 13 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 11 def x25519(sk, pk) return curve25519(sk, pk).to_bytes end |
#x25519_base(sk) ⇒ Object
15 16 17 18 |
# File 'lib/jose/jwa/x25519_rbnacl.rb', line 15 def x25519_base(sk) sk = JOSE::JWA::X25519.coerce_scalar_bytes!(sk) if not sk.respond_to?(:bytesize) return RbNaCl::GroupElements::Curve25519.base_point.mult(sk).to_bytes end |