diff --git a/Lab01Basics/Lab01Code.py b/Lab01Basics/Lab01Code.py index 19edd01..cf2e96f 100644 --- a/Lab01Basics/Lab01Code.py +++ b/Lab01Basics/Lab01Code.py @@ -5,7 +5,7 @@ # an end-to-end encryption system. # # Run the tests through: -# $ py.test-2.7 -v Lab01Tests.py +# $ py.test-2.7 -v Lab01Tests.py ########################### # Group Members: TODO @@ -14,13 +14,13 @@ ##################################################### # TASK 1 -- Ensure petlib is installed on the System -# and also pytest. Ensure the Lab Code can +# and also pytest. Ensure the Lab Code can # be imported. import petlib ##################################################### -# TASK 2 -- Symmetric encryption using AES-GCM +# TASK 2 -- Symmetric encryption using AES-GCM # (Galois Counter Mode) # # Implement a encryption and decryption function @@ -34,13 +34,13 @@ def encrypt_message(K, message): """ Encrypt a message under a key K """ plaintext = message.encode("utf8") - + ## YOUR CODE HERE return (iv, ciphertext, tag) def decrypt_message(K, iv, ciphertext, tag): - """ Decrypt a cipher text under a key K + """ Decrypt a cipher text under a key K In case the decryption fails, throw an exception. """ @@ -78,7 +78,7 @@ def is_point_on_curve(a, b, p, x, y): assert (isinstance(x, Bn) and isinstance(y, Bn)) \ or (x == None and y == None) - if x == None and y == None: + if x is None and y is None: return True lhs = (y * y) % p @@ -102,7 +102,7 @@ def point_add(a, b, p, x0, y0, x1, y1): # ADD YOUR CODE BELOW xr, yr = None, None - + return (xr, yr) def point_double(a, b, p, x, y): @@ -115,7 +115,7 @@ def point_double(a, b, p, x, y): yr = lam * (xp - xr) - yp (mod p) Returns the point representing the double of the input (x, y). - """ + """ # ADD YOUR CODE BELOW xr, yr = None, None @@ -174,9 +174,9 @@ def point_scalar_multiplication_montgomerry_ladder(a, b, p, x, y, scalar): ##################################################### # TASK 4 -- Standard ECDSA signatures # -# - Implement a key / param generation +# - Implement a key / param generation # - Implement ECDSA signature using petlib.ecdsa -# - Implement ECDSA signature verification +# - Implement ECDSA signature verification # using petlib.ecdsa from hashlib import sha256 @@ -184,7 +184,7 @@ def point_scalar_multiplication_montgomerry_ladder(a, b, p, x, y, scalar): from petlib.ecdsa import do_ecdsa_sign, do_ecdsa_verify def ecdsa_key_gen(): - """ Returns an EC group, a random private key for signing + """ Returns an EC group, a random private key for signing and the corresponding public key for verification""" G = EcGroup() priv_sign = G.order().random() @@ -214,7 +214,7 @@ def ecdsa_verify(G, pub_verify, message, sig): # - Use Bob's public key to encrypt a message. # - Use Bob's private key to decrypt the message. # -# NOTE: +# NOTE: def dh_get_key(): """ Generate a DH key pair """ @@ -225,29 +225,29 @@ def dh_get_key(): def dh_encrypt(pub, message, aliceSig = None): - """ Assume you know the public key of someone else (Bob), + """ Assume you know the public key of someone else (Bob), and wish to Encrypt a message for them. - Generate a fresh DH key for this message. - Derive a fresh shared key. - Use the shared key to AES_GCM encrypt the message. - Optionally: sign the message with Alice's key. """ - + ## YOUR CODE HERE pass def dh_decrypt(priv, ciphertext, aliceVer = None): - """ Decrypt a received message encrypted using your public key, - of which the private key is provided. Optionally verify + """ Decrypt a received message encrypted using your public key, + of which the private key is provided. Optionally verify the message came from Alice using her verification key.""" - + ## YOUR CODE HERE pass ## NOTE: populate those (or more) tests # ensure they run using the "py.test filename" command. # What is your test coverage? Where is it missing cases? -# $ py.test-2.7 --cov-report html --cov Lab01Code Lab01Code.py +# $ py.test-2.7 --cov-report html --cov Lab01Code Lab01Code.py def test_encrypt(): assert False @@ -261,9 +261,9 @@ def test_fails(): ##################################################### # TASK 6 -- Time EC scalar multiplication # Open Task. -# +# # - Time your implementations of scalar multiplication -# (use time.clock() for measurements)for different +# (use time.clock() for measurements)for different # scalar sizes) # - Print reports on timing dependencies on secrets. # - Fix one implementation to not leak information.