viff

changeset 1146:ecd0f77f5243

Cache PRFs.
author Marcel Keller <mkeller@cs.au.dk>
date Wed, 25 Feb 2009 17:16:38 +0100
parents 58576bfc42e8
children 5ac7a2c23337
files viff/config.py
diffstat 1 files changed, 20 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/viff/config.py	Wed Feb 25 15:39:34 2009 +0100
     1.2 +++ b/viff/config.py	Wed Feb 25 17:16:38 2009 +0100
     1.3 @@ -49,6 +49,8 @@
     1.4          self.seckey = seckey
     1.5          self.keys = keys
     1.6          self.dealer_keys = dealer_keys
     1.7 +        self.prfs_cache = {}
     1.8 +        self.dealers_cache = {}
     1.9  
    1.10      def prfs(self, modulus):
    1.11          """Retrieve PRSS PRFs.
    1.12 @@ -60,10 +62,15 @@
    1.13          Return a mapping from player subsets to :class:`viff.prss.PRF`
    1.14          instances.
    1.15          """
    1.16 -        prfs = {}
    1.17 -        for subset, key in self.keys.iteritems():
    1.18 -            prfs[subset] = PRF(key, modulus)
    1.19 +        if (modulus in self.prfs_cache):
    1.20 +            prfs = self.prfs_cache[modulus]
    1.21 +        else:
    1.22 +            prfs = {}
    1.23 +            for subset, key in self.keys.iteritems():
    1.24 +                prfs[subset] = PRF(key, modulus)
    1.25 +            self.prfs_cache[modulus] = prfs
    1.26          # TODO: the PRFs ought to be cached
    1.27 +        # Yes, they probably should.
    1.28          return prfs
    1.29  
    1.30      def dealer_prfs(self, modulus):
    1.31 @@ -75,13 +82,16 @@
    1.32          Return a mapping from player subsets to :class:`viff.prss.PRF`
    1.33          instances.
    1.34          """
    1.35 -        dealers = {}
    1.36 -        for dealer, keys in self.dealer_keys.iteritems():
    1.37 -            prfs = {}
    1.38 -            for subset, key in keys.iteritems():
    1.39 -                prfs[subset] = PRF(key, modulus)
    1.40 -                dealers[dealer] = prfs
    1.41 -        # TODO: the PRFs ought to be cached
    1.42 +        if (modulus in self.dealers_cache):
    1.43 +            dealers = self.dealers_cache[modulus]
    1.44 +        else:
    1.45 +            dealers = {}
    1.46 +            for dealer, keys in self.dealer_keys.iteritems():
    1.47 +                prfs = {}
    1.48 +                for subset, key in keys.iteritems():
    1.49 +                    prfs[subset] = PRF(key, modulus)
    1.50 +                    dealers[dealer] = prfs
    1.51 +                    self.dealers_cache[modulus] = dealers
    1.52          return dealers
    1.53  
    1.54      def __repr__(self):