aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2013-08-20 20:50:46 +0200
committerMichał Górny <mgorny@gentoo.org>2013-08-20 20:50:46 +0200
commit70b4133a32476bc5abad18e1f4465a4ec2ceeab1 (patch)
tree10e6e326385e90d319271756dfbc38f2a812de37 /okupy/common
parentMerge pull request #71 from tampakrap/tests (diff)
downloadidentity.gentoo.org-70b4133a32476bc5abad18e1f4465a4ec2ceeab1.tar.gz
identity.gentoo.org-70b4133a32476bc5abad18e1f4465a4ec2ceeab1.tar.bz2
identity.gentoo.org-70b4133a32476bc5abad18e1f4465a4ec2ceeab1.zip
OkupyCipher: make block_size a public property.
Diffstat (limited to 'okupy/common')
-rw-r--r--okupy/common/crypto.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/okupy/common/crypto.py b/okupy/common/crypto.py
index 2596680..705f173 100644
--- a/okupy/common/crypto.py
+++ b/okupy/common/crypto.py
@@ -16,7 +16,6 @@ class OkupyCipher(object):
_hasher_algo = SHA384Hash
_cipher_algo = BlowfishCipher
- _cipher_block_size = 8
def __init__(self):
hasher = self._hasher_algo()
@@ -25,6 +24,13 @@ class OkupyCipher(object):
self.cipher = self._cipher_algo(key_hash)
self.rng = Crypto.Random.new()
+ @property
+ def block_size(self):
+ """
+ Cipher's block size.
+ """
+ return self.cipher.block_size
+
def encrypt(self, data):
"""
Encrypt random-length data block padding it with random data
@@ -34,7 +40,7 @@ class OkupyCipher(object):
# ensure it's bytestring before we append random bits
data = bytes(data)
# minus is intentional. (-X % S) == S - (X % S)
- padding = -len(data) % self._cipher_block_size
+ padding = -len(data) % self.block_size
if padding:
data += self.rng.read(padding)
return self.cipher.encrypt(data)