-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated readme, fixed the test_cases
- Loading branch information
1 parent
99ffb6f
commit 1dc7691
Showing
10 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.