argon2 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -9
  3. data/.travis.yml +0 -1
  4. data/CONTRIBUTING.md +12 -0
  5. data/Changelog.md +10 -11
  6. data/README.md +23 -14
  7. data/ext/argon2_wrap/Makefile +8 -6
  8. data/ext/argon2_wrap/argon_wrap.c +23 -12
  9. data/ext/argon2_wrap/test.c +14 -42
  10. data/ext/phc-winner-argon2/.gitignore +5 -1
  11. data/ext/phc-winner-argon2/.travis.yml +14 -0
  12. data/ext/phc-winner-argon2/Makefile +33 -12
  13. data/ext/phc-winner-argon2/README.md +48 -19
  14. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  15. data/ext/phc-winner-argon2/{src → include}/argon2.h +137 -137
  16. data/ext/phc-winner-argon2/kats/argon2d +12290 -12290
  17. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -1
  18. data/ext/phc-winner-argon2/kats/argon2i +12290 -12290
  19. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -1
  20. data/ext/phc-winner-argon2/opt.o +0 -0
  21. data/ext/phc-winner-argon2/src/argon2.c +125 -145
  22. data/ext/phc-winner-argon2/src/bench.c +5 -5
  23. data/ext/phc-winner-argon2/src/core.c +15 -20
  24. data/ext/phc-winner-argon2/src/core.h +5 -2
  25. data/ext/phc-winner-argon2/src/encoding.c +45 -72
  26. data/ext/phc-winner-argon2/src/encoding.h +24 -0
  27. data/ext/phc-winner-argon2/src/genkat.c +2 -2
  28. data/ext/phc-winner-argon2/src/opt.c +19 -10
  29. data/ext/phc-winner-argon2/src/opt.h +5 -17
  30. data/ext/phc-winner-argon2/src/ref.c +12 -9
  31. data/ext/phc-winner-argon2/src/ref.h +4 -12
  32. data/ext/phc-winner-argon2/src/run.c +67 -42
  33. data/ext/phc-winner-argon2/src/test.c +131 -0
  34. data/lib/argon2.rb +6 -5
  35. data/lib/argon2/constants.rb +3 -2
  36. data/lib/argon2/engine.rb +1 -0
  37. data/lib/argon2/errors.rb +37 -36
  38. data/lib/argon2/ffi_engine.rb +10 -10
  39. data/lib/argon2/version.rb +2 -1
  40. metadata +7 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4946951c753bf3429884bd17d5ab2f20a5b03ed
4
- data.tar.gz: d03d063894871e688f6ec7550799760e81b79200
3
+ metadata.gz: 1ce063f0a857005f2e3c1e33d0313cf6c2dbe7a4
4
+ data.tar.gz: c080ce2b9067066a59dac49655d6e43582efcc1d
5
5
  SHA512:
