Skip to content

Commit

Permalink
Unfinished Version changes in MV to be more like RSA
Browse files Browse the repository at this point in the history
  • Loading branch information
Felefix201 committed Apr 7, 2024
1 parent f88c85c commit b4a6c99
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 79 deletions.
10 changes: 5 additions & 5 deletions GUI/src/app/client/client.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ClientComponent implements OnInit {

protected signatureVerificationCalculated: boolean = false;
protected signatureValid: boolean = false;
private configurationData = this.stateService.getConfigurationData();
private configurationData = this.stateService.getConfigurationDataForRSA();

/**
* Konstruktor der Komponente.
Expand Down Expand Up @@ -173,7 +173,7 @@ export class ClientComponent implements OnInit {
public encrypt() {
const requestBody = new RsaEncryptDecryptRequest(
this.plainText,
this.stateService.getClientKey(this.sendingTo)(),
this.stateService.getClientKeyForRSA(this.sendingTo)(),
this.configurationData().number_system_base
);
const start = Date.now();
Expand Down Expand Up @@ -242,7 +242,7 @@ export class ClientComponent implements OnInit {
const requestBody = new RsaVerifyRequest(
this.plainText,
this.signature,
this.stateService.getClientKey(this.receivedFrom)(),
this.stateService.getClientKeyForRSA(this.receivedFrom)(),
this.configurationData().number_system_base
);
const start = Date.now();
Expand All @@ -262,7 +262,7 @@ export class ClientComponent implements OnInit {
const requestBody = new RsaVerifyRequest(
this.cipherText,
this.signature,
this.stateService.getClientKey(this.receivedFrom)(),
this.stateService.getClientKeyForRSA(this.receivedFrom)(),
this.configurationData().number_system_base
);
const start = Date.now();
Expand Down Expand Up @@ -352,7 +352,7 @@ export class ClientComponent implements OnInit {
this._client = this.stateService.getClientByName(name);
this.sendingTo = this.getOtherClients().values().next().value;
console.log(this.client);
this._clientKeyPair = this.stateService.getClientKey(this.client);
this._clientKeyPair = this.stateService.getClientKeyForRSA(this.client);
}

/**
Expand Down
173 changes: 149 additions & 24 deletions GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ import {
MvEncryptRequest,
MvKeyPair,
} from "../models/mv-beans";
import {ClientData} from "../models/client";
import {Client, ClientData} from "../models/client";
import {StateManagementService} from "../services/management/state-management.service";
import {MatDialog, MatDialogRef} from "@angular/material/dialog";
import {MatSnackBar} from "@angular/material/snack-bar";
import {MvConfigurationData} from "../models/mv-configuration-data";
import {LoadingDialogComponent} from "../loading-dialog/loading-dialog.component";

@Component({
selector: "app-menezes-vanstone",
Expand Down Expand Up @@ -53,13 +57,8 @@ import {StateManagementService} from "../services/management/state-management.se
* Component for the Menezes Vanstone Encryption and Decryption.
*/
export class MenezesVanstoneComponent {
public modulusWidth: number = 128;
public numberSystem: number = 55296;
public millerRabinIterations: number = 100;
public coefficientA: number = 5;
public random_seed: number= 3;

private configurationData = this.stateService.getConfigurationData();
// Value for configuration Data which is provided by the global state management service
private configurationData = this.stateService.getConfigurationDataForMV();

public clients: ClientData[] =
[
Expand Down Expand Up @@ -137,25 +136,151 @@ export class MenezesVanstoneComponent {

constructor(
private stateService: StateManagementService,
private backendRequestService: MvBackendRequestService) {
public dialog: MatDialog,
private backendRequestService: MvBackendRequestService,
private snackBar: MatSnackBar
) {
}

/**
* Returns the modulus width for the Menezes Vanstone key pair.
*/
public get modulusWidth(): number {
return this.configurationData().modulus_width;
}

/**
* Sets the modulus width for the Menezes Vanstone key pair.
* @param modulus_width
*/
public set modulusWidth(modulus_width: number) {
this.configurationData.update(value => ({
...value,
modulus_width
}));
}

/**
* Returns the number system base for the Menezes Vanstone key pair.
*/
public get numberSystem(): number {
return this.configurationData().numberSystem;
}

/**
* Sets the number system base for the Menezes Vanstone key pair.
* @param value
*/
public set numberSystem(value: number) {
this.configurationData.update(data => ({
...data,
numberSystem: value
}));
}

/**
* Returns the number of Miller-Rabin iterations for the Menezes Vanstone key pair.
*/
public get millerRabinIterations(): number {
return this.configurationData().millerRabinIterations;
}

/**
* Sets the number of Miller-Rabin iterations for the Menezes Vanstone key pair.
* @param value
*/
public set millerRabinIterations(value: number) {
this.configurationData.update(data => ({
...data,
millerRabinIterations: value
}));
}

/**
* Returns the coefficient A for the Menezes Vanstone key pair.
*/
public get coefficientA(): number {
return this.configurationData().coefficientA;
}

/**
* Sets the coefficient A for the Menezes Vanstone key pair.
* @param value
*/
public set coefficientA(value: number) {
this.configurationData.update(data => ({
...data,
coefficientA: value
}));
}

/**
* Returns the random seed for the Menezes Vanstone key pair.
*/
public get randomSeed(): number {
return this.configurationData().random_seed;
}

/**
* Sets the random seed for the Menezes Vanstone key pair.
* @param value
*/
public set randomSeed(value: number) {
this.configurationData.update(data => ({
...data,
random_seed: value
}));
}

public generateKeys(client: string) {
let config: MvKeygenConfig = {
modulus_width: this.modulusWidth,
miller_rabin_rounds: this.millerRabinIterations,
coef_a: this.coefficientA,
random_seed: this.random_seed
/**
* Generates a Menezes Vanstone key pair for the given client.
* @param client
*/
public generateKeys(client: Client): void {
let requestContent = new MvConfigurationData(
this.modulusWidth,
this.numberSystem,
this.millerRabinIterations,
this.coefficientA,
this.randomSeed
);
this.generateKeyPair(requestContent, client);
};
this.backendRequestService.createKeyPair(config).then(key => {
if (client === "Alice") {
this.clients[0].keyPair = copyMvKeyPair(key);
} else {
this.clients[1].keyPair = copyMvKeyPair(key);
}
console.log("Generated key pair for " + client);
console.log(key);
console.log(this.clients);

public generateKeyPair(requestContent: MvConfigurationData, client: Client): void {
let loadingDialog = this.openLoadDialog();
const startTime = Date.now();
this.backendRequestService.createKeyPair(requestContent).then(
// todo tristan keyPair is not defined and should be defined, after that, the code should work
// keyPair) => {
// const duration = Date.now() - startTime;
// let entry = this.stateService.getClientKeyForMV(client);
// if(entry) {
// entry.set(keyPair);
// } else {
// console.log("Client " + client.name + " is not registered! Returning empty KeyPair and registering client.");
// }
// loadingDialog.close();
// this.showSnackbar("Schlüsselpaar für " + client.name + " generiert. Dauer: " + duration + "ms");
// }
);
}

/**
* Shows a snackbar with the given message.
*/
private showSnackbar(message: string) {
this.snackBar.open(message, "Ok", {
duration: 5000,
});
}

/**
* Open a dialog to show a loading spinner.
*/
public openLoadDialog(): MatDialogRef<LoadingDialogComponent> {
return this.dialog.open(LoadingDialogComponent, {
disableClose: true // Verhindert das Schließen durch den Benutzer
});
}

Expand Down
24 changes: 0 additions & 24 deletions GUI/src/app/models/menezes-vanstone-configuration-data.ts

This file was deleted.

28 changes: 28 additions & 0 deletions GUI/src/app/models/mv-configuration-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Class that represents the configuration data for the Menezes-Vanstone cryptosystem.
*/
export class MvConfigurationData {
modulus_width: number;
numberSystem: number;
millerRabinIterations: number;
coefficientA: number;
random_seed: number;

constructor(modulus_width: number,
numberSystem: number,
millerRabinIterations: number,
coefficientA: number,
random_seed: number
) {
this.modulus_width = modulus_width;
this.numberSystem = numberSystem;
this.millerRabinIterations = millerRabinIterations;
this.coefficientA = coefficientA;
this.random_seed = random_seed;
}

public static createDefaultConfigurationDataForMV(): MvConfigurationData {
return new MvConfigurationData(256, 55296, 10, 5, 3);
}
}

4 changes: 4 additions & 0 deletions GUI/src/app/models/mv-keygen-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export class MvKeygenConfig {
modulus_width: number;
//todo Tristan, wieso wird hier nicht das Number System (Basis) mit angegeben?
//in der menezesvanstone.component.ts wird in dem keygen jetzt nichtmehr das hier
// verwendet sondern die menezes-vanestone-configuration-data.ts, damit es mit
// dem RSA überein stimmt
miller_rabin_rounds: number;
coef_a: number;
random_seed: number;
Expand Down
24 changes: 13 additions & 11 deletions GUI/src/app/rsa/rsa.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import {SimpleDialogComponent} from "../simple-dialog/simple-dialog.component";
*/
export class RsaComponent {
// Value for configuration Data which is provided by the global state management service
private configurationData = this.stateService.getConfigurationData();
private configurationData = this.stateService.getConfigurationDataForRSA();

constructor(private stateService: StateManagementService,
public dialog: MatDialog,
private backendRequestService: RsaBackendRequestService,
private snackBar: MatSnackBar) {
constructor(
private stateService: StateManagementService,
public dialog: MatDialog,
private backendRequestService: RsaBackendRequestService,
private snackBar: MatSnackBar
) {
}

/**
Expand Down Expand Up @@ -143,7 +145,7 @@ export class RsaComponent {
* @param client
*/
public getModulus(client: Client): string {
const keyPairSignal = this.stateService.getClientKey(client);
const keyPairSignal = this.stateService.getClientKeyForRSA(client);
return keyPairSignal().modulus || "";
}

Expand All @@ -153,7 +155,7 @@ export class RsaComponent {
* @param modulus
*/
public setModulus(client: Client, modulus: string): void {
const keyPairSignal = this.stateService.getClientKey(client);
const keyPairSignal = this.stateService.getClientKeyForRSA(client);
keyPairSignal.update(keyPair => ({
...keyPair,
modulus
Expand All @@ -165,7 +167,7 @@ export class RsaComponent {
* @param client
*/
public getExponent(client: Client): string {
const keyPairSignal = this.stateService.getClientKey(client);
const keyPairSignal = this.stateService.getClientKeyForRSA(client);
return keyPairSignal().e || "";
}

Expand All @@ -175,7 +177,7 @@ export class RsaComponent {
* @param value
*/
public setExponent(client: Client, value: string): void {
const keyPair = this.stateService.getClientKey(client);
const keyPair = this.stateService.getClientKeyForRSA(client);
keyPair.update(keyPair => ({
...keyPair,
e: value
Expand All @@ -187,7 +189,7 @@ export class RsaComponent {
* @param client
*/
public getBlockSizePub(client: Client): string {
const keyPairSignal = this.stateService.getClientKey(client);
const keyPairSignal = this.stateService.getClientKeyForRSA(client);
return keyPairSignal().block_size_pub || "";
}

Expand Down Expand Up @@ -235,7 +237,7 @@ export class RsaComponent {
this.backendRequestService.createKeyPair(requestContent).then(
(keyPair) => {
const duration = Date.now() - startTime;
let entry = this.stateService.getClientKey(client);
let entry = this.stateService.getClientKeyForRSA(client);
if (entry) {
entry.set(keyPair);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {firstValueFrom} from "rxjs";
import {SingleMessageModel} from "../../models/SingleMessageModel";
import {MvKeygenConfig} from "../../models/mv-keygen-config";
import {MvCipherText, MvDecryptRequest, MvEncryptRequest, MvKeyPair} from "../../models/mv-beans";
import {MvConfigurationData} from "../../models/mv-configuration-data";

@Injectable({
providedIn: "root"
Expand All @@ -24,7 +25,7 @@ export class MvBackendRequestService {
/**
* Fragt den Post Endpunkt zum Erstellen eines neuen Schlüsselpaares ab.
*/
public async createKeyPair(body: MvKeygenConfig): Promise<MvKeyPair> {
public async createKeyPair(body: MvConfigurationData): Promise<MvKeyPair> {
const params = this.getParams();
const options = {params};
return firstValueFrom(
Expand Down
Loading

0 comments on commit b4a6c99

Please sign in to comment.