sha512t 0.0.2 → 0.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.
- checksums.yaml +4 -4
- data/lib/sha512.rb +10 -37
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b00ec75a952b8e835cd734ba306841e2e8816b3f
|
4
|
+
data.tar.gz: cebcb2b1aa7246a1a52e7f3eadf2bd338061bd91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df627c2249fb3685ab277ffa5f9bf8b76fc09454a42a3ae6fd6c984086730ce9a9cfd5023ff06a5a17fffc3256aea62027ed375be50ec3df344a9e1b70ad607e
|
7
|
+
data.tar.gz: 4ec1836c8022c5340d02be78a7c372e8d27745a07dc4a69642aaaad15dcb7e2e9572b64ea08d895ebcc894999fed49b3e72fe3ff049d82d14d529737e2d0b001
|
data/lib/sha512.rb
CHANGED
@@ -41,44 +41,21 @@ class Sha512
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def preprocessing(message)
|
44
|
-
# Preprocessing Step 1: Padding the message
|
45
|
-
|
46
|
-
|
47
|
-
padded_message = ""
|
48
|
-
zero = "0"
|
49
|
-
|
50
|
-
bytes.each do |byte|
|
51
|
-
bit = byte.to_s(2)
|
52
|
-
if bit.length < 8
|
53
|
-
bit = (zero * (8 - bit.length)) + bit
|
54
|
-
end
|
55
|
-
padded_message += bit
|
56
|
-
end
|
44
|
+
# Preprocessing Step 1: Padding the message
|
45
|
+
preprocessed_message = message.unpack('B*')[0]
|
46
|
+
message_length = preprocessed_message.length
|
57
47
|
|
58
48
|
# padding with a one bit
|
59
|
-
|
49
|
+
preprocessed_message += "1"
|
60
50
|
|
61
51
|
# add k zero bits, where k is the smallest non-negative solution to the equation l+1+k = 896 mod 1024
|
62
|
-
|
63
|
-
while blocks < 0 do
|
64
|
-
blocks += 1024
|
65
|
-
end
|
66
|
-
padded_message += zero * blocks
|
52
|
+
preprocessed_message += "0" * ((896-(message_length+1)) % 1024)
|
67
53
|
|
68
54
|
# append 128-bit block that is equal to the number of l expressed using a binary representation
|
69
|
-
|
70
|
-
if last_bit_block.length < 128
|
71
|
-
last_bit_block = (zero * (128 - last_bit_block.length)) + last_bit_block
|
72
|
-
end
|
73
|
-
padded_message += last_bit_block
|
55
|
+
preprocessed_message += message_length.to_s(2).rjust(128, '0')
|
74
56
|
|
75
57
|
# Preprocessing Step 2: Parsing the message
|
76
|
-
|
77
|
-
for block in 0..padded_message.size/64-1
|
78
|
-
parsed_message.push(padded_message[(64*block)..(64*block)+63])
|
79
|
-
end
|
80
|
-
|
81
|
-
return parsed_message
|
58
|
+
return preprocessed_message.chars.each_slice(64).map(&:join)
|
82
59
|
end
|
83
60
|
|
84
61
|
def hash_computation(p, iv)
|
@@ -139,11 +116,7 @@ class Sha512
|
|
139
116
|
# Convert hash to hex-String
|
140
117
|
hash_string = ""
|
141
118
|
hash.each do |h|
|
142
|
-
|
143
|
-
if temp.length < 16
|
144
|
-
temp = "0" * (16 - temp.length) + temp
|
145
|
-
end
|
146
|
-
hash_string += temp
|
119
|
+
hash_string += h.to_s(16).rjust(16, '0')
|
147
120
|
end
|
148
121
|
return hash_string
|
149
122
|
end
|
@@ -165,9 +138,9 @@ class Sha512
|
|
165
138
|
# consists of two steps:
|
166
139
|
# 1. padding the message,
|
167
140
|
# 2. parsing the message into message blocks
|
168
|
-
|
141
|
+
preprocessed_massage = Sha512.new.preprocessing(message)
|
169
142
|
|
170
143
|
# Hash Computation
|
171
|
-
return Sha512.new.hash_computation(
|
144
|
+
return Sha512.new.hash_computation(preprocessed_massage, sha512_initial_hash_value)
|
172
145
|
end
|
173
146
|
end
|
metadata
CHANGED