enzoic 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +5 -0
  7. data/README.md +90 -0
  8. data/Rakefile +28 -0
  9. data/enzoic.gemspec +36 -0
  10. data/ext/.DS_Store +0 -0
  11. data/ext/argon2-wrapper/Makefile +74 -0
  12. data/ext/argon2-wrapper/argon2-wrapper.c +165 -0
  13. data/ext/argon2-wrapper/extconf.rb +1 -0
  14. data/ext/argon2_import/.DS_Store +0 -0
  15. data/ext/digest/whirlpool/extconf.rb +10 -0
  16. data/ext/digest/whirlpool/whirlpool-algorithm.c +476 -0
  17. data/ext/digest/whirlpool/whirlpool-algorithm.h +86 -0
  18. data/ext/digest/whirlpool/whirlpool-constants.h +1116 -0
  19. data/ext/digest/whirlpool/whirlpool-portability.h +142 -0
  20. data/ext/digest/whirlpool/whirlpool.c +51 -0
  21. data/ext/phc-winner-argon2/.gitattributes +10 -0
  22. data/ext/phc-winner-argon2/.gitignore +21 -0
  23. data/ext/phc-winner-argon2/.travis.yml +14 -0
  24. data/ext/phc-winner-argon2/Argon2.sln +160 -0
  25. data/ext/phc-winner-argon2/CHANGELOG.md +25 -0
  26. data/ext/phc-winner-argon2/LICENSE +314 -0
  27. data/ext/phc-winner-argon2/Makefile +187 -0
  28. data/ext/phc-winner-argon2/README.md +290 -0
  29. data/ext/phc-winner-argon2/appveyor.yml +25 -0
  30. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  31. data/ext/phc-winner-argon2/export.sh +7 -0
  32. data/ext/phc-winner-argon2/include/argon2.h +435 -0
  33. data/ext/phc-winner-argon2/kats/argon2d +12304 -0
  34. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  35. data/ext/phc-winner-argon2/kats/argon2d_v16 +12304 -0
  36. data/ext/phc-winner-argon2/kats/argon2d_v16.shasum +1 -0
  37. data/ext/phc-winner-argon2/kats/argon2i +12304 -0
  38. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  39. data/ext/phc-winner-argon2/kats/argon2i_v16 +12304 -0
  40. data/ext/phc-winner-argon2/kats/argon2i_v16.shasum +1 -0
  41. data/ext/phc-winner-argon2/kats/argon2id +12304 -0
  42. data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
  43. data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
  44. data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
  45. data/ext/phc-winner-argon2/kats/check-sums.ps1 +42 -0
  46. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  47. data/ext/phc-winner-argon2/kats/test.ps1 +50 -0
  48. data/ext/phc-winner-argon2/kats/test.sh +49 -0
  49. data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
  50. data/ext/phc-winner-argon2/latex/Makefile +18 -0
  51. data/ext/phc-winner-argon2/latex/argon2-specs.tex +920 -0
  52. data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
  53. data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
  54. data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
  55. data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
  56. data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
  57. data/ext/phc-winner-argon2/libargon2.pc +16 -0
  58. data/ext/phc-winner-argon2/man/argon2.1 +57 -0
  59. data/ext/phc-winner-argon2/src/argon2.c +452 -0
  60. data/ext/phc-winner-argon2/src/bench.c +111 -0
  61. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +156 -0
  62. data/ext/phc-winner-argon2/src/blake2/blake2.h +91 -0
  63. data/ext/phc-winner-argon2/src/blake2/blake2b.c +390 -0
  64. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +328 -0
  65. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +56 -0
  66. data/ext/phc-winner-argon2/src/core.c +635 -0
  67. data/ext/phc-winner-argon2/src/core.h +227 -0
  68. data/ext/phc-winner-argon2/src/encoding.c +463 -0
  69. data/ext/phc-winner-argon2/src/encoding.h +57 -0
  70. data/ext/phc-winner-argon2/src/genkat.c +208 -0
  71. data/ext/phc-winner-argon2/src/genkat.h +49 -0
  72. data/ext/phc-winner-argon2/src/opt.c +241 -0
  73. data/ext/phc-winner-argon2/src/ref.c +194 -0
  74. data/ext/phc-winner-argon2/src/run.c +317 -0
  75. data/ext/phc-winner-argon2/src/test.c +254 -0
  76. data/ext/phc-winner-argon2/src/thread.c +57 -0
  77. data/ext/phc-winner-argon2/src/thread.h +67 -0
  78. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
  79. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  80. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
  81. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  82. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
  83. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  84. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
  85. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  86. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
  87. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  88. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
  89. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  90. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
  91. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  92. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
  93. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  94. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
  95. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  96. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
  97. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  98. data/lib/enzoic.rb +189 -0
  99. data/lib/enzoic/argon2_errors.rb +39 -0
  100. data/lib/enzoic/argon2_wrapper_ffi.rb +89 -0
  101. data/lib/enzoic/constants.rb +10 -0
  102. data/lib/enzoic/errors.rb +3 -0
  103. data/lib/enzoic/hashing.rb +258 -0
  104. data/lib/enzoic/password_type.rb +25 -0
  105. data/lib/enzoic/version.rb +5 -0
  106. metadata +354 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f384606d64ea5eac9f13b2467ab4e494d7043312
