argon2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.travis.yml +2 -0
  4. data/README.md +25 -9
  5. data/argon2.gemspec +10 -2
  6. data/bin/console +1 -1
  7. data/bin/setup +3 -0
  8. data/ext/argon2_wrap/Makefile +72 -0
  9. data/ext/argon2_wrap/argon_wrap.c +65 -0
  10. data/ext/argon2_wrap/extconf.rb +1 -0
  11. data/ext/argon2_wrap/test.c +67 -0
  12. data/ext/phc-winner-argon2/.gitignore +7 -0
  13. data/ext/phc-winner-argon2/LICENSE +31 -0
  14. data/ext/phc-winner-argon2/Makefile +102 -0
  15. data/ext/phc-winner-argon2/README.md +193 -0
  16. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  17. data/ext/phc-winner-argon2/kats/argon2d +12302 -0
  18. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  19. data/ext/phc-winner-argon2/kats/argon2i +12302 -0
  20. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  21. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  22. data/ext/phc-winner-argon2/kats/test.sh +47 -0
  23. data/ext/phc-winner-argon2/src/argon2.c +360 -0
  24. data/ext/phc-winner-argon2/src/argon2.h +298 -0
  25. data/ext/phc-winner-argon2/src/bench.c +111 -0
  26. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +143 -0
  27. data/ext/phc-winner-argon2/src/blake2/blake2.h +74 -0
  28. data/ext/phc-winner-argon2/src/blake2/blake2b.c +372 -0
  29. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +162 -0
  30. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +39 -0
  31. data/ext/phc-winner-argon2/src/core.c +662 -0
  32. data/ext/phc-winner-argon2/src/core.h +226 -0
  33. data/ext/phc-winner-argon2/src/genkat.c +194 -0
  34. data/ext/phc-winner-argon2/src/genkat.h +45 -0
  35. data/ext/phc-winner-argon2/src/opt.c +173 -0
  36. data/ext/phc-winner-argon2/src/opt.h +49 -0
  37. data/ext/phc-winner-argon2/src/ref.c +175 -0
  38. data/ext/phc-winner-argon2/src/ref.h +49 -0
  39. data/ext/phc-winner-argon2/src/run.c +223 -0
  40. data/ext/phc-winner-argon2/src/thread.c +36 -0
  41. data/ext/phc-winner-argon2/src/thread.h +46 -0
  42. data/lib/argon2.rb +15 -32
  43. data/lib/argon2/constants.rb +6 -0
  44. data/lib/argon2/engine.rb +10 -0
  45. data/lib/argon2/errors.rb +36 -0
  46. data/lib/argon2/ffi_engine.rb +47 -0
  47. data/lib/argon2/version.rb +1 -1
  48. metadata +75 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7a9392b4bb8cdc56418814da31cafecd75a4541
4
- data.tar.gz: 3f3bb552897de92e5ef3f0633a24608b1fb36e2f
3
+ metadata.gz: 4679e5dd53222a5799fac835361a04a77ae696ae
4
+ data.tar.gz: f53efbb7d825c9e271a6812a03340dc951b58c9b
5
5
  SHA512:
6
- metadata.gz: 9cd94e1f77f4fab2eab9e4365e5e7381006eb718d24bdb6da0263c370a685cea685518488b5e13290dd6b0955b8e781f1f078bf73b2d9a1907a84244701919a4
7
- data.tar.gz: 4c2b3f6cac4ba08e2fdfa2f3e09c98fdb493e82e57a0631aa9c52c3a9086953fe4dd5b87531f89535db72d72367026dcc423e613dc9e5ebe0935ee76591cbcf3
6
+ metadata.gz: bd1070534755d5f6582e6030b2b2e8907deca141553a1f767827ada8816321a16418ac245aa3e5c7453534ae93a649b5173bfe96cc1c3742f380d7194f22328b
7
+ data.tar.gz: 9e912c470b069e3b45a3253b7ad7761138d695468e8a5c65aa8495a98f7bcddf0c0cb1d708ee1165c87b9619e655bcf7ff29b1727e83f9190a46ce22a2d497c3
data/.gitignore CHANGED
@@ -7,3 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor
11
+ /ext/argon2_wrap/libargon2_wrap.so
12
+ /ext/argon2_wrap/tests
13
+ argon2-0.0.2.gem
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
+ - jruby-9000
4
5
  before_install: gem install bundler -v 1.10.5
