argon2 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +16 -0
  3. data/.github/workflows/ruby.yml +32 -0
  4. data/.rubocop.yml +150 -5
  5. data/Changelog.md +3 -0
  6. data/Gemfile +2 -0
  7. data/README.md +8 -7
  8. data/Rakefile +2 -0
  9. data/argon2.gemspec +9 -6
  10. data/bin/console +1 -0
  11. data/ext/argon2_wrap/argon_wrap.c +2 -0
  12. data/ext/argon2_wrap/extconf.rb +1 -0
  13. data/ext/phc-winner-argon2/.gitignore +1 -0
  14. data/ext/phc-winner-argon2/Argon2.sln +2 -4
  15. data/ext/phc-winner-argon2/LICENSE +2 -2
  16. data/ext/phc-winner-argon2/Makefile +86 -18
  17. data/ext/phc-winner-argon2/README.md +3 -1
  18. data/ext/phc-winner-argon2/include/argon2.h +3 -3
  19. data/ext/phc-winner-argon2/libargon2.pc.in +18 -0
  20. data/ext/phc-winner-argon2/src/argon2.c +2 -2
  21. data/ext/phc-winner-argon2/src/bench.c +4 -4
  22. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +3 -3
  23. data/ext/phc-winner-argon2/src/blake2/blake2.h +2 -2
  24. data/ext/phc-winner-argon2/src/blake2/blake2b.c +2 -2
  25. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +2 -2
  26. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +2 -2
  27. data/ext/phc-winner-argon2/src/core.c +20 -6
  28. data/ext/phc-winner-argon2/src/core.h +2 -2
  29. data/ext/phc-winner-argon2/src/encoding.c +2 -2
  30. data/ext/phc-winner-argon2/src/encoding.h +2 -2
  31. data/ext/phc-winner-argon2/src/genkat.c +9 -3
  32. data/ext/phc-winner-argon2/src/genkat.h +2 -2
  33. data/ext/phc-winner-argon2/src/opt.c +2 -2
  34. data/ext/phc-winner-argon2/src/ref.c +2 -2
  35. data/ext/phc-winner-argon2/src/run.c +2 -2
  36. data/ext/phc-winner-argon2/src/test.c +2 -2
  37. data/ext/phc-winner-argon2/src/thread.c +2 -2
  38. data/ext/phc-winner-argon2/src/thread.h +2 -2
  39. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +11 -6
  40. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +11 -6
  41. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +11 -6
  42. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +11 -6
  43. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +16 -8
  44. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +25 -8
  45. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +11 -6
  46. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +11 -6
  47. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +11 -6
  48. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +11 -6
  49. data/lib/argon2.rb +4 -2
  50. data/lib/argon2/ffi_engine.rb +31 -21
  51. data/lib/argon2/version.rb +1 -1
  52. metadata +40 -31
  53. data/.travis.yml +0 -13
  54. data/ext/phc-winner-argon2/libargon2.pc +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f448652ac1fb4a0d6d72144ea0aafb92081581f13c13b0c0b65912b1dfc79e1c
4
- data.tar.gz: a773a85b25a5048d39ee31b7abef28a84f1f74045609b28cc78c137d8a722cce
3
+ metadata.gz: ff5c2dcd38a21e51982265caf83a721327a8cff1a09acc5c51312ce92d2f5619
4
+ data.tar.gz: ab787b9e4ee2a039e286f5b96ebb65da86845749c7003de1b43061a2da2c3699
5
5
  SHA512:
