Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
paths-ignore:
- README.md
push:
branches: main
paths-ignore:
- README.md

Expand All @@ -16,14 +15,17 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- ruby-2.5
- ruby-2.6
- ruby-2.7
- ruby-3.0
- ruby-3.1
- ruby-3.2
- ruby-3.3
- ruby-head
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -34,9 +36,9 @@ jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
ruby-version: 2.7
bundler-cache: true
- run: bundle exec rubocop --format progress --color
18 changes: 17 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
DisplayCopNames: true
NewCops: enable

#
# Metrics
Expand Down Expand Up @@ -36,3 +42,13 @@ Style/FrozenStringLiteralComment:

Style/StringLiterals:
EnforcedStyle: double_quotes

#
# RSpec
#

RSpec/MultipleExpectations:
Max: 3

RSpec/ExampleLength:
Max: 6
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ group :development, :test do
gem "rake", require: false
gem "rake-compiler", "~> 1.0", require: false
gem "rspec", "~> 3.10", require: false
gem "rubocop", "1.18", require: false
gem "rubocop", "1.68", require: false
gem "rubocop-performance", "1.23.0", require: false
gem "rubocop-rake", "0.6.0", require: false
gem "rubocop-rspec", "3.2.0", require: false
end
2 changes: 1 addition & 1 deletion ext/x25519_precomputed/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require "mkmf"

if RUBY_PLATFORM =~ /x86_64|x64/
if RUBY_PLATFORM.match?(/x86_64|x64/)
$CFLAGS << " -Wall -O3 -pedantic -std=c99 -mbmi -mbmi2 -march=haswell"

create_makefile "x25519_precomputed"
Expand Down
4 changes: 2 additions & 2 deletions spec/x25519/montgomery_u_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

RSpec.describe X25519::MontgomeryU do
let(:coordinate_hex) { "e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c" }

subject(:point) { described_class.new(unhex(coordinate_hex)) }

let(:coordinate_hex) { "e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c" }

describe "#to_bytes" do
it "serializes #{described_class} as a Encoding::BINARY String" do
bytes = point.to_bytes
Expand Down
8 changes: 4 additions & 4 deletions spec/x25519/scalar_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

RSpec.describe X25519::Scalar do
let(:scalar_hex) { "a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4" }

subject(:scalar) { described_class.new(unhex(scalar_hex)) }

let(:scalar_hex) { "a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4" }

describe ".generate" do
it "generates random keys" do
# Not great, but better than nothing
Expand All @@ -21,7 +21,7 @@
expect { scalar.multiply("derp") }.to raise_error(TypeError)
end

context "RFC 7748 test vectors" do
context "with RFC 7748 test vectors" do
it "passes the test vectors" do
X25519::TestVectors::VARIABLE_BASE.each do |v|
scalar = described_class.new(unhex(v.scalar))
Expand All @@ -35,7 +35,7 @@
end

describe "#multiply_base" do
context "RFC 7748 test vectors" do
context "with RFC 7748 test vectors" do
it "passes the test vectors" do
X25519::TestVectors::FIXED_BASE.each do |v|
scalar = described_class.new(unhex(v.scalar))
Expand Down
4 changes: 2 additions & 2 deletions spec/x25519_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe X25519 do
it "has a version number" do
expect(described_class::VERSION).not_to be nil
expect(described_class::VERSION).not_to be_nil
end

describe ".diffie_hellman" do
Expand All @@ -24,7 +24,7 @@
end.to raise_error(X25519::InvalidKeyError)
end

context "RFC 7748 test vectors" do
context "with RFC 7748 test vectors" do
it "passes the test vectors" do
X25519::TestVectors::VARIABLE_BASE.each do |v|
shared_secret = described_class.diffie_hellman(unhex(v.scalar), unhex(v.input_coord))
Expand Down
8 changes: 2 additions & 6 deletions x25519.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require File.expand_path("lib/x25519/version", __dir__)
require_relative "lib/x25519/version"

Gem::Specification.new do |spec|
spec.name = "x25519"
Expand All @@ -16,12 +16,8 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/RubyCrypto/x25519"
spec.license = "BSD-3-Clause" # https://spdx.org/licenses/BSD-3-Clause.html
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.platform = Gem::Platform::RUBY
spec.extensions = ["ext/x25519_precomputed/extconf.rb", "ext/x25519_ref10/extconf.rb"]

spec.required_ruby_version = ">= 2.5"
spec.add_development_dependency "bundler", "~> 2.1"
spec.required_ruby_version = ">= 2.7"
end