Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Lab01Code function is_point_on_curve change == to is #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Lab01Basics/Lab01Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -174,17 +174,17 @@ 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
from petlib.ec import EcGroup
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()
Expand Down Expand Up @@ -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 """
Expand All @@ -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
Expand All @@ -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.
Expand Down