Merge lp:~vomun-security/anonplus/security-trunk into lp:anonplus

Proposed by aj00200
Status: Merged
Approved by: aj00200
Approved revision: 182
Merged at revision: 190
Proposed branch: lp:~vomun-security/anonplus/security-trunk
Merge into: lp:anonplus
Diff against target: 41 lines (+29/-1)
1 file modified
src/libs/encryption/aes.py (+29/-1)
To merge this branch: bzr merge lp:~vomun-security/anonplus/security-trunk
Reviewer Review Type Date Requested Status
al1ce (community) security Approve
aj00200 security Approve
Review via email: mp+87120@code.launchpad.net

Commit message

Completed the AES code with random padding.

Description of the change

Completed the AES code with random padding.

To post a comment you must log in.
Revision history for this message
aj00200 (aj00200) wrote :

Everything seems to function and the random padding works as expected.

review: Approve (security)
Revision history for this message
al1ce (al1ce) :
review: Approve (security)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libs/encryption/aes.py'
2--- src/libs/encryption/aes.py 2011-10-23 15:41:09 +0000
3+++ src/libs/encryption/aes.py 2011-12-30 01:31:24 +0000
4@@ -1,7 +1,35 @@
5 '''Handles all AES (Advanced Encryption Standard) encryption. This module is
6 not being used yet, but it will be in a later version.'''
7+import Crypto
8+from Crypto import Random
9+from Crypto.Cipher import AES
10 import libs.encryption.base
11
12 class Encryption(libs.encryption.base.Encryption):
13 '''Hold the AES encryption state.'''
14- pass
15+ def __init__(self, key):
16+ self.aes = AES.new(key)
17+ self.rng = Random.new()
18+
19+ def encrypt(self, data):
20+ '''Pad `data` with random bytes so that it is a multiple of 16
21+ bytes in length. Then encrypt the data and return it.
22+ '''
23+ return self.aes.encrypt(self.pad(data))
24+
25+ def decrypt(self, data):
26+ '''Decrypt the data.'''
27+ return self.aes.decrypt(data)
28+
29+ # AES only methods
30+ def rekey(self, key):
31+ '''Switch to a different key. The key should be 16 bytes in length and
32+ contain purely random data.
33+ '''
34+ self.aes = AES.new(key)
35+
36+ def pad(self, data):
37+ count = 16 - len(data) % 16
38+ data += self.rng.read(count)
39+ return data
40+
41\ No newline at end of file

Subscribers

People subscribed via source and target branches