aboutsummaryrefslogtreecommitdiff
path: root/pypride.py
diff options
context:
space:
mode:
Diffstat (limited to 'pypride.py')
-rw-r--r--pypride.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/pypride.py b/pypride.py
index 5f2a771..f247ceb 100644
--- a/pypride.py
+++ b/pypride.py
@@ -21,6 +21,37 @@
#
# =============================================================================
+"""
+PRIDE block cipher implementation
+
+USAGE EXAMPLE:
+---------------
+Importing:
+-----------
+>>> from pypride import Pride
+
+Create a Pride object:
+-----------------------
+>>> key = "00000000000000000000000000000000".decode('hex')
+>>> cipher = Pride(key)
+
+Encryption:
+------------
+>>> plain = "0000000000000000".decode('hex')
+>>> encrypted = cipher.encrypt(plain)
+>>> encrypted.encode('hex')
+'82b4109fcc70bd1f'
+
+Decryption:
+------------
+>>> decrypted = cipher.decrypt(encrypted)
+>>> decrypted.encode('hex')
+'0000000000000000'
+
+This implementation is fully based on the report PRIDE was presented in (https://eprint.iacr.org/2014/453; specifically section 5.4).
+Test vectors can be found in test-vectors.py and were taken from appendix J of that paper.
+"""
+
class Pride:
def __init__(self,key):
@@ -84,15 +115,15 @@ class Pride:
return number2string_N(state,8)
-""" 4 to 4-bit S-Box and its inverse """
+# 4 to 4-bit S-Box and its inverse
Sbox= [0x0,0x4,0x8,0xf,0x1,0x5,0xe,0x9,0x2,0x7,0xa,0xc,0xb,0xd,0x6,0x3]
Sbox_inv = [Sbox.index(x) for x in xrange(16)]
-""" 64-bit permutation P and its inverse """
+# 64-bit permutation P and its inverse
PBox = [0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51, 4, 20, 36, 52, 5, 21, 37, 53, 6, 22, 38, 54, 7, 23, 39, 55, 8, 24, 40, 56, 9, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, 59, 12, 28, 44, 60, 13, 29, 45, 61, 14, 30, 46, 62, 15, 31, 47, 63]
PBox_inv = [PBox.index(x) for x in xrange(64)]
-""" Matrices for permutation in the L layer """
+# Matrices for permutation in the L layer
L0 = [[0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0],
[0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
[0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0],