kryptonita 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ require "mkmf"
2
+
3
+ dir_config('whirlpool')
4
+
5
+ create_makefile "whirlpool"
@@ -0,0 +1,129 @@
1
+
2
+ #ifndef PORTABLE_C__
3
+ #define PORTABLE_C__
4
+
5
+ #include <limits.h>
6
+
7
+ /* Definition of minimum-width integer types
8
+ *
9
+ * u8 -> unsigned integer type, at least 8 bits, equivalent to unsigned char
10
+ * u16 -> unsigned integer type, at least 16 bits
11
+ * u32 -> unsigned integer type, at least 32 bits
12
+ *
13
+ * s8, s16, s32 -> signed counterparts of u8, u16, u32
14
+ *
15
+ * Always use macro's T8(), T16() or T32() to obtain exact-width results,
16
+ * i.e., to specify the size of the result of each expression.
17
+ */
18
+
19
+ typedef signed char s8;
20
+ typedef unsigned char u8;
21
+
22
+ #if UINT_MAX >= 4294967295UL
23
+
24
+ typedef signed short s16;
25
+ typedef signed int s32;
26
+ typedef unsigned short u16;
27
+ typedef unsigned int u32;
28
+
29
+ #define ONE32 0xffffffffU
30
+
31
+ #else
32
+
33
+ typedef signed int s16;
34
+ typedef signed long s32;
35
+ typedef unsigned int u16;
36
+ typedef unsigned long u32;
37
+
38
+ #define ONE32 0xffffffffUL
39
+
40
+ #endif
41
+
42
+ #define ONE8 0xffU
43
+ #define ONE16 0xffffU
44
+
45
+ #define T8(x) ((x) & ONE8)
46
+ #define T16(x) ((x) & ONE16)
47
+ #define T32(x) ((x) & ONE32)
48
+
49
+ #ifdef _MSC_VER
50
+ typedef unsigned __int64 u64;
51
+ typedef signed __int64 s64;
52
+ #define LL(v) (v##i64)
53
+ #define ONE64 LL(0xffffffffffffffff)
54
+ #else /* !_MSC_VER */
55
+ typedef unsigned long long u64;
56
+ typedef signed long long s64;
57
+ #define LL(v) (v##ULL)
58
+ #define ONE64 LL(0xffffffffffffffff)
59
+ #endif /* ?_MSC_VER */
60
+ #define T64(x) ((x) & ONE64)
61
+ #define ROTR64(v, n) (((v) >> (n)) | T64((v) << (64 - (n))))
62
+ /*
63
+ * Note: the test is used to detect native 64-bit architectures;
64
+ * if the unsigned long is strictly greater than 32-bit, it is
65
+ * assumed to be at least 64-bit. This will not work correctly
66
+ * on (old) 36-bit architectures (PDP-11 for instance).
67
+ *
68
+ * On non-64-bit architectures, "long long" is used.
69
+ */
70
+
71
+ /*
72
+ * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
73
+ * in the unsigned char array pointed to by c.
74
+ */
75
+ #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
76
+
77
+ /*
78
+ * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
79
+ * in the unsigned char array pointed to by c.
80
+ */
81
+ #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
82
+
83
+ /*
84
+ * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention
85
+ * into the unsigned char array pointed to by c.
86
+ */
87
+ #define U32TO8_BIG(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x >> 24); d[1] = T8(x >> 16); d[2] = T8(x >> 8); d[3] = T8(x); } while (0)
88
+
89
+ /*
90
+ * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention
91
+ * into the unsigned char array pointed to by c.
92
+ */
93
+ #define U32TO8_LITTLE(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x); d[1] = T8(x >> 8); d[2] = T8(x >> 16); d[3] = T8(x >> 24); } while (0)
94
+
95
+ /*
96
+ * ROTL32(v, n) returns the value of the 32-bit unsigned value v after
97
+ * a rotation of n bits to the left. It might be replaced by the appropriate
98
+ * architecture-specific macro.
99
+ *
100
+ * It evaluates v and n twice.
101
+ *
102
+ * The compiler might emit a warning if n is the constant 0. The result
103
+ * is undefined if n is greater than 31.
104
+ */
105
+ #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n))))
106
+
107
+ /*
108
+ * Whirlpool-specific definitions.
109
+ */
110
+
111
+ #define DIGESTBYTES 64
112
+ #define DIGESTBITS (8*DIGESTBYTES) /* 512 */
113
+
114
+ #define WBLOCKBYTES 64
115
+ #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */
116
+
117
+ #define LENGTHBYTES 32
118
+ #define LENGTHBITS (8*LENGTHBYTES) /* 256 */
119
+
120
+ typedef struct NESSIEstruct {
121
+ u8 bitLength[LENGTHBYTES]; /* global number of hashed bits (256-bit counter) */
122
+ u8 buffer[WBLOCKBYTES]; /* buffer of data to hash */
123
+ int bufferBits; /* current number of bits on the buffer */
124
+ int bufferPos; /* current (possibly incomplete) byte slot on the buffer */
125
+ u64 hash[DIGESTBYTES/8]; /* the hashing state */
126
+ } NESSIEstruct;
127
+
128
+ #endif /* PORTABLE_C__ */
129
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kryptonita/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kryptonita"
8
+ spec.version = Kryptonita::VERSION
9
+ spec.authors = ["Patrício dos Santos"]
10
+ spec.email = ["ps@patriciodossantos.net"]
11
+ spec.summary = %q{Kryptonita is a Ruby gem that provides a lot of functions for hashing, encrypt and decrypt}
12
+ spec.description = %q{Kryptonita is a Ruby gem that provides a lot of functions for hashing, encrypt and decrypt.}
13
+ spec.homepage = "https://github.com/AngoDev/kryptonita"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,13 @@
1
+ require "kryptonita/version"
2
+ require "whirlpool/whirlpool"
3
+
4
+ module Kryptonita
5
+ class Hash
6
+
7
+ def self.whirlpool(str)
8
+ w = Whirlpool::Class.new
9
+ w.print_string(str).downcase
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Kryptonita
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "./whirlpool/whirlpool"
2
+
3
+ def print
4
+ w = Whirlpool::Class.new
5
+ p w.print_string("rubyç")
6
+ end
7
+
8
+ print
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ module Kryptonita
4
+ describe Hash do
5
+
6
+ describe "#whirlpool" do
7
+ let(:hashed) { Kryptonita::Hash.whirlpool("ruby") }
8
+
9
+ it "returns a string" do
10
+ expect(hashed).to be_a(String)
11
+ end
12
+
13
+ it "returns a string with a size 128" do
14
+ expect(hashed.size).to eq(128)
15
+ end
16
+
17
+ it "returns a correct hash" do
18
+ expect(hashed).to eql("95fc6a05b1edd849a202d9cdb1158930cf1e101900357a8816b743520710be2487c890c3bfb2b70f2308f7e8737473a477bb44950516c23e53a2993091faa9d2")
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,91 @@
1
+ require "kryptonita"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ #config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ #config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ #if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ # config.default_formatter = 'doc'
72
+ #end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ # config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ # Kernel.srand config.seed
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kryptonita
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrício dos Santos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Kryptonita is a Ruby gem that provides a lot of functions for hashing,
56
+ encrypt and decrypt.
57
+ email:
58
+ - ps@patriciodossantos.net
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .ruby-gemset
66
+ - .ruby-version
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - ext/whirlpool/Makefile
72
+ - ext/whirlpool/Whirlpool.c
73
+ - ext/whirlpool/extconf.rb
74
+ - ext/whirlpool/nessie.h
75
+ - kryptonita.gemspec
76
+ - lib/kryptonita.rb
77
+ - lib/kryptonita/version.rb
78
+ - lib/teste.rb
79
+ - spec/kryptonita/hash_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: https://github.com/AngoDev/kryptonita
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Kryptonita is a Ruby gem that provides a lot of functions for hashing, encrypt
105
+ and decrypt
106
+ test_files:
107
+ - spec/kryptonita/hash_spec.rb
108
+ - spec/spec_helper.rb