6
+ install: bin/setup
data/README.md CHANGED
@@ -1,23 +1,39 @@
1
1
  # Argon2
2
2
 
3
- An FFI binding for Argon2.
4
- This gem is unfinished.
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.
5
4
 
5
+ *This gem is still in early development* and at this point is not recommended for use, even in testing.
6
6
 
7
- TODO: Delete this and the text above, and describe your gem
7
+ For early documentation, please see the test cases, which currently demonstrate low level hashing capabilities.
8
8
 
9
- ## Installation
9
+ [![Build Status](https://travis-ci.org/technion/ruby-argon2.svg?branch=master)](https://travis-ci.org/technion/ruby-argon2)
10
10
 
11
- Add this line to your application's Gemfile:
11
+ ## Design
12
12
 
13
- ```ruby
14
- gem 'argon2'
15
- ```
13
+ This project has several key tenants to its design:
16
14
 
15
+ * The reference Argon2 implementation is to be used "unaltered". To ensure this does not occur, and encourage regular updates from upstream, this is implemented as a git submodule, and is intended to stay that way.
16
+ * The FFI interface is kept as slim as possible, with wrapper classes preferred to implementing context structs in FFI
17
+ * 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
+ * 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 are aimed to be very comprehensive.
20
+
21
+ ## FAQ
22
+ ### Don't roll your own crypto!
23
+
24
+ This gets its own section because someone will raise it. I did not invent or alter this algorithm, or implement it directly.
25
+
26
+ ### "Secure wipe is useless"
27
+
28
+ 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.
29
+
30
+ ### Work maximums may be tighter than reference
31
+
32
+ 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.
17
33
 
18
34
  ## Contributing
19
35
 
20
- Not yet - the code is in a high state of flux.
36
+ Not yet - the code is in a high state of flux. If you feel you have identified a security issue, please email me directly. For any other bugs, it is too early to review them.
21
37
 
22
38
  ## License
23
39
 
@@ -15,12 +15,20 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ # submodule_path = 'ext/phc-winner-argon2/src'
19
+ # `ls #{submodule_path}`.split.each do |filename|
20
+ # spec.files << "#{submodule_path}/#{filename}"
21
+ # end
22
+ spec.files << `find ext`.split
23
+
18
24
  spec.bindir = "exe"
19
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
26
  spec.require_paths = ["lib"]
21
- spec.add_dependency 'ffi-compiler'
27
+ spec.add_dependency 'ffi', '~> 1.9'
28
+ spec.add_dependency 'ffi-compiler', '~> 0.1'
22
29
 
23
30
  spec.add_development_dependency "bundler", "~> 1.10"
24
31
  spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "minitest"
32
+ spec.add_development_dependency "minitest", '~> 5'
33
+ spec.extensions << 'ext/argon2_wrap/extconf.rb'
26
34
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "ruby/argon2"
4
+ require "argon2"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
data/bin/setup CHANGED
@@ -3,5 +3,8 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
+ cd ext/argon2_wrap/
7
+ make
8
+ cd ../..
6
9
 
7
10
  # Do any other automated setup that you need to do here
@@ -0,0 +1,72 @@
1
+ # Argon Wrapper Makefile
2
+ # This file is based on the original Argon2 reference
3
+ # Argon2 source code package
4
+ #
5
+ # This work is licensed under a Creative Commons CC0 1.0 License/Waiver.
6
+ #
7
+ # You should have received a copy of the CC0 Public Domain Dedication along with
8
+ # this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9
+ #
10
+
11
+ DIST_SRC = ../phc-winner-argon2/src
12
+ CC = gcc
13
+ SRC = $(DIST_SRC)/argon2.c $(DIST_SRC)/core.c $(DIST_SRC)/blake2/blake2b.c $(DIST_SRC)/thread.c argon_wrap.c
14
+ OBJ = $(SRC:.c=.o)
15
+
16
+ CFLAGS = -std=c89 -pthread -O3 -Wall -g
17
+
18
+ OPT=TRUE
19
+ ifeq ($(OPT), TRUE)
20
+ CFLAGS += -march=native
21
+ SRC += $(DIST_SRC)/opt.c
22
+ else
23
+ SRC += $(DIST_SRC)/ref.c
24
+ endif
25
+
26
+ BUILD_PATH := $(shell pwd)
27
+ KERNEL_NAME := $(shell uname -s)
28
+
29
+ LIB_NAME=argon2_wrap
30
+ ifeq ($(KERNEL_NAME), Linux)
31
+ LIB_EXT := so
32
+ LIB_CFLAGS := -shared -fPIC
33
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
34
+ endif
35
+ ifeq ($(KERNEL_NAME), NetBSD)
36
+ LIB_EXT := so
37
+ LIB_CFLAGS := -shared -fPIC
38
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
39
+ endif
40
+ ifeq ($(KERNEL_NAME), Darwin)
41
+ LIB_EXT := dylib
42
+ LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
43
+ LIB_PATH := -Xlinker -rpath -Xlinker $(BUILD_PATH)
44
+ endif
45
+ ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
46
+ LIB_EXT := dll
47
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
48
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
49
+ endif
50
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD))
51
+ LIB_EXT := so
52
+ LIB_CFLAGS := -shared -fPIC
53
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
54
+ endif
55
+
56
+ LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
57
+
58
+ all: libs
59
+ libs: $(SRC)
60
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $^ -o libargon2_wrap.so
61
+
62
+ #Deliberately avoiding the CFLAGS for our test cases - disable optimise and
63
+ #C89
64
+ test: $(SRC) test.c
65
+ $(CC) -pthread -O3 -Wall -g $^ -o tests
66
+ ./tests
67
+
68
+ clean:
69
+ rm -rf tests libargon2_wrap.so
70
+
71
+ install:
72
+ echo none
@@ -0,0 +1,65 @@
1
+ /* Wrapper for argon Ruby bindings
2
+ * lolware.net
3
+ * Much of this code is based on run.c from the reference implementation
4
+ */
5
+
6
+ #include <stdio.h>
7
+ #include <stdint.h>
8
+ #include <inttypes.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <time.h>
12
+
13
+ #include "../phc-winner-argon2/src/argon2.h"
14
+ #include "../phc-winner-argon2/src/core.h"
15
+
16
+ #define T_COST_DEF 3
17
+ #define LOG_M_COST_DEF 12 /* 2^12 = 4 MiB */
18
+ #define LANES_DEF 1
19
+ #define THREADS_DEF 1
20
+ #define OUT_LEN 32
21
+ #define SALT_LEN 16
22
+
23
+ unsigned int argon2_wrap(char *out, char *pwd, uint8_t *salt, uint32_t t_cost,
24
+ uint32_t m_cost, uint32_t lanes)
25
+ {
26
+ unsigned pwd_length;
27
+ uint8_t hash[OUT_LEN];
28
+ argon2_context context;
29
+
30
+ if (!pwd) {
31
+ return ARGON2_PWD_PTR_MISMATCH;
32
+ }
33
+
34
+ if (!salt) {
35
+ return ARGON2_PWD_PTR_MISMATCH;
36
+ }
37
+
38
+ pwd_length = strlen(pwd);
39
+
40
+ context.out = hash;
41
+ context.outlen = OUT_LEN;
42
+ context.pwd = (uint8_t *)pwd;
43
+ context.pwdlen = pwd_length;
44
+ context.salt = salt;
45
+ context.saltlen = SALT_LEN;
46
+ context.secret = NULL;
47
+ context.secretlen = 0;
48
+ context.ad = NULL;
49
+ context.adlen = 0;
50
+ context.t_cost = t_cost;
51
+ context.m_cost = m_cost;
52
+ context.lanes = lanes;
53
+ context.threads = lanes;
54
+ context.allocate_cbk = NULL;
55
+ context.free_cbk = NULL;
56
+ context.flags = 0;
57
+
58
+ int result = argon2i(&context);
59
+ if (result != ARGON2_OK)
60
+ return result;
61
+
62
+ encode_string(out, 300, &context);
63
+ return ARGON2_OK;
64
+ }
65
+
@@ -0,0 +1 @@
1
+ #I must admit I have no understanding of why this empty file works.
@@ -0,0 +1,67 @@
1
+ /* Wrapper for argon Ruby bindings
2
+ * lolware.net
3
+ * Much of this code is based on run.c from the reference implementation
4
+ */
5
+ #include <stdio.h>
6
+ #include <stdint.h>
7
+ #include <inttypes.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+ #include <time.h>
11
+
12
+ #include "../phc-winner-argon2/src/argon2.h"
13
+
14
+ #define OUT_LEN 32
15
+ #define SALT_LEN 16
16
+
17
+
18
+
19
+ void argon2_wrap(char *out, char *pwd, uint8_t *salt, uint32_t t_cost,
20
+ uint32_t m_cost, uint32_t lanes);
21
+
22
+ int main()
23
+ {
24
+ unsigned char out[OUT_LEN];
25
+ char out2[300];
26
+ char *pwd = NULL;
27
+ uint8_t salt[SALT_LEN];
28
+ int i;
29
+
30
+ pwd = strdup("password");
31
+ memset(salt, 0x00, SALT_LEN); /* pad with null bytes */
32
+ memcpy(salt, "somesalt", 8);
33
+
34
+
35
+ /* ./argon2 password somesalt -t 2 -m 16
36
+ * Hash: 894af4ff2e2d26f3ce15f77a7e1c25db45b4e20439e9961772ba199caddb001e
37
+ * ./argon2 password somesalt -t 2 -m 20
38
+ * Hash: 58d4d929aeeafa40cc049f032035784fb085e8e0d0c5a51ea067341a93d6d286
39
+ * ./argon2 password somesalt -t 2 -m 18
40
+ * Hash: 55292398cce8fc78685e610d004ca9bda5c325a0a2e6285a0de5f816df139aa6
41
+ * ./argon2 password somesalt -t 2 -m 8
42
+ * Hash: e346b1e1aa7ca58c9bb862e223ba5604064398d4394e49e90972c6b54cef43ed
43
+ * ./argon2 password somesalt -t 1 -m 16
44
+ * Hash: b49199e4ecb0f6659e6947f945e391c940b17106e1d0b0a9888006c7f87a789b
45
+ * ./argon2 password somesalt -t 4 -m 16
46
+ * Hash: 72207b3312d79995fbe7b30664837ae1246f9a98e07eac34835ca3498e705f85
47
+ * ./argon2 differentpassword somesalt -t 2 -m 16 -p 1
48
+ * Hash: 8e286f605ed7383987a4aac25a28a04808593b6e17613bc31457146c4f3f4361
49
+ * ./argon2 password diffsalt -t 2 -m 16 -p 1
50
+ * Hash: 8f65b47d902fb2aee5e0b2bdc9041b249fc11f06f35551e0bee52716b41e8311
51
+ */
52
+ hash_argon2i( out, OUT_LEN, pwd, strlen(pwd), salt, SALT_LEN, 2, 1<<16 );
53
+ for(i=0; i<32; ++i )
54
+ printf( "%02x", out[i] );
55
+ printf( "\n" );
56
+
57
+ strcpy(pwd, "password"); /* hash_argon2i wipes password content */
58
+ argon2_wrap(out2, pwd, salt, 2, 1<<16, 1);
59
+ printf("%s\n", out2);
60
+ free(pwd);;
61
+
62
+
63
+ return 0;
64
+
65
+
66
+ }
67
+
@@ -0,0 +1,7 @@
1
+ argon2
2
+ libargon2.a
3
+ libargon2.so
4
+ libargon2.dylib
5
+ .DS_Store
6
+ src/*.o
7
+ src/blake2/*.o
@@ -0,0 +1,31 @@
1
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
2
+
3
+ Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
6
+
7
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
8
+
9
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
10
+
11
+ 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
12
+
13
+ the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
14
+ moral rights retained by the original author(s) and/or performer(s);
15
+ publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
16
+ rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
17
+ rights protecting the extraction, dissemination, use and reuse of data in a Work;
18
+ database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
19
+ other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
20
+
21
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
22
+
23
+ 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
24
+
25
+ 4. Limitations and Disclaimers.
26
+
27
+ No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
28
+ Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
29
+ Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
30
+ Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
31
+
@@ -0,0 +1,102 @@
1
+ #
2
+ # Argon2 source code package
3
+ #
4
+ # This work is licensed under a Creative Commons CC0 1.0 License/Waiver.
5
+ #
6
+ # You should have received a copy of the CC0 Public Domain Dedication along with
7
+ # this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
8
+ #
9
+
10
+ RUN = argon2
11
+ BENCH = bench
12
+ GENKAT = genkat
13
+
14
+ DIST = phc-winner-argon2
15
+
16
+ CC = gcc
17
+ SRC = src/argon2.c src/core.c src/blake2/blake2b.c src/thread.c
18
+ SRC_RUN = src/run.c
19
+ SRC_BENCH = src/bench.c
20
+ SRC_GENKAT = src/genkat.c
21
+ OBJ = $(SRC:.c=.o)
22
+
23
+ CFLAGS = -std=c89 -pthread -O3 -Wall -g
24
+
25
+ #OPT=TRUE
26
+ ifeq ($(OPT), TRUE)
27
+ CFLAGS += -march=native
28
+ SRC += src/opt.c
29
+ else
30
+ SRC += src/ref.c
31
+ endif
32
+
33
+ BUILD_PATH := $(shell pwd)
34
+ KERNEL_NAME := $(shell uname -s)
35
+
36
+ LIB_NAME=argon2
37
+ ifeq ($(KERNEL_NAME), Linux)
38
+ LIB_EXT := so
39
+ LIB_CFLAGS := -shared -fPIC
40
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
41
+ endif
42
+ ifeq ($(KERNEL_NAME), NetBSD)
43
+ LIB_EXT := so
44
+ LIB_CFLAGS := -shared -fPIC
45
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
46
+ endif
47
+ ifeq ($(KERNEL_NAME), Darwin)
48
+ LIB_EXT := dylib
49
+ LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
50
+ LIB_PATH := -Xlinker -rpath -Xlinker $(BUILD_PATH)
51
+ endif
52
+ ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
53
+ LIB_EXT := dll
54
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
55
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
56
+ endif
57
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD))
58
+ LIB_EXT := so
59
+ LIB_CFLAGS := -shared -fPIC
60
+ LIB_PATH := -Wl,-rpath=$(BUILD_PATH)
61
+ endif
62
+
63
+ LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
64
+ LIB_ST := lib$(LIB_NAME).a
65
+
66
+ .PHONY: clean dist format $(GENKAT)
67
+
68
+ all: clean $(RUN) libs
69
+ libs: $(LIB_SH) $(LIB_ST)
70
+
71
+ $(RUN): $(SRC) $(SRC_RUN)
72
+ $(CC) $(CFLAGS) $^ -Isrc -o $@
73
+
74
+ $(BENCH): $(SRC) $(SRC_BENCH)
75
+ $(CC) $(CFLAGS) $^ -Isrc -o $@
76
+
77
+ $(GENKAT): $(SRC) $(SRC_GENKAT)
78
+ $(CC) $(CFLAGS) $^ -Isrc -o $@ -DGENKAT
79
+
80
+ $(LIB_SH): $(SRC)
81
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $^ -Isrc -o $@
82
+
83
+ $(LIB_ST): $(OBJ)
84
+ ar rcs $@ $^
85
+
86
+ clean:
87
+ rm -f $(RUN) $(BENCH) $(GENKAT)
88
+ rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
89
+ rm -rf *.dSYM
90
+ cd src/ && rm -f *.o
91
+ cd src/blake2/ && rm -f *.o
92
+ cd kats/ && rm -f kat-* diff* run_* make_*
93
+
94
+ dist:
95
+ cd ..; \
96
+ tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
97
+
98
+ test:
99
+ @sh kats/test.sh
100
+
101
+ format:
102
+ clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" -i src/*.c src/*.h src/blake2/*.c src/blake2/*.h