lib/noise/state/handshake_state.rb in noise-ruby-0.2.0 vs lib/noise/state/handshake_state.rb in noise-ruby-0.3.0
- old
+ new
@@ -61,10 +61,11 @@
case token
when 'e'
@e = dh_fn.generate_keypair if @e.compact.empty?
message_buffer << @e[1]
@symmetric_state.mix_hash(@e[1])
+ @symmetric_state.mix_key(@e[1]) if @protocol.psk_handshake?
next
when 's'
message_buffer << @symmetric_state.encrypt_and_hash(@s[1])
next
when 'ee'
@@ -85,10 +86,13 @@
end
next
when 'ss'
@symmetric_state.mix_key(dh_fn.dh(@s[0], @rs[1]))
next
+ when 'psk'
+ @symmetric_state.mix_key_and_hash(@protocol.psks.shift)
+ next
end
end
message_buffer << @symmetric_state.encrypt_and_hash(payload)
@symmetric_state.split if @message_patterns.empty?
end
@@ -101,10 +105,11 @@
case token
when 'e'
@re = @protocol.dh_fn.class.from_public(message[0...len]) if @re.compact.empty?
message = message[len..-1]
@symmetric_state.mix_hash(@re[1])
+ @symmetric_state.mix_key(@re[1]) if @protocol.psk_handshake?
next
when 's'
offset = @protocol.cipher_state_handshake.key? ? 16 : 0
temp = message[0...len + offset]
message = message[(len + offset)..-1]
@@ -127,9 +132,12 @@
@symmetric_state.mix_key(dh_fn.dh(@e[0], @rs[1]))
end
next
when 'ss'
@symmetric_state.mix_key(dh_fn.dh(@s[0], @rs[1]))
+ next
+ when 'psk'
+ @symmetric_state.mix_key_and_hash(@protocol.psks.shift)
next
end
end
payload_buffer << @symmetric_state.decrypt_and_hash(message)
@symmetric_state.split if @message_patterns.empty?