6
- metadata.gz: 635d587da7ae973027dac2527cc447cb12e320fe8fb11d9b58c43c59edf758a19ee74dd51e1fd481f696d71ea2b02f3d1f7b624da3b513cc20446226ea5d3112
7
- data.tar.gz: 886f3914110033c14cc0d7ce17c3bffba83e1f58620771e3eb9e1e9d7498d350d5a2bcf847e3aa3849dbceaa1d8c141472575167e573e44c3a6aaf2ee79faf6a
6
+ metadata.gz: 7742082e8db62329c94941512676a40536145ce52b7e2b4d3ba9f7a2cd25fe06eadb35811bb2eb9493aae67f4ae4f663a49f1158fdbea42f34ad7420d9b94321
7
+ data.tar.gz: b2ef7db8cbcbd54f411481995fb53ba76c15810b3c816cae5dfd664ab832279609f2a194951d5c882ab8b2a44755a63bc14b902e1c6b6f20d77dcb6d87c4490a
@@ -1,11 +1,14 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config`
2
+ #. `rubocop --auto-gen-config`
3
3
  Metrics/AbcSize:
4
- Max: 16
4
+ Max: 18
5
5
  Metrics/CyclomaticComplexity:
6
6
  Enabled: false
7
7
  Metrics/PerceivedComplexity:
8
8
  Enabled: false
9
+ Style/MutableConstant:
10
+ Exclude:
11
+ - 'test/key_test.rb'
9
12
 
10
13
  Metrics/LineLength:
11
14
  Max: 160
@@ -48,13 +51,6 @@ Style/IndentArray:
48
51
  Style/LeadingCommentSpace:
49
52
  Exclude:
50
53
  - 'ext/argon2_wrap/extconf.rb'
51
- - 'lib/argon2.rb'
52
- - 'lib/argon2/constants.rb'
53
- - 'lib/argon2/ffi_engine.rb'
54
- - 'test/api_test.rb'
55
- - 'test/low_level_test.rb'
56
- - 'test/util.rb'
57
- - 'test/util_lib.rb'
58
54
 
59
55
  Style/SignalException:
60
56
  Enabled: false
@@ -8,4 +8,3 @@ install: bin/setup
8
8
  script:
9
9
  - cd ext/argon2_wrap/ && make test && cd ../..
10
10
  - CODECLIMATE_REPO_TOKEN=28e3d5d04f4ec87d0899784e6aecc13d7787343b2634b3c94fc1216993d443c2 rake test
11
- - rake rubocop
@@ -0,0 +1,12 @@
1
+ # Contribution Guidelines
2
+
3
+ Any form of contribution is accepted, however, please note the following.
4
+
5
+ ## Please note noncompliant issues or PRs will be closed without discussion
6
+
7
+ - Note the [Design Goals](https://github.com/technion/ruby-argon2/blob/master/README.md#design) documented for the project and work within them
8
+ - Commits should be squashed to a single commit per pull. An exception is that a test suite add or change, followed by code update, may be presented as two commits in one pull
9
+ - Each individual commit should have a descriptive commit message. "Update <file>" is not suitable
10
+ - This is a coding project. Your political goals are not relevant
11
+ - Any complex or large code will probably require a test
12
+ - If an issue is felt to be a security concern, please contact me privately on: technion@lolware.net
@@ -1,17 +1,16 @@
1
- v0.1.0: 2015-11-10
2
- - Initial release
1
+ ## v1.0.0: 2015-03-07
2
+ - API change - 'new' becomes 'create'
3
+ - Version 1.3 of the Argon2 algorithm pulled in
3
4
 
4
- v0.1.1: 2015-11-26
5
- - Use $CC instead of hardcoded gcc. Allows builds on more systems.
5
+ ## v0.1.3: 2015-11-30
6
+ - Fix bug on verifying binary password
6
7
 
7
- v0.1.2: 2015-11-30
8
+ ## v0.1.2: 2015-11-30
8
9
  - Introduce handling of binary input, including NULL containing UTF-16
9
10
  - Implement property testing variable TEST_CHECKS
10
11
 
11
- v0.1.3: 2015-11-30
12
- - Fix bug on verifying binary password
13
-
14
- v0.1.4: 2016-01-11
15
- - Improved OSX compatibility
16
- - Fix broken m_cost check
12
+ ## v0.1.1: 2015-11-26
13
+ - Use $CC instead of hardcoded gcc. Allows builds on more systems.
17
14
 
15
+ ## v0.1.0: 2015-11-10
16
+ - Initial release
data/README.md CHANGED
@@ -2,7 +2,6 @@
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
- This project is now considered stable.
6
5
 
7
6
  [![Build Status](https://travis-ci.org/technion/ruby-argon2.svg?branch=master)](https://travis-ci.org/technion/ruby-argon2)
8
7
  [![Code Climate](https://codeclimate.com/github/technion/ruby-argon2/badges/gpa.svg)](https://codeclimate.com/github/technion/ruby-argon2)
@@ -15,7 +14,7 @@ This project has several key tenants to its design:
15
14
  * The reference Argon2 implementation is to be used "unaltered". To ensure compliance wit this goal, and encourage regular updates from upstream, this is implemented as a git submodule, and is intended to stay that way.
16
15
  * The FFI interface is kept as slim as possible, with wrapper classes preferred to implementing context structs in FFI
17
16
  * 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.
18
- * Tested platforms are MRI Ruby 2.2 and JRuby 9000. No assertions are made on other platforms.
17
+ * Tested platforms are MRI Ruby 2.2, 2.3 and JRuby 9000. No assertions are made on other platforms.
19
18
  * 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.
20
19
  * Test suits should aim for 100% code coverage.
21
20
  * Default work values should not be considered constants. I will increase them from time to time.
@@ -34,22 +33,22 @@ To generate a hash using specific time and memory cost:
34
33
 
35
34
  ```ruby