6
- metadata.gz: fdc0083265c308602bc2a7f9d4948bc210e90fa20e617963736bc3d61163105acfaddb17438e52b9d81db5c0623f7b5a44d8fe059d13ccd08724e1a22a9471de
7
- data.tar.gz: 20bb002c7ba1828fed88e01cd3744873bb3a8b5c1a014bb2a99254653d8bafb44f3b4903509a859acff5a7668512f6cc350b0dda261d2b793628b27d27deb825
6
+ metadata.gz: 1b47bef62063b2871cd0c6235fe38e76b892b9c4b888d0b9798ccf39a6cc7daa2f4539b6a4fa1829635e5970401a59b822bcd1d1f72bfb71b9d3c79781ecf1ae
7
+ data.tar.gz: 476a21e271c981101b51cd0fe32ce6182635994273895de8f57c26224f9f4e4fd883a1a40139fa95c9672a2cb8dea920bce9e362e01fc0893cacfd3b28ce9625
@@ -0,0 +1,16 @@
1
+ name: Rubocop
2
+
3
+ # Run this workflow every time a new commit pushed to your repository
4
+ on: push
5
+
6
+ jobs:
7
+
8
+ rubocop:
9
+ name: Rubocopchecks
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Run Rubocop
13
+ uses: gimenete/rubocop-action@1.0
14
+ env:
15
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16
+
@@ -0,0 +1,32 @@
1
+ name: Test Suite
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby-version: ['3.0', 2.7, 2.5]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby ${{ matrix.ruby-version }}
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby-version }}
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Init submodules
22
+ run: git submodule update --init --recursive
23
+ - name: Build C library
24
+ run: bin/setup
25
+ - name: Test C library
26
+ run: cd ext/argon2_wrap/ && make test && cd ../..
27
+ - name: Run tests
28
+ run: bundle exec rake
29
+ - name: Coveralls
30
+ uses: coverallsapp/github-action@master
31
+ with:
32
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -1,20 +1,26 @@
1
-
2
1
  Metrics/AbcSize:
3
2
  Max: 20
3
+
4
4
  Metrics/CyclomaticComplexity:
5
5
  Enabled: false
6
+
6
7
  Metrics/PerceivedComplexity:
7
8
  Enabled: false
8
- Metrics/LineLength:
9
+
10
+ Layout/LineLength:
9
11
  Max: 160
12
+ Exclude:
13
+ - 'test/low_level_test.rb'
10
14
 
11
15
  Metrics/MethodLength:
12
16
  Max: 24
17
+ Exclude:
18
+ - 'test/low_level_test.rb'
13
19
 
14
- Layout/AlignParameters:
20
+ Layout/ParameterAlignment:
15
21
  Enabled: false
16
22
 
17
- Layout/AlignArray:
23
+ Layout/ArrayAlignment:
18
24
  Enabled: false
19
25
 
20
26
  # Configuration parameters: Exclude.
@@ -37,7 +43,7 @@ Style/HashSyntax:
37
43
 
38
44
  # Offense count: 1
39
45
  # Cop supports --auto-correct.
40
- Layout/IndentArray:
46
+ Layout/FirstArrayElementIndentation:
41
47
  Exclude:
42
48
  - 'lib/argon2/errors.rb'
43
49
 
@@ -61,3 +67,142 @@ Layout/MultilineMethodCallBraceLayout:
61
67
  - 'lib/argon2.rb'
62
68
  - 'test/low_level_test.rb'
63
69
 
70
+ Gemspec/RequiredRubyVersion:
71
+ Enabled: false
72
+
73
+ Layout/BeginEndAlignment: # (new in 0.91)
74
+ Enabled: true
75
+ Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
76
+ Enabled: true
77
+ Layout/SpaceAroundMethodCallOperator: # (new in 0.82)
78
+ Enabled: true
79
+ Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
80
+ Enabled: true
81
+ Lint/ConstantDefinitionInBlock: # (new in 0.91)
82
+ Enabled: true
83
+ Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
84
+ Enabled: true
85
+ Lint/DuplicateElsifCondition: # (new in 0.88)
86
+ Enabled: true
87
+ Lint/DuplicateRequire: # (new in 0.90)
88
+ Enabled: true
89
+ Lint/DuplicateRescueException: # (new in 0.89)
90
+ Enabled: true
91
+ Lint/EmptyConditionalBody: # (new in 0.89)
92
+ Enabled: true
93
+ Lint/EmptyFile: # (new in 0.90)
94
+ Enabled: true
95
+ Lint/FloatComparison: # (new in 0.89)
96
+ Enabled: true
97
+ Lint/IdentityComparison: # (new in 0.91)
98
+ Enabled: true
99
+ Lint/MissingSuper: # (new in 0.89)
100
+ Enabled: true
101
+ Lint/MixedRegexpCaptureTypes: # (new in 0.85)
102
+ Enabled: true
103
+ Lint/OutOfRangeRegexpRef: # (new in 0.89)
104
+ Enabled: true
105
+ Lint/RaiseException: # (new in 0.81)
106
+ Enabled: true
107
+ Lint/SelfAssignment: # (new in 0.89)
108
+ Enabled: true
109
+ Lint/StructNewOverride: # (new in 0.81)
110
+ Enabled: true
111
+ Lint/TopLevelReturnWithArgument: # (new in 0.89)
112
+ Enabled: true
113
+ Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
114
+ Enabled: true
115
+ Lint/UnreachableLoop: # (new in 0.89)
116
+ Enabled: true
117
+ Lint/UselessMethodDefinition: # (new in 0.90)
118
+ Enabled: true
119
+ Lint/UselessTimes: # (new in 0.91)
120
+ Enabled: true
121
+ Style/AccessorGrouping: # (new in 0.87)
122
+ Enabled: true
123
+ Style/ArrayCoercion: # (new in 0.88)
124
+ Enabled: true
125
+ Style/BisectedAttrAccessor: # (new in 0.87)
126
+ Enabled: true
127
+ Style/CaseLikeIf: # (new in 0.88)
128
+ Enabled: true
129
+ Style/CombinableLoops: # (new in 0.90)
130
+ Enabled: true
131
+ Style/ExplicitBlockArgument: # (new in 0.89)
132
+ Enabled: true
133
+ Style/ExponentialNotation: # (new in 0.82)
134
+ Enabled: true
135
+ Style/GlobalStdStream: # (new in 0.89)
136
+ Enabled: true
137
+ Style/HashAsLastArrayItem: # (new in 0.88)
138
+ Enabled: true
139
+ Style/HashEachMethods: # (new in 0.80)
140
+ Enabled: true
141
+ Style/HashLikeCase: # (new in 0.88)
142
+ Enabled: true
143
+ Style/HashTransformKeys: # (new in 0.80)
144
+ Enabled: true
145
+ Style/HashTransformValues: # (new in 0.80)
146
+ Enabled: true
147
+ Style/KeywordParametersOrder: # (new in 0.90)
148
+ Enabled: true
149
+ Style/OptionalBooleanParameter: # (new in 0.89)
150
+ Enabled: true
151
+ Style/RedundantAssignment: # (new in 0.87)
152
+ Enabled: true
153
+ Style/RedundantFetchBlock: # (new in 0.86)
154
+ Enabled: true
155
+ Style/RedundantFileExtensionInRequire: # (new in 0.88)
156
+ Enabled: true
157
+ Style/RedundantRegexpCharacterClass: # (new in 0.85)
158
+ Enabled: true
159
+ Style/RedundantRegexpEscape: # (new in 0.85)
160
+ Enabled: true
161
+ Style/RedundantSelfAssignment: # (new in 0.90)
162
+ Enabled: true
163
+ Style/SingleArgumentDig: # (new in 0.89)
164
+ Enabled: true
165
+ Style/SlicingWithRange: # (new in 0.83)
166
+ Enabled: true
167
+ Style/SoleNestedConditional: # (new in 0.89)
168
+ Enabled: true
169
+ Style/StringConcatenation: # (new in 0.89)
170
+ Enabled: true
171
+
172
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
173
+ Enabled: true
174
+ Lint/AmbiguousAssignment: # (new in 1.7)
175
+ Enabled: true
176
+ Lint/DuplicateBranch: # (new in 1.3)
177
+ Enabled: true
178
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
179
+ Enabled: true
180
+ Lint/EmptyBlock: # (new in 1.1)
181
+ Enabled: true
182
+ Lint/EmptyClass: # (new in 1.3)
183
+ Enabled: true
184
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
185
+ Enabled: true
186
+ Lint/ToEnumArguments: # (new in 1.1)
187
+ Enabled: true
188
+ Lint/UnexpectedBlockArity: # (new in 1.5)
189
+ Enabled: true
190
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
191
+ Enabled: true
192
+ Style/ArgumentsForwarding: # (new in 1.1)
193
+ Enabled: true
194
+ Style/CollectionCompact: # (new in 1.2)
195
+ Enabled: true
196
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
197
+ Enabled: true
198
+ Style/HashExcept: # (new in 1.7)
199
+ Enabled: true
200
+ Style/NegatedIfElseCondition: # (new in 1.2)
201
+ Enabled: true
202
+ Style/NilLambda: # (new in 1.3)
203
+ Enabled: true
204
+ Style/RedundantArgument: # (new in 1.4)
205
+ Enabled: true
206
+ Style/SwapValues: # (new in 1.1)
207
+ Enabled: true
208
+
@@ -1,3 +1,6 @@
1
+ ## v2.0.3: 2021-01-02
2
+ - Address potential memory leak. Unlikely to be exploitable.
3
+
1
4
  ## v2.0.0: 2019-01-06
2
5
  - Defaults to Argon2id for new hashes
3
6
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in argon2.gemspec
data/README.md CHANGED
@@ -2,21 +2,20 @@
2
2
 
3
3
  This Ruby Gem provides FFI bindings, and a simplified interface, to the Argon2 algorithm. [Argon2](https://github.com/P-H-C/phc-winner-argon2) is the official winner of the Password Hashing Competition, a several year project to identify a successor to bcrypt/PBKDF/scrypt methods of securely storing passwords. This is an independant project and not official from the PHC team.
4
4
 
5
-
6
- [![Build Status](https://travis-ci.org/technion/ruby-argon2.svg?branch=master)](https://travis-ci.org/technion/ruby-argon2)
5
+ ![Build Status](https://github.com/technion/ruby-argon2/workflows/Test%20Suite/badge.svg)
7
6
  [![Code Climate](https://codeclimate.com/github/technion/ruby-argon2/badges/gpa.svg)](https://codeclimate.com/github/technion/ruby-argon2)
8
7
  [![Coverage Status](https://coveralls.io/repos/github/technion/ruby-argon2/badge.svg)](https://coveralls.io/github/technion/ruby-argon2)
9
8
 
10
9
  ## Design
11
10
 
12
- This project has several key tenants to its design:
11
+ This project has several key tenets to its design:
13
12
 
14
13
  * The reference Argon2 implementation is to be used "unaltered". To ensure compliance with this goal, and encourage regular updates from upstream, the upstream library is implemented as a git submodule, and is intended to stay that way.
15
14
  * The FFI interface is kept as slim as possible, with wrapper classes preferred to implementing context structs in FFI
16
15
  * Security and maintainability take top priority. This can have an impact on platform support. A PR that contains platform specific code paths is unlikely to be accepted.
17
16
  * Tested platforms are MRI Ruby 2.2, 2.3 and JRuby 9000. No assertions are made on other platforms.
18
17
  * Errors from the C interface are raised as Exceptions. There are a lot of exception classes, but they tend to relate to things like very broken input, and code bugs. Calls to this library should generally not require a rescue.
19
- * Test suits should aim for 100% code coverage.
18
+ * Test suites should aim for 100% code coverage.
20
19
  * Default work values should not be considered constants. I will increase them from time to time.
21
20
  * Not exposing the threads parameter is a design choice. I believe there is significant risk, and minimal gain in using a value other than '1'. Four threads on a four core box completely ties up the entire server to process one user logon. If you want more security, increase m_cost.
22
21
  * Many Rubocop errors have been disabled, but any commit should avoid new alerts or demonstrate their necessity.
@@ -45,7 +44,7 @@ hasher.create("password")
45
44
  ```
46
45
 
47
46
  If you follow this pattern, it is important to create a new `Argon2::Password` every time you generate a hash, in order to ensure a unique salt. See [issue 23](https://github.com/technion/ruby-argon2/issues/23) for more information.
48
- Alternatively, use this shotcut:
47
+ Alternatively, use this shortcut:
49
48
 
50
49
  ```ruby
51
50
  Argon2::Password.create("password")
@@ -81,7 +80,7 @@ Version 1.0.0 included a major version bump over 0.1.4 due to several breaking c
81
80
 
82
81
  The second of these is that the reference Argon2 implementation introduced an algorithm change, which produces a hash which is not backwards compatible. This is documented on [this PR on the C library](https://github.com/P-H-C/phc-winner-argon2/pull/115). This was a regrettable requirement to address a security concern in the algorithm itself. The two versions of the Argon2 algorithm are numbered 1.0 and 1.3 respectively.
83
82
 
84
- Shortly after this, version 1.0.0 of this gem was released with this breaking change, supporting only Argon2 v1.3. Further time later, the official encoding format was updated, with a spec that included the version number, and the library introduced backward compatibility. This should remove the likelyhood of such breaking changes in future. Version 1.1.0 will silently introduce the current version number in hashes, in order to avoid a further compatibility break.
83
+ Shortly after this, version 1.0.0 of this gem was released with this breaking change, supporting only Argon2 v1.3. Further time later, the official encoding format was updated, with a spec that included the version number, and the library introduced backward compatibility. This should remove the likelihood of such breaking changes in future. Version 1.1.0 will silently introduce the current version number in hashes, in order to avoid a further compatibility break.
85
84
 
86
85
 
87
86
  ## Platform Issues
@@ -92,6 +91,8 @@ Windows is not. Nobody anywhere has the resources to support Ruby FFI code on Wi
92
91
 
93
92
  grsec introduces certain challenges. Please see [documentation here](https://github.com/technion/ruby-argon2/issues/15).
94
93
 
94
+ See the .travis.yml file to see currently tested and supported Ruby versions.
95
+
95
96
  ## RubyDocs documentation
96
97
 
97
98
  [The usual URL](http://www.rubydoc.info/gems/argon2) will provide detailed documentation.
@@ -109,7 +110,7 @@ Although the low level C contains support for "secure memory wipe", any code hit
109
110
 
110
111
  ### Work maximums may be tighter than reference
111
112
 
112
- The reference implementation is aimed to provide secure hashing for many years. This implementation doesn't want you to DoS yourself in the meantime. Accordingly, some limits artificial limits exist on work powers. This gem can be much more agile in raising these as technology progresses.
113
+ The reference implementation is aimed to provide secure hashing for many years. This implementation doesn't want you to DoS yourself in the meantime. Accordingly, some artificial limits exist on work powers. This gem can be much more agile in raising these as technology progresses.
113
114
 
114
115
  ### Salts in general
115
116
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
  require 'rubocop/rake_task'
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
 
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'argon2/version'
@@ -20,13 +22,14 @@ Gem::Specification.new do |spec|
20
22
  spec.bindir = "exe"
21
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
24
  spec.require_paths = ["lib"]
23
- spec.add_dependency 'ffi', '~> 1.9'
24
- spec.add_dependency 'ffi-compiler', '>= 0.1'
25
+ spec.add_dependency 'ffi', '~> 1.14'
26
+ spec.add_dependency 'ffi-compiler', '~> 1.0'
25
27
 
26
28
  spec.add_development_dependency "bundler", '~> 2.0'
27
- spec.add_development_dependency "coveralls", '~> 0.8'
28
29
  spec.add_development_dependency "minitest", '~> 5.8'
29
- spec.add_development_dependency "rake", '~> 10.4', '>= 10.4.2'
30
- spec.add_development_dependency "rubocop", '~> 0.49'
30
+ spec.add_development_dependency "rake", '~> 13.0.1'
31
+ spec.add_development_dependency "rubocop", '~> 1.7'
32
+ spec.add_development_dependency "simplecov", '~> 0.20'
33
+ spec.add_development_dependency "simplecov-lcov", '~> 0.8'
31
34
  spec.extensions << 'ext/argon2_wrap/extconf.rb'
32
35
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "argon2"
@@ -130,6 +130,8 @@ int wrap_argon2_verify(const char *encoded, const char *pwd,
130
130
  type = Argon2_d;
131
131
  } else {
132
132
  // Other types not yet supported
133
+ free(ctx.salt);
134
+ free(ctx.out);
133
135
  return ARGON2_DECODING_FAIL;
134
136
  }
135
137
 
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  #I must admit I have no understanding of why this empty file works.
@@ -2,6 +2,7 @@ argon2
2
2
  libargon2.a
3
3
  libargon2.so*
4
4
  libargon2.dylib
5
+ libargon2.pc
5
6
  .DS_Store
6
7
  src/*.o
7
8
  src/blake2/*.o
@@ -1,8 +1,6 @@
1
1
  
2
- Microsoft Visual Studio Solution File, Format Version 12.00
3
- # Visual Studio 14
4
- VisualStudioVersion = 14.0.25420.1
5
- MinimumVisualStudioVersion = 10.0.40219.1
2
+ Microsoft Visual Studio Solution File, Format Version 11.00
3
+ # Visual Studio 2010
6
4
  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Argon2OptTestCI", "vs2015\Argon2OptTestCI\Argon2OptTestCI.vcxproj", "{12956597-5E42-433A-93F3-D4EFF50AA207}"
7
5
  EndProject
8
6
  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Argon2RefTestCI", "vs2015\Argon2RefTestCI\Argon2RefTestCI.vcxproj", "{8A1F7F84-34AF-4DB2-9D58-D4823DFE79E9}"
@@ -7,8 +7,8 @@ You may use this work under the terms of a Creative Commons CC0 1.0
7
7
  License/Waiver or the Apache Public License 2.0, at your option. The terms of
8
8
  these licenses can be found at:
9
9
 
10
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
11
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
10
+ - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
11
+ - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
12
12
 
13
13
  The terms of the licenses are reproduced below.
14
14
 
@@ -8,8 +8,8 @@
8
8
  # License/Waiver or the Apache Public License 2.0, at your option. The terms of
9
9
  # these licenses can be found at:
10
10
  #
11
- # - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12
- # - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
+ # - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
12
+ # - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
13
13
  #
14
14
  # You should have received a copy of both of these licenses along with this
15
15
  # software. If not, they may be obtained at the above URLs.
@@ -18,6 +18,13 @@
18
18
  RUN = argon2
19
19
  BENCH = bench
20
20
  GENKAT = genkat
21
+ ARGON2_VERSION ?= ZERO
22
+
23
+ # installation parameters for staging area and final installation path
24
+ # Note; if Linux and not Debian/Ubuntu version also add lib override to make command-line
25
+ # for RedHat/Fedora, add: LIBRARY_REL=lib64
26
+ DESTDIR ?=
27
+ PREFIX ?= /usr
21
28
 
22
29
  # Increment on an ABI breaking change
23
30
  ABI_VERSION = 1
@@ -56,40 +63,51 @@ endif
56
63
 
57
64
  BUILD_PATH := $(shell pwd)
58
65
  KERNEL_NAME := $(shell uname -s)
66
+ MACHINE_NAME := $(shell uname -m)
67
+
68
+ LIB_NAME = argon2
69
+ PC_NAME = lib$(LIB_NAME).pc
70
+ PC_SRC = $(PC_NAME).in
59
71
 
60
- LIB_NAME=argon2
61
72
  ifeq ($(KERNEL_NAME), Linux)
62
73
  LIB_EXT := so.$(ABI_VERSION)
63
74
  LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
64
75
  SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
65
76
  LINKED_LIB_EXT := so
77
+ PC_EXTRA_LIBS ?= -lrt -ldl
66
78
  endif
67
- ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),FreeBSD NetBSD OpenBSD))
79
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD NetBSD OpenBSD))
68
80
  LIB_EXT := so
69
81
  LIB_CFLAGS := -shared -fPIC
82
+ PC_EXTRA_LIBS ?=
70
83
  endif
71
84
  ifeq ($(KERNEL_NAME), Darwin)
72
85
  LIB_EXT := $(ABI_VERSION).dylib
73
86
  LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
74
87
  LINKED_LIB_EXT := dylib
88
+ PC_EXTRA_LIBS ?=
75
89
  endif
76
90
  ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN)
77
91
  LIB_EXT := dll
78
92
  LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
93
+ PC_EXTRA_LIBS ?=
79
94
  endif
80
95
  ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
81
96
  LIB_EXT := dll
82
97
  LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
98
+ PC_EXTRA_LIBS ?=
83
99
  endif
84
100
  ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
85
101
  LIB_EXT := dll
86
102
  LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
103
+ PC_EXTRA_LIBS ?=
87
104
  endif
88
105
  ifeq ($(KERNEL_NAME), SunOS)
89
106
  CC := gcc
90
107
  CFLAGS += -D_REENTRANT
91
108
  LIB_EXT := so
92
109
  LIB_CFLAGS := -shared -fPIC
110
+ PC_EXTRA_LIBS ?=
93
111
  endif
94
112
 
95
113
  ifeq ($(KERNEL_NAME), Linux)
@@ -105,26 +123,53 @@ ifdef LINKED_LIB_EXT
105
123
  LINKED_LIB_SH := lib$(LIB_NAME).$(LINKED_LIB_EXT)
106
124
  endif
107
125
 
126
+ # Some systems don't provide an unprefixed ar when cross-compiling.
127
+ AR=ar
108
128
 
109
129
  LIBRARIES = $(LIB_SH) $(LIB_ST)
110
130
  HEADERS = include/argon2.h
111
131
 
112
132
  INSTALL = install
113
133
 
114
- DESTDIR =
115
- PREFIX = /usr
116
- INCLUDE_REL = include
117
- LIBRARY_REL = lib
118
- BINARY_REL = bin
134
+ # relative paths for different OS
135
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD))
136
+
137
+ # default for FreeBSD
138
+ BINARY_REL ?= bin
139
+ INCLUDE_REL ?= include
140
+ LIBRARY_REL ?= lib
141
+ PKGCONFIG_REL ?= libdata
142
+
143
+ else ifeq ($(KERNEL_NAME)-$(MACHINE_NAME), Linux-x86_64)
144
+
145
+ # default for Debian/Ubuntu x86_64
146
+ BINARY_REL ?= bin
147
+ INCLUDE_REL ?= include
148
+ LIBRARY_REL ?= lib/x86_64-linux-gnu
149
+ PKGCONFIG_REL ?= $(LIBRARY_REL)
150
+
151
+ else
152
+
153
+ # NetBSD, ... and Linux64/Linux32 variants that use plain lib directory
154
+ BINARY_REL ?= bin
155
+ INCLUDE_REL ?= include
156
+ LIBRARY_REL ?= lib
157
+ PKGCONFIG_REL ?= $(LIBRARY_REL)
158
+
159
+ endif
119
160
 
161
+ # absolute paths to staging area
120
162
  INST_INCLUDE = $(DESTDIR)$(PREFIX)/$(INCLUDE_REL)
121
163
  INST_LIBRARY = $(DESTDIR)$(PREFIX)/$(LIBRARY_REL)
122
164
  INST_BINARY = $(DESTDIR)$(PREFIX)/$(BINARY_REL)
165
+ INST_PKGCONFIG = $(DESTDIR)$(PREFIX)/$(PKGCONFIG_REL)/pkgconfig
123
166
 
124
- .PHONY: clean dist format $(GENKAT) all install
125
-
167
+ # main target
168
+ .PHONY: all
126
169
  all: $(RUN) libs
127
- libs: $(LIBRARIES)
170
+
171
+ .PHONY: libs
172
+ libs: $(LIBRARIES) $(PC_NAME)
128
173
 
129
174
  $(RUN): $(SRC) $(SRC_RUN)
130
175
  $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
@@ -139,49 +184,72 @@ $(LIB_SH): $(SRC)
139
184
  $(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
140
185
 
141
186
  $(LIB_ST): $(OBJ)
142
- ar rcs $@ $^
187
+ $(AR) rcs $@ $^
143
188
 
189
+ .PHONY: clean
144
190
  clean:
145
- rm -f $(RUN) $(BENCH) $(GENKAT)
146
- rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
191
+ rm -f '$(RUN)' '$(BENCH)' '$(GENKAT)'
192
+ rm -f '$(LIB_SH)' '$(LIB_ST)' kat-argon2* '$(PC_NAME)'
147
193
  rm -f testcase
148
194
  rm -rf *.dSYM
149
195
  cd src/ && rm -f *.o
150
196
  cd src/blake2/ && rm -f *.o
151
197
  cd kats/ && rm -f kat-* diff* run_* make_*
152
198
 
199
+
200
+ # all substitutions to pc template
201
+ SED_COMMANDS = /^\#\#.*$$/d;
202
+ SED_COMMANDS += s\#@PREFIX@\#$(PREFIX)\#g;
203
+ SED_COMMANDS += s\#@EXTRA_LIBS@\#$(PC_EXTRA_LIBS)\#g;
204
+ SED_COMMANDS += s\#@UPSTREAM_VER@\#$(ARGON2_VERSION)\#g;
205
+ SED_COMMANDS += s\#@HOST_MULTIARCH@\#$(LIBRARY_REL)\#g;
206
+ SED_COMMANDS += s\#@INCLUDE@\#$(INCLUDE_REL)\#g;
207
+
208
+ # substitute PREFIX and PC_EXTRA_LIBS into pkgconfig pc file
209
+ $(PC_NAME): $(PC_SRC)
210
+ sed '$(SED_COMMANDS)' < '$(PC_SRC)' > '$@'
211
+
212
+
213
+ .PHONY: dist
153
214
  dist:
154
215
  cd ..; \
155
216
  tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
156
217
 
218
+ .PHONY: test
157
219
  test: $(SRC) src/test.c
158
220
  $(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
159
221
  @sh kats/test.sh
160
222
  ./testcase
161
223
 
224
+ .PHONY: testci
162
225
  testci: $(SRC) src/test.c
163
226
  $(CC) $(CI_CFLAGS) $^ -o testcase
164
227
  @sh kats/test.sh
165
228
  ./testcase
166
229
 
167
- .PHONY: test
168
230
 
231
+ .PHONY: format
169
232
  format:
170
233
  clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
171
234
  -i include/*.h src/*.c src/*.h src/blake2/*.c src/blake2/*.h
172
235
 
236
+ .PHONY: install
173
237
  install: $(RUN) libs
174
238
  $(INSTALL) -d $(INST_INCLUDE)
175
239
  $(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE)
176
240
  $(INSTALL) -d $(INST_LIBRARY)
177
- $(INSTALL) $(LIBRARIES) $(INST_LIBRARY)
241
+ $(INSTALL) -m 0644 $(LIBRARIES) $(INST_LIBRARY)
178
242
  ifdef LINKED_LIB_SH
179
- cd $(INST_LIBRARY) && ln -s $(notdir $(LIB_SH) $(LINKED_LIB_SH))
243
+ cd $(INST_LIBRARY) && ln -sf $(notdir $(LIB_SH) $(LINKED_LIB_SH))
180
244
  endif
181
245
  $(INSTALL) -d $(INST_BINARY)
182
246
  $(INSTALL) $(RUN) $(INST_BINARY)
247
+ $(INSTALL) -d $(INST_PKGCONFIG)
248
+ $(INSTALL) -m 0644 $(PC_NAME) $(INST_PKGCONFIG)
183
249
 
250
+ .PHONY: uninstall
184
251
  uninstall:
185
252
  cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS))
186
253
  cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH))
187
254
  cd $(INST_BINARY) && rm -f $(notdir $(RUN))
255
+ cd $(INST_PKG_CONFIG) && rm -f $(notdir $(PC_NAME))