4
+ data.tar.gz: 7f3d428ada763102e27d26aba7ee5172169e5bee
5
+ SHA512:
6
+ metadata.gz: 7a6da77a5e86c97d835e50378c67423c6197f771d5647216d9c7613d7cf402ff6705dbf9e20fce28796bf8957741a3d7459c6dbec0aead19f0ff9e3a7bc4b09e
7
+ data.tar.gz: 20356c44bacd22fa24ea58ee85515acecb44326b4fc5b46ee233ad0b132727b8b61594053e2c91df1a4c5300277f0bcda1c7691acf14ed5b126e59bc265e55b1
@@ -0,0 +1,19 @@
1
+ .DS_store
2
+ /.atomenv.json
3
+ /.idea/
4
+ /.bundle/
5
+ /.yardoc
6
+ /Gemfile.lock
7
+ /_yardoc/
8
+ /coverage/
9
+ /doc/
10
+ /pkg/
11
+ /spec/reports/
12
+ /tmp/
13
+ /ext/argon2-wrapper/libargon2-wrapper.so
14
+ /ext/argon2-wrapper/tests
15
+ /ext/argon2-wrapper/libargon2-wrapper.bundle*
16
+ passwordping-1.0.0.gem
17
+ enzoic-1.0.0.gem
18
+ enzoic-*.gem
19
+ *.bundle
@@ -0,0 +1,3 @@
1
+ [submodule "ext/phc-winner-argon2"]
2
+ path = ext/phc-winner-argon2
3
+ url = https://github.com/P-H-C/phc-winner-argon2.git
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enzoic.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Enzoic Ruby Library
2
+ https://www.enzoic.com/
3
+
4
+ Copyright 2019, Enzoic
5
+ Released under the MIT license.
@@ -0,0 +1,90 @@
1
+ # Enzoic Ruby Client Library
2
+
3
+
4
+ ## TOC
5
+
6
+ This README covers the following topics:
7
+
8
+ - [Installation](#installation)
9
+ - [Source](#source)
10
+ - [API Overview](#api-overview)
11
+ - [The Enzoic constructor](#the-enzoic-constructor)
12
+ - [Platform Requirements](#platform-requirements)
13
+ - [RubyDocs](#rubydocs)
14
+
15
+ ## Installation
16
+
17
+ The compiled library is available as a Ruby Gem:
18
+
19
+ ```shell
20
+ gem install enzoic
21
+ ```
22
+
23
+ ### Source
24
+
25
+ You can build the project from the source in this repository.
26
+
27
+ ## API Overview
28
+
29
+ Here's the API in a nutshell.
30
+
31
+ ```ruby
32
+ require 'enzoic'
33
+
34
+ # Create a new Enzoic instance - this is our primary interface for making API calls
35
+ enzoic = Enzoic::Enzoic.new(apiKey: YOUR_API_KEY, secret: YOUR_API_SECRET)
36
+
37
+ # Check whether a password has been compromised
38
+ if enzoic.check_password("password-to-test")
39
+ puts("Password is compromised")
40
+ else
41
+ puts("Password is not compromised")
42
+ end
43
+
44
+ # Check whether a specific set of credentials are compromised
45
+ if enzoic.check_credentials("test@enzoic.com", "password-to-test")
46
+ puts("Credentials are compromised")
47
+ else
48
+ puts("Credentials are not compromised")
49
+ end
50
+
51
+ # get all exposures for a given user
52
+ exposures = enzoic.get_exposures_for_user("test@enzoic.com")
53
+ puts(exposures.count.to_s + " exposures found for test@enzoic.com")
54
+
55
+ # now get the full details for the first exposure found
56
+ details = enzoic.get_exposure_details(exposures.exposures[0])
57
+ puts("First exposure for test@enzoic.com was " + details.title)
58
+ ```
59
+
60
+ More information in reference format can be found below.
61
+
62
+ ## The Enzoic constructor
63
+
64
+ The standard constructor takes the API key and secret you were issued on Enzoic signup.
65
+
66
+ ```ruby
67
+ enzoic = Enzoic::Enzoic.new(apiKey: YOUR_API_KEY, secret: YOUR_API_SECRET)
68
+ ```
69
+
70
+ If you were instructed to use an alternate API endpoint, you may call the overloaded constructor and pass the base URL you were provided.
71
+
72
+ ```ruby
73
+ enzoic = Enzoic::Enzoic.new(apiKey: YOUR_API_KEY, secret: YOUR_API_SECRET, baseURL: "https://api-alt.enzoic.com/v1")
74
+ ```
75
+
76
+ ## Platform Requirements
77
+
78
+ OSX and Linux platforms are fully supported. Windows is not, since FFI support is needed for some of the cryptography libraries, which is problematic on Windows.
79
+
80
+ Ruby 2.0.0 and up are supported.
81
+
82
+ ## RubyDocs
83
+
84
+ The RubyDocs contain more complete references for the API functions.
85
+
86
+ They can be found here: <http://www.rubydoc.info/gems/enzoic>
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,28 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rake/clean"
4
+ require 'rake/extensiontask'
5
+
6
+ gemspec = Bundler::GemHelper.gemspec
7
+
8
+ CLEAN.include [ 'lib/digest/whirlpool.*', 'ext/argon2-wrapper/libargon2-wrapper.*' ]
9
+ CLOBBER.include [ 'ext/digest/whirlpool/mkmf.log', 'ext/digest/whirlpool/Makefile' ]
10
+
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << "test"
13
+ t.libs << "lib"
14
+ t.warning = true
15
+ t.test_files = FileList['test/**/*_test.rb']
16
+ end
17
+
18
+ Rake::ExtensionTask.new('whirlpool', gemspec) do |ext|
19
+ ext.ext_dir = 'ext/digest/whirlpool'
20
+ ext.lib_dir = 'lib/digest'
21
+ end
22
+
23
+ Rake::ExtensionTask.new('argon2-wrapper', gemspec) do |ext|
24
+ ext.ext_dir = 'ext/argon2-wrapper'
25
+ ext.lib_dir = 'lib/enzoic'
26
+ end
27
+
28
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enzoic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enzoic"
8
+ spec.version = Enzoic::VERSION
9
+ spec.authors = ["Enzoic"]
10
+ spec.email = ["support@enzoic.com"]
11
+
12
+ spec.summary = 'Ruby library for Enzoic API'
13
+ spec.description = 'Ruby library for Enzoic API'
14
+ spec.homepage = 'https://github.com/enzoic/enzoic-ruby-client'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.files << `find ext`.split
19
+
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+ spec.add_dependency 'ffi', '~> 1.11.1'
24
+ spec.add_dependency 'ffi-compiler', '~> 1.0.1'
25
+ spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
26
+ spec.add_dependency 'bcrypt', '~> 3.1', '>= 3.1.11'
27
+ spec.add_dependency 'unix-crypt', '~> 1.3'
28
+ spec.add_dependency 'base64url', '~> 1.0', '>= 1.0.1'
29
+
30
+ spec.add_development_dependency "bundler", '~> 2.0.2', '>= 2.0.2'
31
+ spec.add_development_dependency "rake", '~> 10.4', '>= 10.4.2'
32
+ spec.add_development_dependency "test-unit", '~> 3.2', '>= 3.2.4'
33
+ spec.add_development_dependency "rake-compiler", '~> 1.0', '>= 1.0.4'
34
+ spec.add_development_dependency "io-console", '~> 0.4', '>= 0.4.6'
35
+ spec.extensions = ['ext/argon2-wrapper/extconf.rb', "ext/digest/whirlpool/extconf.rb" ]
36
+ end
Binary file
@@ -0,0 +1,74 @@
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
+ SRC = $(DIST_SRC)/argon2.c $(DIST_SRC)/core.c $(DIST_SRC)/blake2/blake2b.c $(DIST_SRC)/thread.c $(DIST_SRC)/encoding.c argon2-wrapper.c
13
+ OBJ = $(SRC:.c=.o)
14
+
15
+ CFLAGS = -pthread -O3 -Wall -I../phc-winner-argon2/include -I../phc-winner-argon2/src
16
+
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
22
+ CFLAGS += -march=native
23
+ SRC += $(DIST_SRC)/opt.c
24
+ endif
25
+
26
+
27
+ BUILD_PATH := $(shell pwd)
28
+ KERNEL_NAME := $(shell uname -s)
29
+
30
+ LIB_NAME=argon2-wrapper
31
+ ifeq ($(KERNEL_NAME), Linux)
32
+ LIB_EXT := so
33
+ LIB_CFLAGS := -shared -fPIC
34
+ endif
35
+ ifeq ($(KERNEL_NAME), NetBSD)
36
+ LIB_EXT := so
37
+ LIB_CFLAGS := -shared -fPIC
38
+ endif
39
+ ifeq ($(KERNEL_NAME), Darwin)
40
+ LIB_EXT := bundle
41
+ LIB_CFLAGS := -bundle
42
+ endif
43
+ ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
44
+ LIB_EXT := dll
45
+ LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
46
+ endif
47
+ ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD))
48
+ LIB_EXT := so
49
+ LIB_CFLAGS := -shared -fPIC
50
+ endif
51
+ ifeq ($(KERNEL_NAME), SunOS)
52
+ CC := gcc
53
+ CFLAGS += -D_REENTRANT
54
+ LIB_EXT := so
55
+ LIB_CFLAGS := -shared -fPIC
56
+ endif
57
+
58
+ LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
59
+
60
+ all: libs
61
+ libs: $(SRC)
62
+ $(CC) $(CFLAGS) $(LIB_CFLAGS) $^ -o libargon2-wrapper.$(LIB_EXT)
63
+
64
+ #Deliberately avoiding the CFLAGS for our test cases - disable optimise and
65
+ #C89
66
+ test: $(SRC) test.c
67
+ clang -pthread -O3 -fsanitize=address -fsanitize=undefined -Wall -g $^ -o tests $(CFLAGS)
68
+ ./tests
69
+
70
+ clean:
71
+ rm -f tests libargon2-wrapper.$(LIB_EXT)
72
+
73
+ install:
74
+ echo none
@@ -0,0 +1,165 @@
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 "argon2.h"
14
+ #include "core.h"
15
+ #include "encoding.h"
16
+
17
+ #define T_COST_DEF 3
18
+ #define LOG_M_COST_DEF 12 /* 2^12 = 4 MiB */
19
+ #define LANES_DEF 1
20
+ #define THREADS_DEF 1
21
+ #define OUT_LEN 32
22
+ #define SALT_LEN 16
23
+ #define ENCODE_LEN 96 /* Does not include SALT LEN */
24
+
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
+ }
35
+
36
+ int argon2_wrap_version(char *out, const char *pwd, size_t pwd_length,
37
+ uint8_t *salt, uint32_t saltlen, uint32_t t_cost, uint32_t m_cost,
38
+ uint32_t lanes, uint8_t *secret, size_t secretlen, uint32_t version,
39
+ argon2_type type)
40
+ {
41
+ uint8_t hash[OUT_LEN];
42
+ argon2_context context;
43
+
44
+ if (!pwd) {
45
+ return ARGON2_PWD_PTR_MISMATCH;
46
+ }
47
+
48
+ if (!salt) {
49
+ return ARGON2_PWD_PTR_MISMATCH;
50
+ }
51
+
52
+ context.out = hash;
53
+ context.outlen = OUT_LEN;
54
+ context.pwd = (uint8_t *)pwd;
55
+ context.pwdlen = pwd_length;
56
+ context.salt = salt;
57
+ context.saltlen = saltlen;
58
+ context.secret = secret;
59
+ context.secretlen = secretlen;
60
+ context.ad = NULL;
61
+ context.adlen = 0;
62
+ context.t_cost = t_cost;
63
+ context.m_cost = m_cost;
64
+ context.lanes = lanes;
65
+ context.threads = lanes;
66
+ context.allocate_cbk = NULL;
67
+ context.free_cbk = NULL;
68
+ context.flags = 0;
69
+ context.version = version;
70
+
71
+ int result;
72
+ if (type == Argon2_i) {
73
+ result = argon2i_ctx(&context);
74
+ } else if (type == Argon2_id) {
75
+ result = argon2id_ctx(&context);
76
+ } else if (type == Argon2_d) {
77
+ result = argon2d_ctx(&context);
78
+ } else {
79
+ // Unsupported type
80
+ return ARGON2_ENCODING_FAIL;
81
+ }
82
+
83
+ if (result != ARGON2_OK)
84
+ return result;
85
+
86
+ encode_string(out, ENCODE_LEN + saltlen, &context, type);
87
+ return ARGON2_OK;
88
+ }
89
+
90
+ /* Since all new hashes will use latest version, this wraps the
91
+ * function including the version
92
+ */
93
+ int argon2_wrap(char *out, const char *pwd, size_t pwd_length,
94
+ uint8_t *salt, uint32_t saltlen, uint32_t t_cost, uint32_t m_cost,
95
+ uint32_t lanes, uint8_t *secret, size_t secretlen)
96
+ {
97
+ return argon2_wrap_version(out, pwd, pwd_length, salt, saltlen,
98
+ t_cost, m_cost, lanes, secret, secretlen, ARGON2_VERSION_13, Argon2_id);
99
+ }
100
+
101
+ int wrap_argon2_verify(const char *encoded, const char *pwd,
102
+ const size_t pwdlen,
103
+ uint8_t *secret, size_t secretlen)
104
+ {
105
+ argon2_context ctx;
106
+ int ret;
107
+ char *out;
108
+ memset(&ctx, 0, sizeof(argon2_context));
109
+ size_t encoded_len;
110
+ argon2_type type;
111
+
112
+ encoded_len = strlen(encoded);
113
+ /* larger than max possible values */
114
+ ctx.saltlen = encoded_len;
115
+ ctx.outlen = encoded_len;
116
+
117
+ ctx.salt = malloc(ctx.saltlen);
118
+ ctx.out = malloc(ctx.outlen);
119
+ if (!ctx.out || !ctx.salt) {
120
+ free(ctx.salt);
121
+ free(ctx.out);
122
+ return ARGON2_MEMORY_ALLOCATION_ERROR;
123
+ }
124
+
125
+ if (memcmp(encoded, "$argon2id", strlen("$argon2id")) == 0) {
126
+ type = Argon2_id;
127
+ } else if (memcmp(encoded, "$argon2i", strlen("$argon2i")) == 0) {
128
+ type = Argon2_i;
129
+ } else if (memcmp(encoded, "$argon2d", strlen("$argon2d")) == 0) {
130
+ type = Argon2_d;
131
+ } else {
132
+ // Other types not yet supported
133
+ return ARGON2_DECODING_FAIL;
134
+ }
135
+
136
+ if (decode_string(&ctx, encoded, type) != ARGON2_OK) {
137
+ free(ctx.salt);
138
+ free(ctx.out);
139
+ return ARGON2_DECODING_FAIL;
140
+ }
141
+
142
+ out = malloc(ENCODE_LEN + ctx.saltlen);
143
+ if(!out) {
144
+ free(ctx.salt);
145
+ free(ctx.out);
146
+ return ARGON2_DECODING_FAIL;
147
+ }
148
+
149
+ ret = argon2_wrap_version(out, pwd, pwdlen, ctx.salt, ctx.saltlen,
150
+ ctx.t_cost, ctx.m_cost, ctx.lanes, secret, secretlen,
151
+ ctx.version, type);
152
+
153
+ free(ctx.salt);
154
+
155
+ if (ret != ARGON2_OK || wrap_compare((uint8_t*)out, (uint8_t*)encoded,
156
+ strlen(encoded))) {
157
+ free(ctx.out);
158
+ free(out);
159
+ return ARGON2_DECODING_FAIL;
160
+ }
161
+ free(ctx.out);
162
+ free(out);
163
+
164
+ return ARGON2_OK;
165
+ }