package csidh_test

import "seekia/internal/cryptography/csidh"

import "testing"

func TestEncryptDecryptCsidh(t *testing.T) {

	testPublicKey1, testPrivateKey1, err := csidh.GetNewRandomPublicPrivateCsidhKeys()
	if (err != nil) {
		t.Fatal("Failed to derive Csidh keys: " + err.Error())
	}

	testPublicKey2, testPrivateKey2, err := csidh.GetNewRandomPublicPrivateCsidhKeys()
	if (err != nil) {
		t.Fatal("Failed to derive Csidh keys: " + err.Error())
	}

	newSecret1, err := csidh.CalculateCsidhSharedKey(testPublicKey1, testPrivateKey2)
	if (err != nil){
		t.Fatal("CalculateCsidhSharedKey failed: " + err.Error())
	}

	newSecret2, err := csidh.CalculateCsidhSharedKey(testPublicKey2, testPrivateKey1)
	if (err != nil){
		t.Fatal("CalculateCsidhSharedKey failed: " + err.Error())
	}

	if (newSecret1 != newSecret2){
		t.Fatal("Csidh failed: Secret keys do not match.")
	}
}