Skip to content

Commit

Permalink
Merge branch 'Tristan-H11:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Felefix201 authored Apr 7, 2024
2 parents c67cbde + 5735c23 commit f88c85c
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 156 deletions.
8 changes: 8 additions & 0 deletions GUI/src/app/menezes-vanstone/menezes-vanstone.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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
Expand Down Expand Up @@ -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>
Expand Down
84 changes: 71 additions & 13 deletions GUI/src/app/menezes-vanstone/menezes-vanstone.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import {
copyMvCipherText,
copyMvKeyPair,
copyMvPublicKey,
MvCipherText, MvDecryptRequest,
MvEncryptRequest, MvKeyPair,
MvCipherText,
MvDecryptRequest,
MvEncryptRequest,
MvKeyPair,
} from "../models/mv-beans";
import {ClientData} from "../models/client";
import {StateManagementService} from "../services/management/state-management.service";
Expand Down Expand Up @@ -55,6 +57,7 @@ export class MenezesVanstoneComponent {
public numberSystem: number = 55296;
public millerRabinIterations: number = 100;
public coefficientA: number = 5;
public random_seed: number= 3;

private configurationData = this.stateService.getConfigurationData();

Expand All @@ -64,12 +67,31 @@ export class MenezesVanstoneComponent {
name: "Alice",
keyPair: {
public_key: {
curve: {a: -25, b: 0, prime: "259421157018863391010844302469063884861"},
generator: {x: "152198469913648308717544634828661961231", y: "50296851635441247077790719368115682846"},
y: {x: "26370934085012164485153092381593646122", y: "126290671313284822425335475919650022666"}
curve: {
a: -25, prime: "259421157018863391010844302469063884861",
generator: {
x: "152198469913648308717544634828661961231",
y: "50296851635441247077790719368115682846",
is_infinite: false
},
order_of_subgroup: "2"
},
y: {
x: "26370934085012164485153092381593646122",
y: "126290671313284822425335475919650022666",
is_infinite: false
}
},
private_key: {
curve: {a: -25, b: 0, prime: "259421157018863391010844302469063884861"},
curve: {
a: -25, prime: "259421157018863391010844302469063884861",
generator: {
x: "152198469913648308717544634828661961231",
y: "50296851635441247077790719368115682846",
is_infinite: false
},
order_of_subgroup: "2"
},
x: "12401522966815986254216934185370504355"
}
},
Expand All @@ -80,12 +102,31 @@ export class MenezesVanstoneComponent {
name: "Bob",
keyPair: {
public_key: {
curve: {a: -25, b: 0, prime: "259421157018863391010844302469063884861"},
generator: {x: "152198469913648308717544634828661961231", y: "50296851635441247077790719368115682846"},
y: {x: "26370934085012164485153092381593646122", y: "126290671313284822425335475919650022666"}
curve: {
a: -25, prime: "259421157018863391010844302469063884861",
generator: {
x: "152198469913648308717544634828661961231",
y: "50296851635441247077790719368115682846",
is_infinite: false
},
order_of_subgroup: "2"
},
y: {
x: "26370934085012164485153092381593646122",
y: "126290671313284822425335475919650022666",
is_infinite: false
}
},
private_key: {
curve: {a: -25, b: 0, prime: "259421157018863391010844302469063884861"},
curve: {
a: -25, prime: "259421157018863391010844302469063884861",
generator: {
x: "152198469913648308717544634828661961231",
y: "50296851635441247077790719368115682846",
is_infinite: false
},
order_of_subgroup: "2"
},
x: "12401522966815986254216934185370504355"
}
},
Expand All @@ -103,7 +144,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") {
Expand All @@ -128,7 +170,7 @@ export class MenezesVanstoneComponent {
};
this.backendRequestService.encrypt(request).then(ciphertext => {
client.ciphertext = copyMvCipherText(ciphertext);
console.log("Encrypted message: ", JSON.stringify(ciphertext))
console.log("Encrypted message: ", JSON.stringify(ciphertext));
});
}

Expand All @@ -138,7 +180,7 @@ export class MenezesVanstoneComponent {
private_key: copyMvKeyPair(client.keyPair).private_key,
cipher_text: copyMvCipherText(client.ciphertext),
radix: this.numberSystem
}
};
this.backendRequestService.decrypt(request).then(plaintext => {
client.plaintext = plaintext.message;
});
Expand All @@ -149,7 +191,23 @@ export class MenezesVanstoneComponent {
let client = (name === "Alice") ? this.clients[0] : this.clients[1];
let partner = (name === "Alice") ? this.clients[1] : this.clients[0];
partner.ciphertext = copyMvCipherText(client.ciphertext);
client.plaintext = "";
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;
}
}
42 changes: 14 additions & 28 deletions GUI/src/app/models/mv-beans.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export interface EllipticCurve {
a: number;
b: number;
prime: string;
order_of_subgroup: string;
generator: EcPoint;
}

export interface EcPoint {
x: string;
y: string;
is_infinite: boolean;
}

export interface MvPublicKey {
curve: EllipticCurve;
generator: EcPoint;
y: EcPoint;
}

Expand All @@ -25,6 +26,13 @@ export interface MvKeyPair {
private_key: MvPrivateKey;
}

export interface MvCreateKeyPairRequest {
modulus_width: number;
miller_rabin_rounds: number;
coef_a: number;
random_seed: number;
}

export interface MvEncryptRequest {
public_key: MvPublicKey;
message: string;
Expand All @@ -42,63 +50,41 @@ export interface MvDecryptRequest {
radix: number;
}

// Deep Copy Function for EllipticCurve
export function copyEllipticCurve(curve: EllipticCurve): EllipticCurve {
return { ...curve };
return {
...curve,
generator: copyEcPoint(curve.generator)
};
}

// Deep Copy Function for EcPoint
export function copyEcPoint(point: EcPoint): EcPoint {
return { ...point };
}

// Deep Copy Function for MvPublicKey
export function copyMvPublicKey(publicKey: MvPublicKey): MvPublicKey {
return {
curve: copyEllipticCurve(publicKey.curve),
generator: copyEcPoint(publicKey.generator),
y: copyEcPoint(publicKey.y)
};
}

// Deep Copy Function for MvPrivateKey
export function copyMvPrivateKey(privateKey: MvPrivateKey): MvPrivateKey {
return {
curve: copyEllipticCurve(privateKey.curve),
x: privateKey.x
};
}

// Deep Copy Function for MvBeans
export function copyMvKeyPair(keyPair: MvKeyPair): MvKeyPair {
return {
public_key: copyMvPublicKey(keyPair.public_key),
private_key: copyMvPrivateKey(keyPair.private_key)
};
}

// Deep Copy Function for MvEncryptRequest
export function copyMvEncryptRequest(request: MvEncryptRequest): MvEncryptRequest {
return {
public_key: copyMvPublicKey(request.public_key),
message: request.message,
radix: request.radix
};
}

// Deep Copy Function for MvCipherText
export function copyMvCipherText(cipherText: MvCipherText): MvCipherText {
return {
encrypted_message: cipherText.encrypted_message,
points: cipherText.points.map(copyEcPoint)
};
}

// Deep Copy Function for MvDecryptRequest
export function copyMvDecryptRequest(request: MvDecryptRequest): MvDecryptRequest {
return {
private_key: copyMvPrivateKey(request.private_key),
cipher_text: copyMvCipherText(request.cipher_text),
radix: request.radix
};
}
5 changes: 4 additions & 1 deletion GUI/src/app/models/mv-keygen-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading

0 comments on commit f88c85c

Please sign in to comment.