viff

changeset 1446:161c652c4ae0

Added authentication codes to share.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Mon, 05 Jul 2010 11:33:57 +0200
parents 67def1bd577b
children cc963bc7ae5e
files viff/bedoza.py viff/test/test_bedoza_runtime.py
diffstat 2 files changed, 5 insertions(+), 208 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza.py	Fri Jul 02 10:21:50 2010 +0200
     1.2 +++ b/viff/bedoza.py	Mon Jul 05 11:33:57 2010 +0200
     1.3 @@ -26,10 +26,10 @@
     1.4  class BeDOZaShare(Share):
     1.5      """A share in the BeDOZa runtime.
     1.6  
     1.7 -    A share in the BeDOZa runtime is a pair ``(x_i, keys)`` of:
     1.8 +    A share in the BeDOZa runtime is a pair ``(x_i, authentication_codes)`` of:
     1.9  
    1.10      - A share of a number, ``x_i``
    1.11 -    - A n-tuple of keys, ``keys``
    1.12 +    - A list of authentication_codes, ``authentication_codes``
    1.13  
    1.14      The :class:`Runtime` operates on shares, represented by this class.
    1.15      Shares are asynchronous in the sense that they promise to attain a
    1.16 @@ -42,10 +42,10 @@
    1.17      that runtime.
    1.18      """
    1.19  
    1.20 -    def __init__(self, runtime, field, value=None, keys=None):
    1.21 +    def __init__(self, runtime, field, value=None, authentication_codes=None):
    1.22          self.share = value
    1.23 -        self.keys = keys
    1.24 -        Share.__init__(self, runtime, field, (value, keys))
    1.25 +        self.authentication_codes = authentication_codes
    1.26 +        Share.__init__(self, runtime, field, (value, authentication_codes))
    1.27  
    1.28  
    1.29  class BeDOZaRuntime(Runtime, HashBroadcastMixin):
     2.1 --- a/viff/test/test_bedoza_runtime.py	Fri Jul 02 10:21:50 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Mon Jul 05 11:33:57 2010 +0200
     2.3 @@ -34,207 +34,4 @@
     2.4  
     2.5      runtime_class = BeDOZaRuntime
     2.6  
     2.7 -    @protocol
     2.8 -    def test_secret_share(self, runtime):
     2.9 -        """Test sharing of random numbers."""
    2.10 -
    2.11 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.12 -
    2.13 -        def check((xi, Ks)):
    2.14 -            # Check that we got the expected number of shares.
    2.15 -            self.assert_type(xi, FieldElement)
    2.16 -            self.assert_type(Ks[0], FieldElement)
    2.17 -            self.assert_type(Ks[1], FieldElement)
    2.18 -            self.assert_type(Ks[2], FieldElement)
    2.19 -
    2.20 -        if 1 == runtime.id:
    2.21 -            share = runtime.secret_share([1], self.Zp, 42)
    2.22 -        else:
    2.23 -            share = runtime.secret_share([1], self.Zp)
    2.24 -        share.addCallback(check)
    2.25 -        return share
    2.26 -
    2.27 -    @protocol
    2.28 -    def test_open_secret_share(self, runtime):
    2.29 -        """Test sharing and open of a number."""
    2.30 -
    2.31 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.32 -
    2.33 -        def check(v):
    2.34 -            self.assertEquals(v, 42)
    2.35 -
    2.36 -        if 1 == runtime.id:
    2.37 -            x = runtime.secret_share([1], self.Zp, 42)
    2.38 -        else:
    2.39 -            x = runtime.secret_share([1], self.Zp)
    2.40 -        d = runtime.open(x)
    2.41 -        d.addCallback(check)
    2.42 -        return d
    2.43 -
    2.44 -    @protocol
    2.45 -    def test_random_share(self, runtime):
    2.46 -        """Test creation of a random shared number."""
    2.47 -
    2.48 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.49 -
    2.50 -        def check(v):
    2.51 -            self.assertEquals(True, True)
    2.52 -
    2.53 -        x = runtime.random_share(self.Zp)
    2.54 -        d = runtime.open(x)
    2.55 -        d.addCallback(check)
    2.56 -        return d
    2.57 -
    2.58 -    @protocol
    2.59 -    def test_sum(self, runtime):
    2.60 -        """Test addition of two numbers."""
    2.61 -
    2.62 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.63 -
    2.64 -        x1 = 42
    2.65 -        y1 = 7
    2.66 -
    2.67 -        def check(v):
    2.68 -            self.assertEquals(v, x1 + y1)
    2.69 -
    2.70 -        if 1 == runtime.id:
    2.71 -            x2 = runtime.secret_share([1], self.Zp, x1)
    2.72 -        else:
    2.73 -            x2 = runtime.secret_share([1], self.Zp)
    2.74 -
    2.75 -        if 3 == runtime.id:
    2.76 -            y2 = runtime.secret_share([3], self.Zp, y1)
    2.77 -        else:
    2.78 -            y2 = runtime.secret_share([3], self.Zp)
    2.79 -
    2.80 -        z2 = runtime.add(x2, y2)
    2.81 -        d = runtime.open(z2)
    2.82 -        d.addCallback(check)
    2.83 -        return d
    2.84 -
    2.85 -    @protocol
    2.86 -    def test_sum_plus(self, runtime):
    2.87 -        """Test addition of two numbers."""
    2.88 -
    2.89 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.90 -
    2.91 -        x1 = 42
    2.92 -        y1 = 7
    2.93 -
    2.94 -        def check(v):
    2.95 -            self.assertEquals(v, x1 + y1)
    2.96 -
    2.97 -        if 1 == runtime.id:
    2.98 -            x2 = runtime.secret_share([1], self.Zp, x1)
    2.99 -        else:
   2.100 -            x2 = runtime.secret_share([1], self.Zp)
   2.101 -
   2.102 -        if 3 == runtime.id:
   2.103 -            y2 = runtime.secret_share([3], self.Zp, y1)
   2.104 -        else:
   2.105 -            y2 = runtime.secret_share([3], self.Zp)
   2.106 -
   2.107 -        z2 = x2 + y2
   2.108 -        d = runtime.open(z2)
   2.109 -        d.addCallback(check)
   2.110 -        return d
   2.111 -
   2.112 -    @protocol
   2.113 -    def test_sum_constant(self, runtime):
   2.114 -        """Test addition of two numbers."""
   2.115 -
   2.116 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
   2.117 -
   2.118 -        x1 = 42
   2.119 -        y1 = 7
   2.120 -
   2.121 -        def check(v):
   2.122 -            self.assertEquals(v, x1 + y1)
   2.123 -
   2.124 -        if 1 == runtime.id:
   2.125 -            x2 = runtime.secret_share([1], self.Zp, x1)
   2.126 -        else:
   2.127 -            x2 = runtime.secret_share([1], self.Zp)
   2.128 -
   2.129 -        z2 = x2 + y1
   2.130 -        d = runtime.open(z2)
   2.131 -        d.addCallback(check)
   2.132 -        return d
   2.133 -
   2.134 -    @protocol
   2.135 -    def test_sub(self, runtime):
   2.136 -        """Test subtration of two numbers."""
   2.137 -
   2.138 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
   2.139 -
   2.140 -        x1 = 42
   2.141 -        y1 = 7
   2.142 -
   2.143 -        def check(v):
   2.144 -            self.assertEquals(v, x1 - y1)
   2.145 -
   2.146 -        if 1 == runtime.id:
   2.147 -            x2 = runtime.secret_share([1], self.Zp, x1)
   2.148 -        else:
   2.149 -            x2 = runtime.secret_share([1], self.Zp)
   2.150 -
   2.151 -        if 3 == runtime.id:
   2.152 -            y2 = runtime.secret_share([3], self.Zp, y1)
   2.153 -        else:
   2.154 -            y2 = runtime.secret_share([3], self.Zp)
   2.155 -
   2.156 -        z2 = runtime.sub(x2, y2)
   2.157 -        d = runtime.open(z2)
   2.158 -        d.addCallback(check)
   2.159 -        return d
   2.160 -
   2.161 -    @protocol
   2.162 -    def test_sub_minus(self, runtime):
   2.163 -        """Test subtration of two numbers."""
   2.164 -
   2.165 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
   2.166 -
   2.167 -        x1 = 42
   2.168 -        y1 = 7
   2.169 -
   2.170 -        def check(v):
   2.171 -            self.assertEquals(v, x1 - y1)
   2.172 -
   2.173 -        if 1 == runtime.id:
   2.174 -            x2 = runtime.secret_share([1], self.Zp, x1)
   2.175 -        else:
   2.176 -            x2 = runtime.secret_share([1], self.Zp)
   2.177 -
   2.178 -        if 3 == runtime.id:
   2.179 -            y2 = runtime.secret_share([3], self.Zp, y1)
   2.180 -        else:
   2.181 -            y2 = runtime.secret_share([3], self.Zp)
   2.182 -
   2.183 -        z2 = x2 - y2
   2.184 -        d = runtime.open(z2)
   2.185 -        d.addCallback(check)
   2.186 -        return d
   2.187 -
   2.188 -    @protocol
   2.189 -    def test_sub_constant(self, runtime):
   2.190 -        """Test subtration of two numbers."""
   2.191 -
   2.192 -        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
   2.193 -
   2.194 -        x1 = 42
   2.195 -        y1 = 7
   2.196 -
   2.197 -        def check(v):
   2.198 -            self.assertEquals(v, x1 - y1)
   2.199 -
   2.200 -        if 1 == runtime.id:
   2.201 -            x2 = runtime.secret_share([1], self.Zp, x1)
   2.202 -        else:
   2.203 -            x2 = runtime.secret_share([1], self.Zp)
   2.204 -
   2.205 -        z2 = x2 - y1
   2.206 -        d = runtime.open(z2)
   2.207 -        d.addCallback(check)
   2.208 -        return d
   2.209 -
   2.210  BeDOZaBasicCommandsTest.skip = "Skipped because the tested code is not implemented."