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
a6759aad
Commit
a6759aad
authored
Dec 24, 2020
by
Luc Libralesso
Browse files
correct execution errors for midori128 ; outputs do not match initialization vectors
parent
5a14bd71
Changes
9
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a6759aad
...
...
@@ -58,3 +58,9 @@ dot -T png tmp/test.dot -o test.png
-
[ ] SKINNY implementation
-
[ ] spark implementation
-
[ ] DAGviz : hypergraph representation
# TODO (refactor)
-
[ ] InputNode with constant (use DTable constant set-up instead of inserting directly into each element: nodes/input.rb)
\ No newline at end of file
constraints/tables.rb
View file @
a6759aad
...
...
@@ -157,6 +157,7 @@ end
# A table variable whose instanciation type is dynamic
class
DynamicVariable
<
Variable
attr_reader
:indexes
,
:table
attr_accessor
:value
# TODO(all) remove this after refactoring of DTable
def
initialize
(
table
,
indexes
,
*
params
)
@table
=
table
...
...
cryptodag.rb
View file @
a6759aad
...
...
@@ -60,11 +60,21 @@ class CryptoOperator
protected
def
check_inputs
(
values
)
raise
"CryptoOperator.check_inputs: values do not match (
#{
@values
.
length
}
should be
#{
@inputs
.
length
}
)"
unless
values
.
length
==
@inputs
.
length
for
e
in
values
if
e
==
nil
raise
"CryptoOperator.check_inputs: values contain some nil:
#{
values
}
"
end
end
# TODO(all) check domains
end
protected
def
check_outputs
(
values
)
raise
"CryptoOperator.check_outputs: values do not match (
#{
@values
.
length
}
should be
#{
@outputs
.
length
}
)"
unless
values
.
length
==
@outputs
.
length
for
e
in
values
if
e
==
nil
raise
"CryptoOperator.check_outputs: values contain some nil:
#{
values
}
"
end
end
# TODO(all) check domains
end
...
...
@@ -128,5 +138,5 @@ class CryptoDag
@nodes
=
nodes
end
end
\ No newline at end of file
cryptosystems/midori128/constants.rb
View file @
a6759aad
...
...
@@ -5,79 +5,80 @@
def
subcell_mat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b7
,
0xae
,
0xa7
,
0xfd
,
0x9c
,
0x6d
,
0x0c
,
0xff
,
0x9e
,
0xef
,
0x8e
,
0xb8
,
0xb1
,
0x38
,
0x31
,
0xa8
,
0xa1
,
0xac
,
0xa5
,
0xf9
,
0x98
,
0x79
,
0x18
,
0xe9
,
0x88
,
0xed
,
0x8c
,
0xf4
,
0xf5
,
0x64
,
0x65
,
0xf6
,
0xf7
,
0xe6
,
0xe7
,
0xfc
,
0xdc
,
0x6c
,
0x4c
,
0xfe
,
0xde
,
0xee
,
0xce
,
0xf0
,
0xf1
,
0x70
,
0x71
,
0xe0
,
0xe1
,
0xe4
,
0xe5
,
0xf8
,
0xd8
,
0x78
,
0x58
,
0xe8
,
0xc8
,
0xec
,
0xcc
]
end
end
...
...
cryptosystems/midori128/midori128.rb
View file @
a6759aad
...
...
@@ -3,6 +3,7 @@
require_relative
'./constants.rb'
require_relative
'../../cryptodag.rb'
require_relative
'../../simulate_cryptodag.rb'
require_relative
'../../nodes/input.rb'
require_relative
'../../nodes/indexedsubbytes.rb'
...
...
@@ -10,15 +11,6 @@ require_relative '../../nodes/shufflecell.rb'
require_relative
'../../nodes/mixcolumn.rb'
require_relative
'../../nodes/xor.rb'
# require_relative '../../cryptonodes/input.rb'
# require_relative '../../cryptonodes/constant.rb'
# require_relative '../../cryptonodes/output.rb'
# require_relative '../../cryptonodes/keyseparation.rb'
# require_relative '../../cryptonodes/xor.rb'
# require_relative '../../cryptonodes/subcell.rb'
# require_relative '../../cryptonodes/shufflecell.rb'
# require_relative '../../cryptonodes/mixcolumn.rb'
class
Midori128_Dag
<
CryptoDag
...
...
@@ -59,6 +51,21 @@ class Midori128_Dag < CryptoDag
super
([
@x
,
@k
],
[
out_xor
],
nodes
)
end
##
# @param x [2DVec<u8>] input message
# @param k [2DVec<u8>] input key
# @returns [2DVec<u8>] crypted message
def
simulate_behavior
(
x
,
k
)
computed_outputs
=
compute_set_of_operators
(
x
.
flatten
()
+
k
.
flatten
(),
# input values
@x
.
flatten_output
(
0
)
+
@k
.
flatten_output
(
0
),
# input variables
@output_nodes
[
0
].
flatten_output
(
0
),
# output variables
@nodes
.
map
{
|
n
|
n
.
operators
}.
reduce
([],
:
+
)
)
return
computed_outputs
end
# def simulate_behavior(x,k)
# # simulates constants
# for i in 0..@nb_rounds-2 do
...
...
nodes/input.rb
View file @
a6759aad
...
...
@@ -12,7 +12,19 @@ class InputNode < CryptoDagNode
# @param values [ Array ] : values of the variable
def
initialize
(
name
:,
type:
0
..
255
,
dimensions
:,
values:
nil
)
# create output variables
output
=
DTable
.
new
(
name
,
type
,
dimensions
,
values
)
output
=
DTable
.
new
(
name
,
type
,
dimensions
,
values
,
constant
:(
values!
=
nil
))
# output.declarationMode = :unfolded
# if name == "Cst_1"
# p output
# end
if
values
!=
nil
dimensions
[
0
].
times
do
|
i
|
dimensions
[
1
].
times
do
|
j
|
output
[
i
][
j
].
value
=
values
[
i
][
j
]
end
end
end
super
(
inputs:
[],
outputs:
[
output
],
operators:
[],
name:
name
)
end
end
operators/elementary.rb
View file @
a6759aad
...
...
@@ -145,6 +145,8 @@ end
## Galois Field multiplication (a.b)
# @return a.b
def
g_mul
(
a
,
b
)
raise
"g_mul: a is nil"
unless
a
!=
nil
raise
"g_mul: b is nil"
unless
b
!=
nil
p
=
0
8
.
times
do
|
counter
|
if
(
b
&
1
)
!=
0
...
...
simulate_cryptodag.rb
View file @
a6759aad
...
...
@@ -41,7 +41,11 @@ def compute_set_of_operators(input_values, input_variables, output_variables, op
end
end
end
for
k
in
value_map
.
keys
if
value_map
[
k
]
==
nil
raise
"simulate_cryptodag: ERROR value_map contains a nil value"
end
end
dg
=
RGL
::
DirectedAdjacencyGraph
[
*
adj_list
]
sorted_vertices
=
dg
.
topsort_iterator
.
to_a
sorted_vertices
=
sorted_vertices
.
filter
{
|
v
|
v
.
class
<=
CryptoOperator
}
...
...
@@ -57,7 +61,9 @@ def compute_set_of_operators(input_values, input_variables, output_variables, op
raise
"compute_set_of_operators: bad topological sort (variable
#{
e
}
should be computed)"
end
end
# p "op:#{op.class} input values: #{values}"
outputs
=
op
.
compute
(
values
)
# p "op:#{op.class} output values: #{outputs}"
outputs
.
length
.
times
do
|
i
|
if
!
value_map
.
include?
(
op
.
outputs
[
i
])
value_map
[
op
.
outputs
[
i
]]
=
outputs
[
i
]
...
...
tests/cryptosystems/midori128.rb
View file @
a6759aad
...
...
@@ -7,27 +7,27 @@ require_relative "../../cryptosystems/midori128/midori128.rb"
class
TestMidori128
<
Minitest
::
Unit
::
TestCase
def
test_construction
()
# create DAG
dag
=
Midori128_Dag
.
new
(
nb_rounds
=
3
)
dag
=
Midori128_Dag
.
new
()
# # simulate behavior
#
output = dag.simulate_behavior(
#
[
#
[0x51,0xe7,0xec,0xbc],
#
[0x08,0x3a,0x87,0x29],
#
[0x4c,0x5c,0xd7,0x75],
#
[0xe6,0xa2,0xba,0x43]
#
],
#
[
#
[0x68,0x3c,0x5b,0x3e],
#
[0x7d,0x85,0x10,0x2a],
#
[0xed,0xb3,0x09,0x8c],
#
[0x3b,0xf3,0x86,0xbf]
#
]
#
)
#
assert_equal(output, [
#
[
0x1e, 0xdf, 0x18, 0xe4
]
,
#
[
0x0a, 0xf7, 0x01, 0xaf
]
,
#
[
0xc4, 0x1b, 0xb7, 0xc8
]
,
#
[
0xfd, 0x4c, 0x3e, 0x3d
]
#
])
output
=
dag
.
simulate_behavior
(
[
[
0x51
,
0xe7
,
0xec
,
0xbc
],
[
0x08
,
0x3a
,
0x87
,
0x29
],
[
0x4c
,
0x5c
,
0xd7
,
0x75
],
[
0xe6
,
0xa2
,
0xba
,
0x43
]
],
[
[
0x68
,
0x3c
,
0x5b
,
0x3e
],
[
0x7d
,
0x85
,
0x10
,
0x2a
],
[
0xed
,
0xb3
,
0x09
,
0x8c
],
[
0x3b
,
0xf3
,
0x86
,
0xbf
]
]
)
assert_equal
(
output
,
[
0x1e
,
0xdf
,
0x18
,
0xe4
,
0x0a
,
0xf7
,
0x01
,
0xaf
,
0xc4
,
0x1b
,
0xb7
,
0xc8
,
0xfd
,
0x4c
,
0x3e
,
0x3d
])
end
end
\ No newline at end of file
Write
Preview
Supports
Markdown
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