36
35
  hasher = Argon2::Password.new(t_cost: 2, m_cost: 16)
37
- hasher.hash("password")
38
- => "$argon2i$m=65536,t=2,p=1$mLa9JT3Y9P2XhB5Mtuj+yQ$rojObVNKe/ehgd9SWQBB+8nJ8L34Aj3Kiz+aNrWvrx4"
36
+ hasher.create("password")
37
+ => "$argon2i$m=65536,t=2,p=1$6ua7khmHLZwIHnjV2A6nSw$Kak8CTBN/yUYAESSxJKO/jfWH+40c0JQtc7EXhLm0SU"
39
38
  ```
40
39
 
41
40
  To utilise default costs:
42
41
 
43
42
  ```ruby
44
43
  hasher = Argon2::Password.new
45
- hasher.hash("password")
44
+ hasher.create("password")
46
45
  ```
47
46
 
48
47
  Alternatively, use this shotcut:
49
48
 
50
49
  ```ruby
51
- Argon2::Password.hash("password")
52
- => "$argon2i$m=65536,t=2,p=1$AZwVlHIbgRC7yQhkPKa4tA$F5eM2Zzt4GhIVnR8SNOh3ysyMvGxAO6omsw8kzjbcs4"
50
+ Argon2::Password.create("password")
51
+ => "$argon2i$m=65536,t=2,p=1$VYXqHZe+5OpNzhbU0LvMZA$XGmkk9tzjYtjatmS5VvuovLvUCfijevwgDzvIkOF+bs"
53
52
  ```
54
53
 
55
54
  You can then use this function to verify a password against a given hash. Will return either true or false.
@@ -63,13 +62,22 @@ Argon2 supports an optional key value. This should be stored securely on your se
63
62
  ```ruby
64
63
  KEY = "A key"
65
64
  argon = Argon2::Password.new(t_cost: 2, m_cost: 16, secret: KEY)
66
- myhash = argon.hash("A password")
65
+ myhash = argon.create("A password")
67
66
  Argon2::Password.verify_password("A password", myhash, KEY)
68
67
  ```
69
68
 
70
- ## OSX 'El Capitan' Issues
69
+ ## Important notes regarding version 1.0 upgrade
70
+ Version 1.0.0 included a major version bump over 0.1.4 due to several breaking changes. The first of these was an API change, which you can read the background on [here](https://github.com/technion/ruby-argon2/issues/9).
71
71
 
72
- The default installation workflow has caused issues with a number of gems under this update. There is some excellent documentation on the issue and some workarounds in the [Jekyll Documentation](http://jekyllrb.com/docs/troubleshooting/#jekyll-amp-mac-os-x-1011).
72
+ 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.
73
+
74
+ As the crypt format did not change, there is no simple way to identify an original, or improved hash. To support existing users, I'll be maintaining the 0.1.x branch with patches and bugfixes for the immediate future.
75
+
76
+ ## Platform Issues
77
+
78
+ The default installation workflow has caused issues with a number of gems under the latest OSX. There is some excellent documentation on the issue and some workarounds in the [Jekyll Documentation](http://jekyllrb.com/docs/troubleshooting/#jekyll-amp-mac-os-x-1011). With this in mind, OSX is a fully supported OS.
79
+
80
+ Windows is not. Nobody anywhere has the resources to support Ruby FFI code on Windows.
73
81
 
74
82
  ## RubyDocs documentation
75
83
 
@@ -78,9 +86,11 @@ The default installation workflow has caused issues with a number of gems under
78
86
  ## FAQ
79
87
  ### Don't roll your own crypto!
80
88
 
81
- This gets its own section because someone will raise it. I did not invent or alter this algorithm, or implement it directly.
89
+ This gets its own section because someone will raise it. I did not invent or alter this algorithm, or implement it directly. These bindings were written following [considerable involvement with the C reference](https://github.com/P-H-C/phc-winner-argon2/commits/master?author=technion), and a strong focus has been made on following the intent of the algorithm.
90
+
91
+ It is strongly advised to avoid implementations that utilise off-spec methods of introducing salts, invent imaginary parameters, or which use the word "encryption" in describing the password hashing process
82
92
 
83
- ### "Secure wipe is useless"
93
+ ### Secure wipe is useless
84
94
 
85
95
  Although the low level C contains support for "secure memory wipe", any code hitting that layer has copied your password to a dozen places in memory. It should be assumed that such functionality does not exist.
86
96
 
@@ -94,9 +104,8 @@ If you are providing your own salt, you are probably using it wrong. The design
94
104
 
95
105
  ## Contributing
96
106
 
97
- Any form of contribution is appreciated, however, please note the design goals above and work within them.
107
+ Any form of contribution is appreciated, however, please review [CONTRIBUTING.md](CONTRIBUTING.md).
98
108
 
99
- If an issue is felt to be a security concern, please contact me privately on: technion@lolware.net. If required, you may encrypt with [my GPG key](https://lolware.net/technion-GPG-KEY).
100
109
 
101
110
  ## Building locally/Tests
102
111
 
@@ -12,16 +12,18 @@ DIST_SRC = ../phc-winner-argon2/src
12
12
  SRC = $(DIST_SRC)/argon2.c $(DIST_SRC)/core.c $(DIST_SRC)/blake2/blake2b.c $(DIST_SRC)/thread.c $(DIST_SRC)/encoding.c argon_wrap.c
13
13
  OBJ = $(SRC:.c=.o)
14
14
 
15
- CFLAGS = -std=c89 -pthread -O3 -Wall -g
15
+ CFLAGS = -pthread -O3 -Wall -g -I../phc-winner-argon2/include -I../phc-winner-argon2/src
16
16
 
17
- OPT=TRUE
18
- ifeq ($(OPT), TRUE)
17
+ OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=native src/opt.c -c 2>/dev/null; echo $$?)
18
+ # Detect compatible platform
19
+ ifneq ($(OPTTEST), 0)
20
+ SRC += $(DIST_SRC)/ref.c
21
+ else
19
22
  CFLAGS += -march=native
20
23
  SRC += $(DIST_SRC)/opt.c
21
- else
22
- SRC += $(DIST_SRC)/ref.c
23
24
  endif
24
25
 
26
+
25
27
  BUILD_PATH := $(shell pwd)
26
28
  KERNEL_NAME := $(shell uname -s)
27
29
 
@@ -56,7 +58,7 @@ libs: $(SRC)
56
58
  #Deliberately avoiding the CFLAGS for our test cases - disable optimise and
57
59
  #C89
58
60
  test: $(SRC) test.c
59
- clang -pthread -O3 -fsanitize=address -fsanitize=undefined -Wall -g $^ -o tests
61
+ clang -pthread -O3 -fsanitize=address -fsanitize=undefined -Wall -g $^ -o tests $(CFLAGS)
60
62
  ./tests
61
63
 
62
64
  clean:
@@ -10,9 +10,9 @@
10
10
  #include <string.h>
11
11
  #include <time.h>
12
12
 
13
- #include "../phc-winner-argon2/src/argon2.h"
14
- #include "../phc-winner-argon2/src/core.h"
15
- #include "../phc-winner-argon2/src/encoding.h"
13
+ #include "argon2.h"
14
+ #include "core.h"
15
+ #include "encoding.h"
16
16
 
17
17
  #define T_COST_DEF 3
18
18
  #define LOG_M_COST_DEF 12 /* 2^12 = 4 MiB */
@@ -22,7 +22,16 @@
22
22
  #define SALT_LEN 16
23
23
  #define ENCODE_LEN 108
24
24
 
25
- int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len);
25
+ /* Workaround for https://github.com/technion/ruby-argon2/issues/8. Hopefully temporary */
26
+ static int wrap_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
27
+ size_t i;
28
+ uint8_t d = 0U;
29
+
30
+ for (i = 0U; i < len; i++) {
31
+ d |= b1[i] ^ b2[i];
32
+ }
33
+ return (int)((1 & ((d - 1) >> 8)) - 1);
34
+ }
26
35
 
27
36
  unsigned int argon2_wrap(char *out, const char *pwd, size_t pwd_length,
28
37
  uint8_t *salt, uint32_t t_cost, uint32_t m_cost, uint32_t lanes,
@@ -57,7 +66,7 @@ unsigned int argon2_wrap(char *out, const char *pwd, size_t pwd_length,
57
66
  context.free_cbk = NULL;
58
67
  context.flags = 0;
59
68
 
60
- int result = argon2i(&context);
69
+ int result = argon2i_ctx(&context);
61
70
  if (result != ARGON2_OK)
62
71
  return result;
63
72
 
@@ -73,11 +82,13 @@ int wrap_argon2_verify(const char *encoded, const char *pwd,
73
82
  int ret;
74
83
  char out[ENCODE_LEN];
75
84
  memset(&ctx, 0, sizeof(argon2_context));
76
-
77
- /* max values, to be updated in decode_string */
78
- ctx.adlen = 512;
79
- ctx.saltlen = 512;
80
- ctx.outlen = 512;
85
+ size_t encoded_len;
86
+
87
+ encoded_len = strlen(encoded);
88
+ /* larger than max possible values */
89
+ ctx.adlen = encoded_len;
90
+ ctx.saltlen = encoded_len;
91
+ ctx.outlen = encoded_len;
81
92
 
82
93
  ctx.ad = malloc(ctx.adlen);
83
94
  ctx.salt = malloc(ctx.saltlen);
@@ -89,7 +100,7 @@ int wrap_argon2_verify(const char *encoded, const char *pwd,
89
100
  return ARGON2_MEMORY_ALLOCATION_ERROR;
90
101
  }
91
102
 
92
- if(decode_string(&ctx, encoded, Argon2_i) != 1) {
103
+ if(decode_string(&ctx, encoded, Argon2_i) != ARGON2_OK) {
93
104
  free(ctx.ad);
94
105
  free(ctx.salt);
95
106
  free(ctx.out);
@@ -102,7 +113,7 @@ int wrap_argon2_verify(const char *encoded, const char *pwd,
102
113
  free(ctx.ad);
103
114
  free(ctx.salt);
104
115
 
105
- if (ret != ARGON2_OK || argon2_compare((uint8_t*)out, (uint8_t*)encoded,
116
+ if (ret != ARGON2_OK || wrap_compare((uint8_t*)out, (uint8_t*)encoded,
106
117
  strlen(encoded))) {
107
118
  free(ctx.out);
108
119
  return ARGON2_DECODING_FAIL;
@@ -10,7 +10,7 @@
10
10
  #include <time.h>
11
11
  #include <assert.h>
12
12
 
13
- #include "../phc-winner-argon2/src/argon2.h"
13
+ #include "argon2.h"
14
14
 
15
15
  #define OUT_LEN 32
16
16
  #define SALT_LEN 16
@@ -48,7 +48,7 @@ int wrap_argon2_verify(const char *encoded, const char *pwd,
48
48
  int main()
49
49
  {
50
50
  unsigned char out[OUT_LEN];
51
- unsigned char hex_out[OUT_LEN*2];
51
+ unsigned char hex_out[OUT_LEN*2 + 4]; /* Allow space for NULL byute */
52
52
  char out2[300];
53
53
  char *pwd = NULL;
54
54
  uint8_t salt[SALT_LEN];
@@ -58,24 +58,6 @@ int main()
58
58
  memcpy(salt, "somesalt", 8);
59
59
 
60
60
 
61
- /* ./argon2 password somesalt -t 2 -m 16
62
- * Hash: 894af4ff2e2d26f3ce15f77a7e1c25db45b4e20439e9961772ba199caddb001e
63
- * ./argon2 password somesalt -t 2 -m 20
64
- * Hash: 58d4d929aeeafa40cc049f032035784fb085e8e0d0c5a51ea067341a93d6d286
65
- * ./argon2 password somesalt -t 2 -m 18
66
- * Hash: 55292398cce8fc78685e610d004ca9bda5c325a0a2e6285a0de5f816df139aa6
67
- * ./argon2 password somesalt -t 2 -m 8
68
- * Hash: e346b1e1aa7ca58c9bb862e223ba5604064398d4394e49e90972c6b54cef43ed
69
- * ./argon2 password somesalt -t 1 -m 16
70
- * Hash: b49199e4ecb0f6659e6947f945e391c940b17106e1d0b0a9888006c7f87a789b
71
- * ./argon2 password somesalt -t 4 -m 16
72
- * Hash: 72207b3312d79995fbe7b30664837ae1246f9a98e07eac34835ca3498e705f85
73
- * ./argon2 differentpassword somesalt -t 2 -m 16 -p 1
74
- * Hash: 8e286f605ed7383987a4aac25a28a04808593b6e17613bc31457146c4f3f4361
75
- * ./argon2 password diffsalt -t 2 -m 16 -p 1
76
- * Hash: 8f65b47d902fb2aee5e0b2bdc9041b249fc11f06f35551e0bee52716b41e8311
77
- */
78
-
79
61
  #define RAWTEST(T, M, P, PWD, REF) \
80
62
  pwd = strdup(PWD); \
81
63
  assert(pwd); \
@@ -87,15 +69,14 @@ int main()
87
69
  free(pwd); \
88
70
  printf( "Ref test: %s: PASS\n", REF);
89
71
 
90
- RAWTEST(2, 16, 1, "password", "894af4ff2e2d26f3ce15f77a7e1c25db45b4e20439e9961772ba199caddb001e");
91
- RAWTEST(2, 20, 1, "password", "58d4d929aeeafa40cc049f032035784fb085e8e0d0c5a51ea067341a93d6d286");
92
- RAWTEST(2, 18, 1, "password", "55292398cce8fc78685e610d004ca9bda5c325a0a2e6285a0de5f816df139aa6");
93
- RAWTEST(2, 8, 1, "password", "e346b1e1aa7ca58c9bb862e223ba5604064398d4394e49e90972c6b54cef43ed");
94
- RAWTEST(1, 16, 1, "password", "b49199e4ecb0f6659e6947f945e391c940b17106e1d0b0a9888006c7f87a789b");
95
- RAWTEST(4, 16, 1, "password", "72207b3312d79995fbe7b30664837ae1246f9a98e07eac34835ca3498e705f85");
96
- RAWTEST(2, 16, 1, "differentpassword", "8e286f605ed7383987a4aac25a28a04808593b6e17613bc31457146c4f3f4361");
72
+ RAWTEST(2, 16, 1, "password", "1c7eeef9e0e969b3024722fc864a1ca9f6ca20da73f9bf3f1731881beae2039e");
73
+ RAWTEST(2, 18, 1, "password", "5c6dfd2712110cf88f1426059b01d87f8210d5368da0e7ee68586e9d4af4954b");
74
+ RAWTEST(2, 8, 1, "password", "dfebf9d4eadd6859f4cc6a9bb20043fd9da7e1e36bdacdbb05ca569f463269f8");
75
+ RAWTEST(1, 16, 1, "password", "fabd1ddbd86a101d326ac2abe79660202b10192925d2fd2483085df94df0c91a");
76
+ RAWTEST(4, 16, 1, "password", "b3b4cb3d6e2c1cb1e7bffdb966ab3ceafae701d6b7789c3f1e6c6b22d82d99d5");
77
+ RAWTEST(2, 16, 1, "differentpassword", "b2db9d7c0d1288951aec4b6e1cd3835ea29a7da2ac13e6f48554a26b127146f9");
97
78
  memcpy(salt, "diffsalt", 8);
98
- RAWTEST(2, 16, 1, "password", "8f65b47d902fb2aee5e0b2bdc9041b249fc11f06f35551e0bee52716b41e8311");
79
+ RAWTEST(2, 16, 1, "password", "bb6686865f2c1093f70f543c9535f807d5b42d5dc6d71f14a4a7a291913e05e0");
99
80
 
100
81
 
101
82
  #define WRAP_TEST(T, M, PWD, REF) \
@@ -106,25 +87,16 @@ int main()
106
87
  printf( "Ref test: %s: PASS\n", REF);
107
88
 
108
89
  memcpy(salt, "somesalt", 8);
109
- /* echo password | ./argon2 somesalt -t 2 -m 16
110
- * $argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$iUr0/y4tJvPOFfd6fhwl20W04gQ56ZYXcroZnK3bAB4
111
- */
112
90
  WRAP_TEST(2, 16, "password",
113
- "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$iUr0/y4tJvPOFfd6fhwl20W04gQ56ZYXcroZnK3bAB4");
91
+ "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$HH7u+eDpabMCRyL8hkocqfbKINpz+b8/FzGIG+riA54");
114
92
 
115
- /* echo password | ./argon2 somesalt -t 2 -m 8
116
- * $argon2i$m=256,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$40ax4ap8pYybuGLiI7pWBAZDmNQ5TknpCXLGtUzvQ+0
117
- */
118
93
  WRAP_TEST(2, 8, "password",
119
- "$argon2i$m=256,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$40ax4ap8pYybuGLiI7pWBAZDmNQ5TknpCXLGtUzvQ+0");
94
+ "$argon2i$m=256,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$3+v51OrdaFn0zGqbsgBD/Z2n4eNr2s27BcpWn0Yyafg");
120
95
 
121
- /* echo diffpassword | ./argon2 somesalt -t 2 -m 16
122
- * $argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$y/IeiuTydN/Sud4UzLqv6Spx8Eqree6FoP088X6WyW4
123
- */
124
- WRAP_TEST(2, 16, "diffpassword",
125
- "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$y/IeiuTydN/Sud4UzLqv6Spx8Eqree6FoP088X6WyW4");
96
+ WRAP_TEST(2, 16, "differentpassword",
97
+ "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$studfA0SiJUa7EtuHNODXqKafaKsE+b0hVSiaxJxRvk");
126
98
 
127
- ret = wrap_argon2_verify("$argon2i$m=65536,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$iUr0/y4tJvPOFfd6fhwl20W04gQ56ZYXcroZnK3bAB4", "password",
99
+ ret = wrap_argon2_verify("$argon2i$m=256,t=2,p=1$c29tZXNhbHQAAAAAAAAAAA$3+v51OrdaFn0zGqbsgBD/Z2n4eNr2s27BcpWn0Yyafg", "password",
128
100
  strlen("password"), NULL, 0);
129
101
  assert(ret == ARGON2_OK);
130
102
  printf("Verify OK test: PASS\n");
@@ -6,6 +6,10 @@ libargon2.dylib
6
6
  src/*.o
7
7
  src/blake2/*.o
8
8
  genkat
9
- test.c
10
9
  .idea
11
10
  *.pyc
11
+ testcase
12
+ *.gcda
13
+ *.gcno
14
+ *.gcov
15
+ bench
@@ -0,0 +1,14 @@
1
+ language: c
2
+
3
+ compiler:
4
+ - clang
5
+ - gcc
6
+
7
+ os:
8
+ - linux
9
+ - osx
10
+
11
+ script: make && make testci
12
+
13
+ after_success:
14
+ - bash <(curl -s https://codecov.io/bash)
@@ -19,14 +19,17 @@ SRC_BENCH = src/bench.c
19
19
  SRC_GENKAT = src/genkat.c
20
20
  OBJ = $(SRC:.c=.o)
21
21
 
22
- CFLAGS = -std=c89 -pthread -O3 -Wall -g
22
+ CFLAGS += -std=c89 -pthread -O3 -Wall -g -Iinclude -Isrc
23
+ CI_CFLAGS := $(CFLAGS) -Werror=declaration-after-statement -D_FORTIFY_SOURCE=2 \
24
+ -Wextra -Wno-type-limits -Werror -coverage
23
25
 
24
- #OPT=TRUE
25
- ifeq ($(OPT), TRUE)
26
+ OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=native src/opt.c -c 2>/dev/null; echo $$?)
27
+ # Detect compatible platform
28
+ ifneq ($(OPTTEST), 0)
29
+ SRC += src/ref.c
30
+ else
26
31
  CFLAGS += -march=native
27
32
  SRC += src/opt.c
28
- else
29
- SRC += src/ref.c
30
33
  endif
31
34
 
32
35
  BUILD_PATH := $(shell pwd)
@@ -35,7 +38,8 @@ KERNEL_NAME := $(shell uname -s)
35
38
  LIB_NAME=argon2
36
39
  ifeq ($(KERNEL_NAME), Linux)
37
40
  LIB_EXT := so
38
- LIB_CFLAGS := -shared -fPIC
41
+ LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
42
+ SO_LDFLAGS := -Wl,-soname,libargon2.so.0
39
43
  endif
40
44
  ifeq ($(KERNEL_NAME), NetBSD)
41
45
  LIB_EXT := so
@@ -54,6 +58,12 @@ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD))
54
58
  LIB_CFLAGS := -shared -fPIC
55
59
  endif
56
60
 
61
+ ifeq ($(KERNEL_NAME), Linux)
62
+ ifeq ($(CC), clang)
63
+ CI_CFLAGS += -fsanitize=address -fsanitize=undefined
64
+ endif
65
+ endif
66
+
57
67
  LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
58
68
  LIB_ST := lib$(LIB_NAME).a
59
69
 
@@ -63,16 +73,16 @@ all: clean $(RUN) libs
63
73
  libs: $(LIB_SH) $(LIB_ST)
64
74
 
65
75
  $(RUN): $(SRC) $(SRC_RUN)
66
- $(CC) $(CFLAGS) $^ -Isrc -o $@
76
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
67
77
 
68
78
  $(BENCH): $(SRC) $(SRC_BENCH)
69
- $(CC) $(CFLAGS) $^ -Isrc -o $@
79
+ $(CC) $(CFLAGS) $^ -o $@
70
80
 
71
81
  $(GENKAT): $(SRC) $(SRC_GENKAT)
72
- $(CC) $(CFLAGS) $^ -Isrc -o $@ -DGENKAT
82
+ $(CC) $(CFLAGS) $^ -o $@ -DGENKAT
73
83
 
74
84
  $(LIB_SH): $(SRC)
75
- $(CC) $(CFLAGS) $(LIB_CFLAGS) $^ -Isrc -o $@
85
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
76
86
 
77
87
  $(LIB_ST): $(OBJ)
78
88
  ar rcs $@ $^
@@ -80,6 +90,7 @@ $(LIB_ST): $(OBJ)
80
90
  clean:
81
91
  rm -f $(RUN) $(BENCH) $(GENKAT)
82
92
  rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
93
+ rm -f testcase
83
94
  rm -rf *.dSYM
84
95
  cd src/ && rm -f *.o
85
96
  cd src/blake2/ && rm -f *.o
@@ -89,8 +100,18 @@ dist:
89
100
  cd ..; \
90
101
  tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
91
102
 
92
- test:
103
+ test: $(SRC) src/test.c
104
+ $(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
93
105
  @sh kats/test.sh
106
+ ./testcase
107
+
108
+ testci: $(SRC) src/test.c
109
+ $(CC) $(CI_CFLAGS) $^ -o testcase
110
+ @sh kats/test.sh
111
+ ./testcase
112
+
113
+ .PHONY: test
94
114
 
95
115
  format:
96
- clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" -i src/*.c src/*.h src/blake2/*.c src/blake2/*.h
116
+ clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
117
+ -i include/*.h src/*.c src/*.h src/blake2/*.c src/blake2/*.h