ruby-scrypt 1.0.0.pre → 1.0.0.pre2

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.
data/README.md CHANGED
@@ -1,4 +1,17 @@
1
1
  ruby-scrypt
2
2
  ===========
3
3
 
4
- Litecoin Scrypt hashing function for Ruby
4
+ Litecoin Scrypt hashing function for Ruby.
5
+
6
+ Usage :
7
+
8
+ require 'scrypt'
9
+
10
+ # Litecoin block #526291
11
+ block_header_hex = "02000000" + "b73417169f9055d2a9e143faa078e0cf97a13c40a5fc117a6b85a2240e5a7d1a" + "dc39618a259aa142f2c01e3640f19a68848a7494e75f22a4f068e24ae5a4d8b1" + "b1e51853" + "0eb6101b" + "003a269b"
12
+ Scrypt.hash_hex( block_header_hex )
13
+ # => "000000000003f406a8163444623935c2c4320a7d5508773b3c2de8fee4b14068"
14
+
15
+ block_header_bin = [block_header_hex].pack("H*")
16
+ Scrypt.hash_bin( block_header_bin )
17
+ # => "\x00\x00\x00\x00\x00\x03\xF4\x06\xA8\x164Db95\xC2\xC42\n}U\bw;<-\xE8\xFE\xE4\xB1@h"
data/ext/scrypt/scrypt.c CHANGED
@@ -30,11 +30,18 @@
30
30
  // * StringValuePtr converts a Ruby String object to a C char *
31
31
  static VALUE method_scrypt_hash_bin(VALUE mod, VALUE payload) {
32
32
  char output[32];
33
+ unsigned char i, tmp;
33
34
  Check_Type(payload, T_STRING);
34
35
  if (RSTRING_LEN(payload) != 80)
35
36
  rb_raise(rb_eArgError, "Invalid argument : wait a 80 length binary string. %ld", RSTRING_LEN(payload));
36
37
 
37
38
  scrypt_1024_1_1_256(StringValuePtr(payload), output);
39
+ // reverse output
40
+ for (i = 0 ; i < 16; i++) {
41
+ tmp = output[i];
42
+ output[i] = output[31-i];
43
+ output[31-i] = tmp;
44
+ }
38
45
  return rb_str_new(output, 32);
39
46
  }
40
47
 
data/lib/scrypt.rb CHANGED
@@ -3,6 +3,6 @@ require "scrypt/scrypt"
3
3
  module Scrypt
4
4
  def self.hash_hex( input )
5
5
  raise ArgumentError, 'input must be a 160 byte hexa string.' if input.size != 160
6
- hash_bin( [input].pack("H*") ).reverse.unpack("H*")[0]
6
+ hash_bin( [input].pack("H*") ).unpack("H*")[0]
7
7
  end
8
8
  end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ruby-scrypt"
6
+ s.version = "1.0.0.pre2"
7
+ s.authors = ["Vincent Renaudineau"]
8
+ s.email = ["vincent.renaudineau@wanadoo.fr"]
9
+ s.summary = %q{Litecoin Scrypt hashing function for Ruby.}
10
+ s.description = %q{Litecoin Scrypt hashing function for Ruby. Only allow 80 or 160 bytes payload.}
11
+ s.homepage = "https://github.com/Timmy72/ruby-scrypt"
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.extensions = %w[ext/scrypt/extconf.rb]
17
+ s.require_paths = ["lib"]
18
+ end
data/test/scrypt_test.rb CHANGED
@@ -8,10 +8,10 @@ class ScryptTest < MiniTest::Unit::TestCase
8
8
  input_hex = "02000000b73417169f9055d2a9e143faa078e0cf97a13c40a5fc117a6b85a2240e5a7d1adc39618a259aa142f2c01e3640f19a68848a7494e75f22a4f068e24ae5a4d8b1b1e518530eb6101b003a269b"
9
9
  input_bin = [input_hex].pack("H*")
10
10
  output_hex = "000000000003f406a8163444623935c2c4320a7d5508773b3c2de8fee4b14068"
11
- output_bin = [output_hex].pack("H*").reverse
11
+ output_bin = [output_hex].pack("H*")
12
12
 
13
- assert_equal output_hex, Scrypt.hash_hex(input_hex)
14
13
  assert_equal output_bin, Scrypt.hash_bin(input_bin)
14
+ assert_equal output_hex, Scrypt.hash_hex(input_hex)
15
15
 
16
16
  assert_raises ArgumentError do
17
17
  Scrypt.hash_bin("toto")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-scrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0.pre2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,8 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2014-03-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Litecoin Scrypt hashing function for Ruby. Only allow 80 bytes payload.
14
+ description: Litecoin Scrypt hashing function for Ruby. Only allow 80 or 160 bytes
15
+ payload.
15
16
  email:
16
17
  - vincent.renaudineau@wanadoo.fr
17
18
  executables: []
@@ -26,6 +27,7 @@ files:
26
27
  - ext/scrypt/percival_scrypt.h
27
28
  - ext/scrypt/scrypt.c
28
29
  - lib/scrypt.rb
30
+ - ruby-scrypt.gemspec
29
31
  - test/scrypt_test.rb
30
32
  homepage: https://github.com/Timmy72/ruby-scrypt
31
33
  licenses: