Skip to content

Commit

Permalink
updated readme, fixed the test_cases
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisekjha committed May 29, 2024
1 parent 99ffb6f commit 1dc7691
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 26 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ Use the recipient's Kyber public key to encrypt this AES session key, creating a

This script ensures the secure encryption and decryption of messages using a combination of Kyber and AES-256, providing strong security against both current and future threats.

# Steps to Run the Test

1. Activate the environment
```
source venv/bin/activate
```

2. Set the PYTHONPATH to include the current directory and the pyky directory:
```
export PYTHONPATH=$PYTHONPATH:/path/to/pqc_aes_multipath:/path/to/pqc_aes_multipath/pyky
```
3. To Verify PYTHONPATH

```
echo $PYTHONPATH
```
Binary file added src/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/decryption.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/encryption.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/key_management.cpython-312.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions src/key_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from src.key_management import generate_kyber_keypair

# Generate Kyber key pair
private_key, public_key = generate_kyber_keypair()
print("Private Key:", private_key)
print("Public Key:", public_key)
2 changes: 1 addition & 1 deletion src/key_management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ccakem import kem_keygen512, kem_encaps512, kem_decaps512
from pyky.ccakem import kem_keygen512, kem_encaps512, kem_decaps512

def generate_kyber_keypair():
"""Generate a Kyber key pair."""
Expand Down
5 changes: 5 additions & 0 deletions test_pyky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
from pyky.ccakem import kem_keygen512
print("pyky package is accessible.")
except ImportError:
print("pyky package is not accessible.")
66 changes: 41 additions & 25 deletions tests/test_encryption.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
#test case for encryption.py
import os
import unittest
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
#from src.key_management import generate_kyber_keypair
from pyky.ccakem import kem_keygen512, kem_encaps512, kem_decaps512
from src.encryption import generate_aes_key, aes_encrypt
from src.decryption import aes_decrypt

class TestEncryption(unittest.TestCase):
def test_generate_aes_key(self):
# Arrange
# Act
key = generate_aes_key()
# Assert
self.assertEqual(len(key), 32)

def test_aes_encrypt(self):
# Arrange
message = b'Hello, World!'
session_key = os.urandom(32)
# Act
encrypted_message = aes_encrypt(message, session_key)
# Assert
self.assertNotEqual(encrypted_message, message)
self.assertEqual(len(encrypted_message), 48)

if __name__ == '__main__':
unittest.main()


def generate_kyber_keypair():
"""Generate a Kyber key pair."""
return kem_keygen512()

def test_encryption():
# Generate Kyber key pair

priv_key, pub_key = generate_kyber_keypair()
print("Kyber key pair generated.")

# Generate AES session key
aes_key = generate_aes_key()
print("AES session key generated.")

# Encrypt AES session key with Kyber public key
encrypted_session_key, _ = kem_encaps512(pub_key)
print("AES session key encrypted with Kyber public key.")

# Encrypt a sample message with AES
message = b"Hello, this is a test message!"
encrypted_message = aes_encrypt(message, aes_key)
print("Message encrypted with AES.")

# Decrypt AES session key with Kyber private key
decrypted_aes_key = kem_decaps512(priv_key, encrypted_session_key)
print("AES session key decrypted with Kyber private key.")

# Decrypt the message with the decrypted AES key
decrypted_message = aes_decrypt(encrypted_message, decrypted_aes_key)
print("Message decrypted with AES.")

# Check if the original message and decrypted message are the same
assert message == decrypted_message, "Decryption failed: original and decrypted messages do not match!"
print("Encryption and decryption test passed!")

if __name__ == "__main__":
test_encryption()
File renamed without changes.

0 comments on commit 1dc7691

Please sign in to comment.