crypto-lite 0.0.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +7 -0
- data/README.md +491 -0
- data/Rakefile +5 -1
- data/lib/crypto-lite.rb +113 -48
- data/lib/crypto-lite/config.rb +32 -0
- data/lib/crypto-lite/helper.rb +25 -0
- data/lib/crypto-lite/metal.rb +128 -0
- data/lib/crypto-lite/sign_rsa.rb +29 -0
- data/lib/crypto-lite/version.rb +2 -2
- data/test/test_base58.rb +36 -0
- data/test/test_bitcoin_addr.rb +58 -0
- data/test/test_hash.rb +24 -55
- data/test/test_hash_sha.rb +87 -0
- metadata +55 -6
@@ -0,0 +1,58 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_bitcoin_addr.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestBitcoinAddr < MiniTest::Test
|
9
|
+
|
10
|
+
|
11
|
+
def test_bitcoin_addr_v1
|
12
|
+
pk = "0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352"
|
13
|
+
|
14
|
+
step1 = sha256( pk )
|
15
|
+
assert_equal "0b7c28c9b7290c98d7438e70b3d3f7c848fbd7d1dc194ff83f4f7cc9b1378e98",
|
16
|
+
step1
|
17
|
+
|
18
|
+
step2 = ripemd160( step1 )
|
19
|
+
assert_equal "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31",
|
20
|
+
step2
|
21
|
+
|
22
|
+
step3 = "00" + step2
|
23
|
+
assert_equal "00f54a5851e9372b87810a8e60cdd2e7cfd80b6e31",
|
24
|
+
step3
|
25
|
+
|
26
|
+
step4 = sha256( step3 )
|
27
|
+
assert_equal "ad3c854da227c7e99c4abfad4ea41d71311160df2e415e713318c70d67c6b41c",
|
28
|
+
step4
|
29
|
+
|
30
|
+
step5 = sha256( step4 )
|
31
|
+
assert_equal "c7f18fe8fcbed6396741e58ad259b5cb16b7fd7f041904147ba1dcffabf747fd",
|
32
|
+
step5
|
33
|
+
|
34
|
+
step6 = step5[0..7] # note: 4 bytes in hex string are 8 digits/chars
|
35
|
+
assert_equal "c7f18fe8", step6
|
36
|
+
|
37
|
+
step7 = step3 + step6
|
38
|
+
assert_equal "00f54a5851e9372b87810a8e60cdd2e7cfd80b6e31c7f18fe8", step7
|
39
|
+
|
40
|
+
addr = base58( step7 )
|
41
|
+
assert_equal "1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs", addr
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def test_bitcoin_addr_v2
|
46
|
+
pk = "0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352"
|
47
|
+
|
48
|
+
step1 = hash160( pk )
|
49
|
+
assert_equal "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31", step1
|
50
|
+
|
51
|
+
step2 = "00" + step1
|
52
|
+
assert_equal "00f54a5851e9372b87810a8e60cdd2e7cfd80b6e31", step2
|
53
|
+
|
54
|
+
addr = base58check( step2 )
|
55
|
+
assert_equal "1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs", addr
|
56
|
+
end
|
57
|
+
|
58
|
+
end # class TestBitcoinAddr
|
data/test/test_hash.rb
CHANGED
@@ -8,71 +8,40 @@ require 'helper'
|
|
8
8
|
|
9
9
|
class TestHash < MiniTest::Test
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
SHA256_HELLO_CRYPTOS = '33eedea60b0662c66c289ceba71863a864cf84b00e10002ca1069bf58f9362d5'
|
11
|
+
KECCAK256_TESTS = [
|
12
|
+
['', 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'],
|
13
|
+
['testing', '5f16f4c7f149ac4f9510d9cf8cf384038ad348b3bcdc01915f95de12df9d1b02'],
|
14
|
+
['Hello, Cryptos!', '2cf14baa817e931f5cc2dcb63c889619d6b7ae0794fc2223ebadf8e672c776f5'],
|
15
|
+
]
|
17
16
|
|
17
|
+
SHA3_256_TESTS = [
|
18
|
+
['', 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a'],
|
19
|
+
['Hello, Cryptos!', '7dddf4bc9b86352b67e8823e5010ddbd2a90a854469e2517992ca7ca89e5bd58'],
|
20
|
+
]
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_abc
|
25
|
-
['abc',
|
26
|
-
'abc'.b,
|
27
|
-
"\x61\x62\x63",
|
28
|
-
0x616263
|
29
|
-
].each do |input|
|
30
|
-
assert_equal SHA256_ABC, sha256( input )
|
31
|
-
assert_equal SHA256_ABC, sha256( input, :openssl )
|
32
|
-
end
|
22
|
+
RIPEMD160_TESTS = [
|
23
|
+
['Hello, Cryptos!', '4d65f7b740bbade4097e1348e15d2a7d52ac5f53'],
|
24
|
+
]
|
33
25
|
|
34
|
-
['616263',
|
35
|
-
'0x616263',
|
36
|
-
'0X616263'
|
37
|
-
].each do |input|
|
38
|
-
assert_equal SHA256_ABC, sha256hex( input )
|
39
|
-
end
|
40
|
-
## pp sha256hex( 'hello' ) -- fails - uses non-hex chars
|
41
|
-
|
42
|
-
# a = dec (97), hex (61), bin (01100001)
|
43
26
|
|
44
|
-
[ 'a',
|
45
|
-
"\x61",
|
46
|
-
0b01100001,
|
47
|
-
0x61
|
48
|
-
].each do |input|
|
49
|
-
assert_equal SHA256_A, sha256( input )
|
50
|
-
assert_equal SHA256_A, sha256( input, :openssl )
|
51
|
-
end
|
52
27
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
28
|
+
def test_keccak256
|
29
|
+
KECCAK256_TESTS.each do |item|
|
30
|
+
assert_equal item[1], keccak256( item[0].b )
|
31
|
+
end
|
32
|
+
end
|
59
33
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
assert_equal SHA256_B, sha256( input )
|
34
|
+
def test_sha3_256
|
35
|
+
SHA3_256_TESTS.each do |item|
|
36
|
+
assert_equal item[1], sha3_256( item[0].b )
|
64
37
|
end
|
38
|
+
end
|
65
39
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
assert_equal SHA256_C, sha256( input )
|
40
|
+
def test_ripemd160
|
41
|
+
RIPEMD160_TESTS.each do |item|
|
42
|
+
assert_equal item[1], ripemd160( item[0].b )
|
70
43
|
end
|
71
44
|
end
|
72
45
|
|
73
46
|
|
74
|
-
def test_misc
|
75
|
-
assert_equal SHA256_HELLO_CRYPTOS, sha256( 'Hello, Cryptos!' )
|
76
|
-
end
|
77
|
-
|
78
47
|
end # class TestHash
|
@@ -0,0 +1,87 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_hash_sha.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
|
9
|
+
class TestHashSha < MiniTest::Test
|
10
|
+
|
11
|
+
SHA256_ABC = 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
|
12
|
+
SHA256_A = 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'
|
13
|
+
SHA256_B = '3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d'
|
14
|
+
SHA256_C = '2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6'
|
15
|
+
|
16
|
+
|
17
|
+
BIN_TESTS = [
|
18
|
+
['', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'],
|
19
|
+
['Hello, Cryptos!', '33eedea60b0662c66c289ceba71863a864cf84b00e10002ca1069bf58f9362d5'],
|
20
|
+
|
21
|
+
['Blockchain 1', '223aae3830e87aff41db07714983671429a74fb7064646e27ab62adbdc892cd1'],
|
22
|
+
['Blockchain 2', '8f4b5a896e78f680de2c141d25533e8c9207c9ee0d9b09c22a5a01d7992e7d1b'],
|
23
|
+
['Blockchain 3', 'f9f5e7d64f3a93f071900a73d34b2b722867adcb09345a21a25b5cd7f8b41254'],
|
24
|
+
['Blockchain 4', '69580cfb9a134395106ac27de53595cc41fb9940dcc298082c87144932a983a9'],
|
25
|
+
['Blockchain 12', 'f94455d34e7b32dc7dac780fb94a5e958f0d7e2da4cc6500505d5daed719c227'],
|
26
|
+
['Blockchain 13', '0cedb5e229c9582a35ec291ccb172b3f7c76a20c7f645e08d24ece8d5692e153'],
|
27
|
+
]
|
28
|
+
|
29
|
+
|
30
|
+
def test_bin
|
31
|
+
BIN_TESTS.each do |item|
|
32
|
+
assert_equal item[1], sha256( item[0].b )
|
33
|
+
assert_equal item[1], sha256( item[0].b, engine: 'openssl' )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_abc
|
39
|
+
['abc',
|
40
|
+
'abc'.b,
|
41
|
+
"\x61\x62\x63",
|
42
|
+
0x616263
|
43
|
+
].each do |input|
|
44
|
+
assert_equal SHA256_ABC, sha256( input )
|
45
|
+
assert_equal SHA256_ABC, sha256( input, engine: 'openssl' )
|
46
|
+
end
|
47
|
+
|
48
|
+
['616263',
|
49
|
+
'0x616263',
|
50
|
+
'0X616263'
|
51
|
+
].each do |input|
|
52
|
+
assert_equal SHA256_ABC, sha256( hex: input )
|
53
|
+
end
|
54
|
+
## pp sha256hex( 'hello' ) -- fails - uses non-hex chars
|
55
|
+
|
56
|
+
# a = dec (97), hex (61), bin (01100001)
|
57
|
+
|
58
|
+
[ 'a',
|
59
|
+
"\x61",
|
60
|
+
0b01100001,
|
61
|
+
0x61
|
62
|
+
].each do |input|
|
63
|
+
assert_equal SHA256_A, sha256( input )
|
64
|
+
assert_equal SHA256_A, sha256( input, engine: 'openssl' )
|
65
|
+
end
|
66
|
+
|
67
|
+
['61',
|
68
|
+
'0x61',
|
69
|
+
'0X61'
|
70
|
+
].each do |input|
|
71
|
+
assert_equal SHA256_A, sha256( hex: input )
|
72
|
+
end
|
73
|
+
|
74
|
+
[ 'b',
|
75
|
+
0b01100010
|
76
|
+
].each do |input|
|
77
|
+
assert_equal SHA256_B, sha256( input )
|
78
|
+
end
|
79
|
+
|
80
|
+
[ 'c',
|
81
|
+
0b01100011
|
82
|
+
].each do |input|
|
83
|
+
assert_equal SHA256_C, sha256( input )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end # class TestHashSha
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypto-lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: digest-sha3-patched
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: base32-alphabets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: base58-alphabets
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: rdoc
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,8 +86,8 @@ dependencies:
|
|
44
86
|
- - "~>"
|
45
87
|
- !ruby/object:Gem::Version
|
46
88
|
version: '3.22'
|
47
|
-
description: crypto-lite -
|
48
|
-
|
89
|
+
description: crypto-lite - cryptographic secure hash functions and public key signature
|
90
|
+
algorithms made easy
|
49
91
|
email: wwwmake@googlegroups.com
|
50
92
|
executables: []
|
51
93
|
extensions: []
|
@@ -59,11 +101,18 @@ files:
|
|
59
101
|
- README.md
|
60
102
|
- Rakefile
|
61
103
|
- lib/crypto-lite.rb
|
104
|
+
- lib/crypto-lite/config.rb
|
105
|
+
- lib/crypto-lite/helper.rb
|
106
|
+
- lib/crypto-lite/metal.rb
|
107
|
+
- lib/crypto-lite/sign_rsa.rb
|
62
108
|
- lib/crypto-lite/version.rb
|
63
109
|
- lib/crypto.rb
|
64
110
|
- lib/crypto/lite.rb
|
65
111
|
- test/helper.rb
|
112
|
+
- test/test_base58.rb
|
113
|
+
- test/test_bitcoin_addr.rb
|
66
114
|
- test/test_hash.rb
|
115
|
+
- test/test_hash_sha.rb
|
67
116
|
- test/test_version.rb
|
68
117
|
homepage: https://github.com/rubycoco/blockchain
|
69
118
|
licenses:
|
@@ -89,6 +138,6 @@ requirements: []
|
|
89
138
|
rubygems_version: 3.1.4
|
90
139
|
signing_key:
|
91
140
|
specification_version: 4
|
92
|
-
summary: crypto-lite -
|
93
|
-
|
141
|
+
summary: crypto-lite - cryptographic secure hash functions and public key signature
|
142
|
+
algorithms made easy
|
94
143
|
test_files: []
|