From 5735c230b12ddaf48d44d96089c2a6fbbf152420 Mon Sep 17 00:00:00 2001
From: Tristan-H11 <triddel02@gmx.de>
Date: Sun, 7 Apr 2024 13:08:42 +0200
Subject: [PATCH] KeyGen in die GUI eingebaut

---
 .../menezes-vanstone.component.html            |  8 ++++++++
 .../menezes-vanstone.component.ts              | 18 +++++++++++++++++-
 GUI/src/app/models/mv-keygen-config.ts         |  5 ++++-
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/GUI/src/app/menezes-vanstone/menezes-vanstone.component.html b/GUI/src/app/menezes-vanstone/menezes-vanstone.component.html
index 7459dbff..660c2e98 100644
--- a/GUI/src/app/menezes-vanstone/menezes-vanstone.component.html
+++ b/GUI/src/app/menezes-vanstone/menezes-vanstone.component.html
@@ -13,11 +13,13 @@
             <mat-label>Modulbreite</mat-label>
             <input class="text-align-right" matInput type="number" [(ngModel)]="modulusWidth">
             <span matTextSuffix>-Bit</span>
+            <mat-hint>Bei {{numberSystem}} mindestens {{calcMinimumBitsize()}} Bit</mat-hint>
         </mat-form-field>
 
         <mat-form-field appearance="outline" class="config-form-field">
             <mat-label>Zahlensystem</mat-label>
             <input class="text-align-right" matInput type="number" [(ngModel)]="numberSystem">
+            <mat-hint>Bei {{modulusWidth}}-Bit maximal {{calcMaxNumbersystem()}}</mat-hint>
         </mat-form-field>
 
         <mat-form-field appearance="outline" class="config-form-field">
@@ -32,6 +34,11 @@
             <mat-hint>wird '-a^2'</mat-hint>
         </mat-form-field>
 
+        <mat-form-field appearance="outline" class="config-form-field">
+            <mat-label>Seed</mat-label>
+            <input class="text-align-right" matInput type="number" [(ngModel)]="random_seed">
+        </mat-form-field>
+
         <mat-action-row class="action-row-content-left">
             <button mat-flat-button *ngFor="let client of clients" color="primary" (click)="generateKeys(client.name)">
                 Schlüsselpaar für {{client.name}} erzeugen
@@ -63,6 +70,7 @@
         Punkte: {{JSON.stringify(client.ciphertext.points)}}
 
         <mat-action-row>
+            <button mat-flat-button color="primary" (click)="clearFields(client.name)">Löschen</button>
             <button mat-flat-button color="primary" [disabled]="client.plaintext.length<1" (click)="encrypt(client.name)">Verschlüsseln</button>
             <button mat-flat-button color="primary" [disabled]="client.ciphertext.encrypted_message.length<1" (click)="decrypt(client.name)">Entschlüsseln</button>
             <button mat-flat-button color="primary" (click)="send(client.name)">Senden</button>
diff --git a/GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts b/GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts
index e7a5a46c..3b0f9677 100644
--- a/GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts
+++ b/GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts
@@ -59,6 +59,7 @@ export class MenezesVanstoneComponent {
     public numberSystem: number = 55296;
     public millerRabinIterations: number = 100;
     public coefficientA: number = 5;
+    public random_seed: number= 3;
 
     public clients: ClientData[] =
         [
@@ -141,7 +142,8 @@ export class MenezesVanstoneComponent {
         let config: MvKeygenConfig = {
             modulus_width: this.modulusWidth,
             miller_rabin_rounds: this.millerRabinIterations,
-            coef_a: this.coefficientA
+            coef_a: this.coefficientA,
+            random_seed: this.random_seed
         };
         this.backendRequestService.createKeyPair(config).then(key => {
             if (client === "Alice") {
@@ -191,5 +193,19 @@ export class MenezesVanstoneComponent {
         client.ciphertext = {encrypted_message: "", points: []};
     }
 
+    public clearFields(name: string) {
+        let client = (name === "Alice") ? this.clients[0] : this.clients[1];
+        client.plaintext = "";
+        client.ciphertext = {encrypted_message: "", points: []};
+    }
+
     protected readonly JSON = JSON;
+
+    public calcMinimumBitsize(): number {
+        return Math.ceil(Math.log2(this.numberSystem));
+    }
+
+    public calcMaxNumbersystem(): number {
+        return 2 ** this.modulusWidth;
+    }
 }
diff --git a/GUI/src/app/models/mv-keygen-config.ts b/GUI/src/app/models/mv-keygen-config.ts
index 553d1350..2a2c791e 100644
--- a/GUI/src/app/models/mv-keygen-config.ts
+++ b/GUI/src/app/models/mv-keygen-config.ts
@@ -2,12 +2,15 @@ export class MvKeygenConfig {
     modulus_width: number;
     miller_rabin_rounds: number;
     coef_a: number;
+    random_seed: number;
 
     constructor(modulus_width: number,
                 miller_rabin_rounds: number,
-                coef_a: number) {
+                coef_a: number,
+                random_seed: number) {
         this.modulus_width = modulus_width;
         this.miller_rabin_rounds = miller_rabin_rounds;
         this.coef_a = coef_a;
+        this.random_seed = random_seed;
     }
 }