aboutsummaryrefslogtreecommitdiff
path: root/pypride.py
diff options
context:
space:
mode:
authorCamil Staps2015-04-23 12:51:25 +0200
committerCamil Staps2015-04-23 12:51:25 +0200
commit09560a14c64f9a5e418334d3a5e77447e32ae85f (patch)
tree44e8794a2eaad4614b397e06f40a46ef6791bc34 /pypride.py
parentAttribution for pypresent ideas (diff)
Timing; generate roundkeys on initialisation
Diffstat (limited to 'pypride.py')
-rw-r--r--pypride.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/pypride.py b/pypride.py
index 935d8c4..b30b565 100644
--- a/pypride.py
+++ b/pypride.py
@@ -61,13 +61,12 @@ class Pride:
def __init__(self,key):
"""Create a PRIDE cipher object
- key: the key as a 128-bit raw string"""
+ Input: the key as a 128-bit raw string"""
- if len(key) * 8 == 128:
- self.key_whitening = string2number(key[:8])
- self.key_1 = key[8:]
- else:
+ if len(key) != 16:
raise ValueError, "Key must be a 128-bit raw string"
+ self.whitening_key = string2number(key[:8])
+ self.roundkeys = [roundKey(key[8:], i) for i in xrange(0,21)]
def encrypt(self,block):
"""Encrypt 1 block (8 bytes)
@@ -79,17 +78,17 @@ class Pride:
# Initial permutation & pre-whitening
state = pLayer_dec(state)
- state = addRoundKey(state, self.key_whitening)
+ state = addRoundKey(state, self.whitening_key)
# 19 rounds R
for i in xrange (1,20):
- state = addRoundKey(state, roundKey(self.key_1, i))
+ state = addRoundKey(state, self.roundkeys[i])
state = sBoxLayer(state)
state = lLayer(state)
# Last round R'
- state = addRoundKey(state, roundKey(self.key_1, 20))
+ state = addRoundKey(state, self.roundkeys[20])
state = sBoxLayer(state)
# Post-whitening & final permutation
- state = addRoundKey(state, self.key_whitening)
+ state = addRoundKey(state, self.whitening_key)
state = pLayer(state)
return number2string_N(state,8)
@@ -104,17 +103,17 @@ class Pride:
# Final permutation & post-whitening
state = pLayer_dec(state)
- state = addRoundKey(state, self.key_whitening)
+ state = addRoundKey(state, self.whitening_key)
# Last round R'
state = sBoxLayer_dec(state)
- state = addRoundKey(state, roundKey(self.key_1, 20))
+ state = addRoundKey(state, self.roundkeys[20])
# 19 rounds R
for i in xrange(19,0,-1):
state = lLayer_dec(state)
state = sBoxLayer_dec(state)
- state = addRoundKey(state, roundKey(self.key_1, i))
+ state = addRoundKey(state, self.roundkeys[i])
# Pre-whitening & initial permutation
- state = addRoundKey(state, self.key_whitening)
+ state = addRoundKey(state, self.whitening_key)
state = pLayer(state)
return number2string_N(state,8)