Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Luc Libralesso
cryptodag
Commits
a6320b1c
Commit
a6320b1c
authored
Dec 22, 2020
by
Luc Libralesso
Browse files
correct bugs in mixcolumnNode + add tests
parent
5577de89
Changes
4
Hide whitespace changes
Inline
Side-by-side
cryptodag.rb
View file @
a6320b1c
...
...
@@ -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
...
...
nodes/mixcolumn.rb
View file @
a6320b1c
...
...
@@ -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
tests/nodes/exec_mc.rb
0 → 100755
View file @
a6320b1c
#!/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
tests/nodes/exec_s.rb
View file @
a6320b1c
...
...
@@ -9,7 +9,7 @@ require "minitest/autorun"
require
"pry"
class
TestExec
Xor
Node
<
Minitest
::
Unit
::
TestCase
class
TestExec
S
Node
<
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment