Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
ff48a66b
Commit
ff48a66b
authored
Jul 14, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement the watermarker using operands swapping method
parent
0d6a8dfd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
23 deletions
+128
-23
OperandSwappingWatermarker.cpp
src/kyut/watermarker/OperandSwappingWatermarker.cpp
+17
-5
test_OperandSwappingWatermarker.cpp
test/kyut/watermarker/test_OperandSwappingWatermarker.cpp
+111
-18
No files found.
src/kyut/watermarker/OperandSwappingWatermarker.cpp
View file @
ff48a66b
...
...
@@ -423,13 +423,25 @@ namespace kyut::watermarker {
return
(
std
::
max
)(
embedExpression
(
expr
.
left
,
stream
),
embedExpression
(
expr
.
right
,
stream
));
}
// TODO: implement watermarking
const
auto
leftSideEffect
=
embedExpression
(
expr
.
left
,
stream
);
const
auto
rightSideEffect
=
embedExpression
(
expr
.
right
,
stream
);
// Sort both of the operands
auto
[
lo
,
hi
]
=
std
::
minmax
(
expr
.
left
,
expr
.
right
,
[](
auto
a
,
auto
b
)
{
return
*
a
<
*
b
;
});
(
void
)
swapOperands
;
const
auto
loEffect
=
embedExpression
(
lo
,
stream
);
const
auto
hiEffect
=
embedExpression
(
hi
,
stream
);
return
(
std
::
max
)(
leftSideEffect
,
rightSideEffect
);
if
(
static_cast
<
std
::
uint32_t
>
(
loEffect
)
+
static_cast
<
std
::
uint32_t
>
(
hiEffect
)
>=
3
)
{
// The operands have side effect and cannot be swapped
return
(
std
::
max
)(
loEffect
,
hiEffect
);
}
// Embed watermarks by swapping operands
const
bool
bit
=
stream
.
readBit
();
if
(
bit
==
(
expr
.
left
==
lo
))
{
swapOperands
(
expr
);
}
return
(
std
::
max
)(
loEffect
,
hiEffect
);
}
SideEffect
embedSelect
(
wasm
::
Select
&
expr
,
CircularBitStreamReader
&
stream
)
{
...
...
test/kyut/watermarker/test_OperandSwappingWatermarker.cpp
View file @
ff48a66b
...
...
@@ -14,7 +14,7 @@
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
watermarker
)
BOOST_AUTO_TEST_CASE
(
embed_operand_swapping
)
{
BOOST_AUTO_TEST_CASE
(
embed_operand_swapping
_000000
)
{
wasm
::
Module
module
;
wasm
::
ModuleReader
{}.
read
(
KYUT_TEST_SOURCE_DIR
"/example/test2.wast"
,
module
);
...
...
@@ -24,24 +24,117 @@ BOOST_AUTO_TEST_CASE(embed_operand_swapping) {
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"f3"
);
// Embed 0b0000'00
CircularBitStreamReader
s
{{
0
b0000
'
0000
}};
const
auto
numBitsEmbedded
=
embedOperandSwapping
(
module
,
s
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
3
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"f3"
);
// f1
{
const
auto
body
=
module
.
functions
[
0
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
BOOST_REQUIRE_EQUAL
(
body
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
}
// f2
{
const
auto
body
=
module
.
functions
[
1
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
3
);
const
auto
r
=
body
->
right
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
r
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
r
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
BOOST_REQUIRE_EQUAL
(
r
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
}
// f3
{
const
auto
body
=
module
.
functions
[
2
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
is
<
wasm
::
Binary
>
(),
true
);
BOOST_REQUIRE_EQUAL
(
body
->
right
->
is
<
wasm
::
Binary
>
(),
true
);
const
auto
l
=
body
->
left
->
cast
<
wasm
::
Binary
>
();
const
auto
r
=
body
->
right
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
l
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
l
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
BOOST_REQUIRE_EQUAL
(
l
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
BOOST_REQUIRE_EQUAL
(
r
->
op
,
wasm
::
GtSInt32
);
BOOST_REQUIRE_EQUAL
(
r
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
3
);
BOOST_REQUIRE_EQUAL
(
r
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
4
);
}
}
BOOST_AUTO_TEST_CASE
(
embed_operand_swapping_110111
)
{
wasm
::
Module
module
;
wasm
::
ModuleReader
{}.
read
(
KYUT_TEST_SOURCE_DIR
"/example/test2.wast"
,
module
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
3
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"f3"
);
// Embed 0b1101'11
CircularBitStreamReader
s
{{
0
b1101
'
1100
}};
const
auto
numBitsEmbedded
=
embedOperandSwapping
(
module
,
s
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
3
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"f3"
);
// f1
{
CircularBitStreamReader
s
{{
0
b0000
'
0000
}};
const
auto
numBitsEmbedded
=
embedOperandSwapping
(
module
,
s
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
6
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
.
size
(),
std
::
size_t
{
3
});
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
0
]
->
name
,
"f1"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"f2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"f3"
);
// f1
{
const
auto
bin
=
module
.
functions
[
0
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
bin
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
BOOST_REQUIRE_EQUAL
(
bin
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
}
const
auto
body
=
module
.
functions
[
0
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
BOOST_REQUIRE_EQUAL
(
body
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
}
// f2
{
const
auto
body
=
module
.
functions
[
1
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
3
);
const
auto
r
=
body
->
right
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
r
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
r
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
BOOST_REQUIRE_EQUAL
(
r
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
}
// f3
{
const
auto
body
=
module
.
functions
[
2
]
->
body
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
body
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
body
->
left
->
is
<
wasm
::
Binary
>
(),
true
);
BOOST_REQUIRE_EQUAL
(
body
->
right
->
is
<
wasm
::
Binary
>
(),
true
);
const
auto
l
=
body
->
left
->
cast
<
wasm
::
Binary
>
();
const
auto
r
=
body
->
right
->
cast
<
wasm
::
Binary
>
();
BOOST_REQUIRE_EQUAL
(
l
->
op
,
wasm
::
LtSInt32
);
BOOST_REQUIRE_EQUAL
(
l
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
4
);
BOOST_REQUIRE_EQUAL
(
l
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
3
);
BOOST_REQUIRE_EQUAL
(
r
->
op
,
wasm
::
AddInt32
);
BOOST_REQUIRE_EQUAL
(
r
->
left
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
2
);
BOOST_REQUIRE_EQUAL
(
r
->
right
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
(),
1
);
}
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
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