Commit a6320b1c authored by Luc Libralesso's avatar Luc Libralesso
Browse files

correct bugs in mixcolumnNode + add tests

parent 5577de89
......@@ -59,6 +59,10 @@ class CryptoOperator
protected def check_inputs(values)
# puts "###"
# p @inputs
# p values
# puts "==="
raise "CryptoOperator.check_inputs: values do not match (#{@values.length} should be #{@inputs.length})" unless values.length == @inputs.length
# TODO(all) check domains
end
......
......@@ -7,9 +7,14 @@ class MixColumnNode < CryptoDagNode
def initialize(name:, input:, m:)
output = DTable.new("#{name}", input.type, input.dimensions)
@m = m
operators = [
MixColumnsOperator.new(input, output, m),
]
operators = []
input.dimensions[1].times do |x|
operators.push(MixColumnsOperator.new(
input.dimensions[0].times.map{|y| input[y][x]},
output.dimensions[0].times.map{|y| output[y][x]},
m
))
end
super(inputs: [input], outputs: [output], operators: operators, name: name)
end
end
#!/usr/bin/ruby
## test XorNode
require_relative "../../nodes/input.rb"
require_relative "../../nodes/mixcolumn.rb"
require_relative "../../simulate_cryptodag.rb"
require "minitest/autorun"
require "pry"
class TestExecSNode < Minitest::Unit::TestCase
def test_simple22s()
a_node = InputNode.new(name:"input_a",dimensions:[4,4])
mc_node = MixColumnNode.new(name:"mc", input:a_node.outputs[0], m:[
[2,3,1,1],
[1,2,3,1],
[1,1,2,3],
[3,1,1,2],
]) # AES mix columns
computed_outputs = compute_set_of_operators(
[
0, 1, 219 ,242,
0, 1, 19 ,10,
0, 1, 83 ,34,
0, 1, 69 ,92
].flatten, # input values
a_node.flatten_output(0), # input variables
mc_node.flatten_output(0), # output variables
mc_node.operators
)
assert_equal(computed_outputs, [
0, 1, 142 ,159,
0, 1, 77 ,220,
0, 1, 161 ,88,
0, 1, 188 ,157,
].flatten)
end
end
\ No newline at end of file
......@@ -9,7 +9,7 @@ require "minitest/autorun"
require "pry"
class TestExecXorNode < Minitest::Unit::TestCase
class TestExecSNode < Minitest::Unit::TestCase
def test_simple22s()
subtable_1 = 256.times.map{|i|(i*2) % 256}.to_a
subtable_2 = 256.times.map{|i|(i+1) % 256}.to_a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment