Skip to content

Commit

Permalink
Move ring parameter from constructor to self_equivalence methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdsn committed Aug 29, 2021
1 parent d3f04f6 commit dd59a43
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 169 deletions.
8 changes: 2 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from argparse import ArgumentParser
from pathlib import Path

from sage.all import GF

from code_generator.bit_packed import BitPackedCodeGenerator
from code_generator.default import DefaultCodeGenerator
from code_generator.inlined import InlinedCodeGenerator
Expand All @@ -18,8 +16,6 @@
from self_equivalences.anf import LinearSelfEquivalenceProvider
from white_box_speck import WhiteBoxSpeck

gf2 = GF(2)

parser = ArgumentParser(description="Generate a white-box Speck implementation using self-equivalence encodings")
parser.add_argument("key", nargs="+", help="the key to use for the Speck implementation, a hexadecimal representation of the words")
parser.add_argument("--block-size", nargs="?", type=int, default=128, choices=[32, 48, 64, 96, 128], help="the block size in bits of the Speck implementation (default: %(default)i)")
Expand All @@ -39,11 +35,11 @@

logging.debug(f"Generating random external encodings...")
if args.self_equivalences == "affine":
self_equivalence_provider = AffineSelfEquivalenceProvider(gf2, word_size)
self_equivalence_provider = AffineSelfEquivalenceProvider(word_size)
input_external_encoding = random_affine_external_encoding(word_size)
output_external_encoding = random_affine_external_encoding(word_size)
else:
self_equivalence_provider = LinearSelfEquivalenceProvider(gf2, word_size)
self_equivalence_provider = LinearSelfEquivalenceProvider(word_size)
input_external_encoding = random_linear_external_encoding(word_size)
output_external_encoding = random_linear_external_encoding(word_size)

Expand Down
7 changes: 3 additions & 4 deletions src/self_equivalences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ class SelfEquivalenceProvider(ABC):
"""

@abstractmethod
def __init__(self, ring, word_size):
def __init__(self, word_size):
"""
Initializes an instance of SelfEquivalenceProvider with the provided parameters.
:param ring: the ring
:param word_size: the word size
"""
self.ring = ring
self.word_size = word_size

@abstractmethod
def random_self_equivalence(self):
def random_self_equivalence(self, ring):
"""
Generates a random self-equivalence of the function S(x, y) = (x + y, y).
:param ring: the ring
:return: a tuple of matrix A, vector a, matrix B, and vector b, such that S = (b o B) o S o (a o A)
"""
pass
Loading

0 comments on commit dd59a43

Please sign in to comment.