From 3d91db0c87f57c34cb729572b4a16d83b602cc3e Mon Sep 17 00:00:00 2001 From: Julio Date: Mon, 24 Apr 2023 17:48:23 +1000 Subject: [PATCH 1/9] clarify that bytearray is unsigned --- H4x2-TinySDK/H4x2-TinySDK/Math/EdDSA.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/H4x2-TinySDK/H4x2-TinySDK/Math/EdDSA.cs b/H4x2-TinySDK/H4x2-TinySDK/Math/EdDSA.cs index a4bd660..c0cabdb 100644 --- a/H4x2-TinySDK/H4x2-TinySDK/Math/EdDSA.cs +++ b/H4x2-TinySDK/H4x2-TinySDK/Math/EdDSA.cs @@ -65,7 +65,7 @@ public static bool Verify(byte[] message, byte[] signature, Point pub) return false; Point R = Point.FromBytes(signature.Take(32).ToArray()); - BigInteger s = new BigInteger(signature.Skip(32).ToArray()); + BigInteger s = new BigInteger(signature.Skip(32).ToArray(), true, false); byte[] encodedR = R.ToByteArray(); byte[] encodedPubKey = pub.ToByteArray(); From abbcc2b3a089a4b2ee4be8f7d43da21a400eed50 Mon Sep 17 00:00:00 2001 From: Julio Date: Mon, 24 Apr 2023 17:59:15 +1000 Subject: [PATCH 2/9] reduces key generation to 2 steps --- .../H4x2-TinySDK/Tools/KeyGenerator.cs | 189 ++++++++---------- 1 file changed, 79 insertions(+), 110 deletions(-) diff --git a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs index e55c4dc..e42b66c 100644 --- a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs +++ b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs @@ -64,8 +64,6 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) throw new Exception("GenShard: Number of keys requested must be at minimum 1"); } - // Generate random key multiplier - BigInteger EphKeyi = Utils.RandomBigInt(); // Generate DiffieHellman Keys based on this ork's priv and other Ork's Pubs byte[][] ECDHij = mgORKj.Select(pub => createKey(pub)).ToArray(); @@ -77,8 +75,12 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) long timestampi = DateTime.UtcNow.Ticks; BigInteger[] k = new BigInteger[numKeys]; - Point[] gK = new Point[numKeys]; + Point[] gKn = new Point[numKeys]; + Point[] gRn = new Point[numKeys]; + BigInteger[] Sn = new BigInteger[numKeys]; PolyPoint[][] Yij = new PolyPoint[numKeys][]; + BigInteger r; + BigInteger h; for (int i = 0; i < numKeys; i++) { @@ -86,33 +88,40 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) k[i] = Utils.RandomBigInt(); // Calculate public shard - gK[i] = Curve.G * k[i]; + gKn[i] = Curve.G * k[i]; + + // Calculate Zero Knowledge Proof for gK[n]i + r = Utils.RandomBigInt(); + gRn[i] = Curve.G * r; + h = new BigInteger(SHA512.HashData(gRn[i].ToByteArray().Concat(gKn[i].ToByteArray()).ToArray()), true, false) % Curve.N; + Sn[i] = (r + (h * k[i])) % Curve.N; // For each ORK, secret share value ki Yij[i] = (SecretSharing.Share(k[i], mgOrkj_Xs, Threshold, Curve.N)).ToArray(); } // Encrypt shard Yj with each ORK key - string[] YCiphers = ECDHij.Select((key, i) => encryptShares(key, Yij, i, timestampi, keyID)).ToArray(); + string[] YCiphers = ECDHij.Select((key, i) => encryptShares(key, Yij, i, timestampi, keyID, gKn, gRn, Sn)).ToArray(); - // Encrypted partial public with ephemeral key - string[] gKnCiphers = gK.Select(point => AES.Encrypt(point.ToBase64(), EphKeyi)).ToArray(); // encrypt base64 encoded point with string representation of ephKey + // Generate partial EdDSA R2 + BigInteger ri = Utils.RandomBigInt(); + Point gRi = Curve.G * ri; - // Encrypt latest state + // Store latest state string cacheState = JsonSerializer.Serialize(new CacheState_GenShard { MgORKj = mgORKj.Select(p => p.ToByteArray64()).ToArray(), // remember IDs are string representations of Xs ECDHij = ECDHij, - EphKey = EphKeyi.ToByteArray(true, true), K = k.Select(i => i.ToByteArray(true, true)).ToArray(), Li = li.ToByteArray(true, true), - Stage = 2 - }); + Stage = 2, + GKn = gKn.Select(gK => gK.ToByteArray64()).ToArray(), + Ri = ri.ToByteArray(true, false) + }) ; GenShardResponse response = new GenShardResponse { - GKnCiphers = gKnCiphers, YijCiphers = YCiphers, - Timestampi = timestampi.ToString() + GRi = gRi.ToByteArray() }; _cachingManager.AddOrGetCache("KeyGen:" + keyID, cacheState).GetAwaiter().GetResult(); // add state to memory @@ -124,7 +133,7 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) /// Make sure orkShares provided are sorted in same order as mgORKj. For example, orkshare[0].From = ork2 AND mgORKj[0] = ork2's public. /// This function cannot correlate orkId to public key unless it's in the same order /// - public string SendShard(string keyID, string[][] gKnCiphers, string[] yijCiphers, Point[] gMultiplier) + public string SendShard(string keyID, string[] yijCiphers, Point[] gMultiplier, Point R2) { string state_s = _cachingManager.AddOrGetCache("KeyGen:" + keyID, string.Empty).GetAwaiter().GetResult(); //Retrive the state cached from GenShard function _cachingManager.Remove("KeyGen:" + keyID); // remove in case something fails @@ -149,87 +158,53 @@ public string SendShard(string keyID, string[][] gKnCiphers, string[] yijCiphers throw new Exception("SendShard: One or more of the shares has expired"); } + if (yijCiphers.Length != MaxAmount) throw new Exception("SendShard: Did not recieve correct amount of ciphers"); + int numKeys = decryptedShares.All(s => s.Shares.Length == decryptedShares.First().Shares.Length) ? decryptedShares.First().Shares.Length : throw new Exception("SendShard: Different amount of shares provided"); BigInteger[] Y = new BigInteger[numKeys]; BigInteger[] k = state.K.Select(i => new BigInteger(i, true, true)).ToArray(); - Point[] gKntesti = new Point[numKeys]; Point[] gMultiplied = new Point[numKeys]; + byte[] gR_S; + Point Y_Pub; + + Point[] gKn = new Point[numKeys]; + for (int i = 0; i < numKeys; i++) gKn[i] = Curve.Infinity; // populate list with infinity + + for (int i = 0; i < numKeys; i++) { // Aggregate all shares to form final Y coordinate Y[i] = decryptedShares.Aggregate(BigInteger.Zero, (sum, point) => (sum + new BigInteger(point.Shares[i], true, true)) % Curve.N); - // Generate sharded public key for final verification - gKntesti[i] = Curve.G * Y[i]; - // Multiply the required multipliers if(i < gMultiplier.Length){ if(gMultiplier[i] is null) gMultiplied[i] = null; else if(gMultiplier[i].IsSafePoint()) gMultiplied[i] = gMultiplier[i] * k[i]; else throw new Exception("SendShard: Not all points supplied are safe"); } - } - - // Generate partial EdDSA R2 - BigInteger ri = Utils.RandomBigInt(); - Point gRi = Curve.G * ri; - - string cacheData = JsonSerializer.Serialize(new CacheState_SendShard - { - MgORKj = state.MgORKj, - ECDHij = state.ECDHij, - Yn = Y.Select(point => point.ToByteArray(true, true)).ToArray(), - Timestamp = timestamp, - Ri = ri.ToByteArray(true, true), - GKnCiphers = gKnCiphers, - Li = state.Li, - Stage = 3 - }); - - var response = JsonSerializer.Serialize(new SendShardResponse - { - EphKeyi = new BigInteger(state.EphKey, true, true).ToString(), - GKntesti = gKntesti.Select(point => point.ToByteArray()).ToArray(), - GMultiplied = gMultiplied.Select(point => point is null ? null : point.ToByteArray()).ToArray(), - GRi = gRi.ToByteArray() - }); - - _cachingManager.AddOrGetCache("KeyGen:" + keyID, cacheData).GetAwaiter().GetResult(); // add latest cache - - return response; - } - public string SetKey(string keyID, Point[] gKntest, Point R2, string[] EphKeyj) - { - string state_s = _cachingManager.AddOrGetCache("KeyGen:" + keyID, string.Empty).GetAwaiter().GetResult(); //Retrive the state cached from GenShard function - _cachingManager.Remove("KeyGen:" + keyID); // remove in case something fails - if(String.IsNullOrEmpty(state_s)) throw new Exception("SetKey: KeyID in state does not exist"); - - // Reastablish state - CacheState_SendShard state = JsonSerializer.Deserialize(state_s); - if(state.Stage != 3) throw new Exception("SetKey: Requests in wrong order"); - - // Decrypt the partial publics with EphKey - int numKeys = state.Yn.Length; - BigInteger[] ephKeys = EphKeyj.Select(k => BigInteger.Parse(k)).ToArray(); - var gKni = state.GKnCiphers[0].Select((_, i) => state.GKnCiphers.Select((cipher, j) => Point.FromBase64(AES.Decrypt(cipher[i], ephKeys[j])))); - Point[] gKn = gKni.Select(p => p.Aggregate((sum, next) => sum + next)).ToArray(); - - for(int i = 0; i < numKeys; i++) - { - // Verifying both publics - if(!gKn[i].isEqual(gKntest[i])) throw new Exception("SetKey: GKTest failed"); + // Validating the Zero Knowledge Proof + for (int j = 0; j < MaxAmount; j++) + { + if (!decryptedShares.All(share => + { + gR_S = share.RPubs[i].Concat(share.Si[i]).ToArray(); // concact R and S TODO: Maybe do this before? + Y_Pub = Point.FromBytes(share.SharePubs[i]); + gKn[i] = gKn[i] + Y_Pub; + return EdDSA.Verify(Array.Empty(), gR_S, Y_Pub); + })) throw new Exception("SendShard: Not all public signatures pass verification"); + } } // This is done only on first key Point R = state.MgORKj.Select(p => Point.From64Bytes(p)) .Aggregate(Curve.Infinity, (sum, next) => sum + next) + R2; - + // Prepare the signature message - byte[] MData_To_Hash = gKn[0].ToByteArray().Concat(Encoding.ASCII.GetBytes(state.Timestamp.ToString())).Concat(Encoding.ASCII.GetBytes(keyID)).ToArray(); // M = hash( gK[1] | timestamp | keyID ) + byte[] MData_To_Hash = gKn[0].ToByteArray().Concat(Encoding.ASCII.GetBytes(timestamp.ToString())).Concat(Encoding.ASCII.GetBytes(keyID)).ToArray(); // M = hash( gK[1] | timestamp | keyID ) byte[] M = SHA256.HashData(MData_To_Hash); byte[] HData_To_Hash = R.ToByteArray().Concat(gKn[0].ToByteArray()).Concat(M).ToArray(); BigInteger H = Utils.Mod(new BigInteger(SHA512.HashData(HData_To_Hash), true, false), Curve.N); @@ -238,26 +213,29 @@ public string SetKey(string keyID, Point[] gKntest, Point R2, string[] EphKeyj) // Generate the partial signature with ORK's lagrange BigInteger li = new BigInteger(state.Li, true, true); - BigInteger Y = new BigInteger(state.Yn[0], true, true); - BigInteger si = Utils.Mod(this.MSecOrki + ri + (H * Y * li), Curve.N); + BigInteger si = Utils.Mod(this.MSecOrki + ri + (H * Y[0] * li), Curve.N); + - // Encrypt latest state - string encrypted_state = AES.Encrypt(JsonSerializer.Serialize(new EncCommitState + string stateData = AES.Encrypt(JsonSerializer.Serialize(new EncCommitState { KeyID = keyID, - Timestampi = state.Timestamp, - gKn = gKn.Select(point => point.ToByteArray64()).ToArray(), - Yn = state.Yn, + Timestamp = timestamp, + gKn = gKn.Select(gK => gK.ToByteArray64()).ToArray(), + Yn = Y.Select(y => y.ToByteArray(true, true)).ToArray(), mgORKj = state.MgORKj, R2 = R2.ToByteArray64() }), MSecOrki); - return JsonSerializer.Serialize(new SetKeyResponse + var response = JsonSerializer.Serialize(new SendShardResponse { - Si = si.ToString(), - EncCommitState_Encrypted = encrypted_state, - GKn = gKn.Select(p => p.ToByteArray()).ToArray() + + GMultiplied = gMultiplied.Select(point => point is null ? null : point.ToByteArray()).ToArray(), + Si = si.ToByteArray(true, false), + GK1 = gKn[1].ToByteArray(), + EncCommitStatei = stateData }); + + return response; } public CommitResponse Commit(string keyID, BigInteger S, string encCommitStatei) @@ -269,13 +247,13 @@ public CommitResponse Commit(string keyID, BigInteger S, string encCommitStatei) { throw new Exception("Commit: KeyID of instanciated object does not equal that of previous state"); } - if (!VerifyDelay(state.Timestampi, DateTime.UtcNow.Ticks)) + if (!VerifyDelay(state.Timestamp, DateTime.UtcNow.Ticks)) { throw new Exception("Commit: State has expired"); } Point gK = Point.From64Bytes(state.gKn[0]); - byte[] MData_To_Hash = gK.ToByteArray().Concat(Encoding.ASCII.GetBytes(state.Timestampi.ToString()).Concat(Encoding.ASCII.GetBytes(keyID))).ToArray(); // M = hash( gK[1] | timestamp | keyID ) + byte[] MData_To_Hash = gK.ToByteArray().Concat(Encoding.ASCII.GetBytes(state.Timestamp.ToString()).Concat(Encoding.ASCII.GetBytes(keyID))).ToArray(); // M = hash( gK[1] | timestamp | keyID ) byte[] M = SHA256.HashData(MData_To_Hash); Point[] mgORKj = state.mgORKj.Select(mgORK => Point.From64Bytes(mgORK)).ToArray(); @@ -296,7 +274,7 @@ public CommitResponse Commit(string keyID, BigInteger S, string encCommitStatei) return new CommitResponse { KeyID = state.KeyID, - Timestampi = state.Timestampi, + Timestampi = state.Timestamp, mIDORK = mgORKj.Select(pub => Utils.Mod(new BigInteger(SHA256.HashData(Encoding.ASCII.GetBytes(pub.ToBase64())), false, true), Curve.N).ToString()).ToArray(), gKn = state.gKn.Select(p => Point.From64Bytes(p).ToBase64()).ToArray(), Yn = state.Yn.Select(y => new BigInteger(y, true, true).ToString()).ToArray(), @@ -330,75 +308,66 @@ private ShareData decryptShares(string encryptedShare, byte[] DHKey) return JsonSerializer.Deserialize(AES.Decrypt(encryptedShare, DHKey)); // decrypt encrypted share and create DataToEncrypt object } - private string encryptShares(byte[] key, PolyPoint[][] shares, int index, long timestampi, string keyID) + private string encryptShares(byte[] key, PolyPoint[][] shares, int index, long timestampi, string keyID, Point[] gKn, Point[] gRn, BigInteger[] Sn) { var data_to_encrypt = new ShareData { KeyID = keyID, Timestampi = timestampi.ToString(), Shares = shares.Select(pointShares => pointShares[index].Y.ToByteArray(true, true)).ToArray(), + SharePubs = gKn.Select(sharePub => sharePub.ToByteArray()).ToArray(), + RPubs = gRn.Select(gR => gR.ToByteArray()).ToArray(), + Si = Sn.Select(s => s.ToByteArray(true, false)).ToArray() }; return AES.Encrypt(JsonSerializer.Serialize(data_to_encrypt), key); } + internal class CacheState_GenShard { public byte[][] MgORKj { get; set; } // list of ORK Pubs public byte[][] ECDHij { get; set; } // list of ECDH Keys - public byte[] EphKey { get; set; } public int Stage { get; set; } public byte[][] K { get; set; } public byte[] Li { get; set; } + public byte[][] GKn { get; set; } // list of partial pubs + public byte[] Ri { get; set; } // little r for entry signing } - internal class CacheState_SendShard - { - public byte[][] MgORKj { get; set; } // list of ORK Pubs - public byte[][] ECDHij { get; set; } // list of ECDH Keys - public byte[][] Yn { get; set; } - public long Timestamp { get; set; } - public byte[] Ri { get; set; } - public string[][] GKnCiphers { get; set; } // stuff encrypted with eph key - public byte[] Li { get; set; } - public int Stage { get; set; } - } + internal class GenShardResponse { - public string[] GKnCiphers { get; set; } public string[] YijCiphers { get; set; } - public string Timestampi { get; set; } + public byte[] GRi { get; set; } } internal class SendShardResponse { - public string EphKeyi { get; set; } - public byte[][] GKntesti { get; set; } public byte[][] GMultiplied { get; set; } - public byte[] GRi { get; set; } + public byte[] Si { get; set; } + public byte[] GK1 { get; set; } + public string EncCommitStatei { get; set; } } internal class ShareData { public string KeyID { get; set; } public string Timestampi { get; set; } - public byte[][] Shares { get; set; } + public byte[][] Shares { get; set; } // Y[n]j + public byte[][] SharePubs { get; set; } // gK[n]i + public byte[][] RPubs { get; set; } // gR[n]i + public byte[][] Si { get; set; } // S[n]i } internal class EncCommitState { public string KeyID { get; set; } - public long Timestampi { get; set; } + public long Timestamp { get; set; } public byte[][] gKn { get; set; } public byte[][] Yn { get; set; } public byte[][] mgORKj { get; set; } public byte[] R2 { get; set; } } - internal class SetKeyResponse - { - public string Si { get; set; } - public string EncCommitState_Encrypted { get; set; } - public byte[][] GKn { get; set; } - } public class CommitResponse { From 1e41bd6f34d9da8ba627ef74737c87fac5323d28 Mon Sep 17 00:00:00 2001 From: Julio Date: Mon, 24 Apr 2023 19:03:33 +1000 Subject: [PATCH 3/9] updated H4x2-TideJS to follow new keyGen flow --- .../modules/H4x2-TideJS/Clients/NodeClient.js | 26 +------ .../H4x2-TideJS/Flow/dKeyGenerationFlow.js | 30 ++------ .../modules/H4x2-TideJS/Functions/SignUp.js | 10 ++- .../modules/H4x2-TideJS/Math/KeyGeneration.js | 72 +++++-------------- .../H4x2-TideJS/Models/GenShardResponse.js | 7 +- .../H4x2-TideJS/Models/SendShardResponse.js | 21 +++--- .../H4x2-TideJS/Models/SetKeyResponse.js | 21 ------ .../H4x2-TinySDK/Tools/KeyGenerator.cs | 4 +- 8 files changed, 47 insertions(+), 144 deletions(-) delete mode 100644 H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SetKeyResponse.js diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js index f8b18d0..fef4355 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js @@ -17,7 +17,6 @@ import Point from "../Ed25519/point.js" import GenShardResponse from "../Models/GenShardResponse.js"; -import SetKeyResponse from "../Models/SetKeyResponse.js"; import ClientBase from "./ClientBase.js" import SendShardResponse from "../Models/SendShardResponse.js"; @@ -79,14 +78,14 @@ export default class NodeClient extends ClientBase { /** * @param {string} uid * @param {string[]} shares - * @param {string[][]} gKnCiphers + * @param {Point} R2 * @param {Point[]} gMultipliers */ - async SendShard(uid, shares, gKnCiphers, gMultipliers) { + async SendShard(uid, shares, R2, gMultipliers) { const data = this._createFormData( { 'yijCipher': shares, - 'gKnCipher': gKnCiphers, + 'R2': R2, 'gMultipliers': gMultipliers.map(p => p == null ? "" : p.toBase64()) }); const response = await this._post(`/Create/SendShard?uid=${uid}`, data); @@ -95,25 +94,6 @@ export default class NodeClient extends ClientBase { return SendShardResponse.from(responseData); } - /** - * @param {string} uid - * @param {Point[]} gKntest - * @param {Point} R2 - * @param {string[]} ephKeyj - */ - async SetKey(uid, gKntest, R2, ephKeyj) { - const data = this._createFormData( - { - 'gKntesti': gKntest.map(gKtest => gKtest.toBase64()), - 'R2': R2.toBase64(), - 'ephKeyj': ephKeyj - } - ); - const response = await this._post(`/Create/SetKey?uid=${uid}`, data); - const responseData = await this._handleError(response, "SetKey"); - return SetKeyResponse.from(responseData) - } - /** * @param {string} uid diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Flow/dKeyGenerationFlow.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Flow/dKeyGenerationFlow.js index 6b48ca1..96fdfb7 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Flow/dKeyGenerationFlow.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Flow/dKeyGenerationFlow.js @@ -1,7 +1,6 @@ import NodeClient from "../Clients/NodeClient.js"; import Point from "../Ed25519/point.js"; -import { Commit_DecryptCVK, GenShardReply, SendShardReply, SetKeyValidation } from "../Math/KeyGeneration.js"; -import SetKeyResponse from "../Models/SetKeyResponse.js"; +import { Commit_DecryptCVK, GenShardReply, SendShardReply } from "../Math/KeyGeneration.js"; export default class dKeyGenerationFlow { /** @@ -31,34 +30,17 @@ export default class dKeyGenerationFlow { /** * @param {string} uid * @param {string[][]} YijCipher - * @param {string[][]} gKnCipher + * @param {Point} R2 * @param {Point[]} gMultipliers - */ - async SendShard(uid, YijCipher, gKnCipher, gMultipliers) { - const clients = this.orks.map(ork => new NodeClient(ork[1])) // create node clients - - const pre_SendShardResponses = clients.map((client, i) => client.SendShard(uid, YijCipher[i], gKnCipher, gMultipliers)) - const SendShardResponses = await Promise.all(pre_SendShardResponses); - - return SendShardReply(SendShardResponses, this.orks.map(ork => ork[0]), gKnCipher); - } - - /** - * @param {string} uid - * @param {Point[]} gKntest - * @param {Point[]} gKn - * @param {Point} R2 * @param {bigint} timestamp - * @param {Point[]} mgORKi - * @param {string[]} ephKeyj */ - async SetKey(uid, gKntest, gKn, R2, timestamp, mgORKi, ephKeyj) { + async SendShard(uid, YijCipher, R2, gMultipliers, timestamp) { const clients = this.orks.map(ork => new NodeClient(ork[1])) // create node clients - const pre_setKeyResponses = clients.map((client, i) => client.SetKey(uid, gKntest, R2, ephKeyj)); - const SetKeyResponses = await Promise.all(pre_setKeyResponses); + const pre_SendShardResponses = clients.map((client, i) => client.SendShard(uid, YijCipher[i], R2, gMultipliers)) + const SendShardResponses = await Promise.all(pre_SendShardResponses); - return await SetKeyValidation(SetKeyResponses, uid, gKn, gKntest, timestamp, mgORKi, R2); + return SendShardReply(uid, SendShardResponses, this.orks.map(ork => ork[2]), timestamp, R2); } /** diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Functions/SignUp.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Functions/SignUp.js index 80cc3a2..03ef9f9 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Functions/SignUp.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Functions/SignUp.js @@ -71,8 +71,8 @@ export default class SignUp { // Start Key Generation Flow const KeyGenFlow = new dKeyGenerationFlow(this.orkInfo); - const {sortedShares, timestamp, gKCiphers} = await KeyGenFlow.GenShard(uid, 2); // GenShard - const {gKntest, R2, gMultiplied, gKn, ephKeys} = await KeyGenFlow.SendShard(uid, sortedShares, gKCiphers, [null, passwordPoint_R]); + const {sortedShares, timestamp, R2} = await KeyGenFlow.GenShard(uid, 2); // GenShard + const {S, encCommitStatei, gMultiplied} = await KeyGenFlow.SendShard(uid, sortedShares, R2, [null, passwordPoint_R], timestamp); // Do Prism Flow const prismFlow = new PrismFlow(this.orkInfo); @@ -80,7 +80,6 @@ export default class SignUp { const prismAuthi = await prismFlow.GetPrismAuths(gMultiplied[1], random); // but later on, we'll only need one or the other, so i'm keeping them seperate // Resume Key Generation Flow - const {S, encCommitStatei} = await KeyGenFlow.SetKey(uid, gKntest, gKn, R2, timestamp, this.orkInfo.map(ork => ork[2]), ephKeys); const CVK = await KeyGenFlow.Commit(uid, S, encCommitStatei, prismAuthi, gPRISMAuth) const encryptedCode = await encryptData(secretCode, BigIntToByteArray(CVK)); @@ -105,8 +104,8 @@ export default class SignUp { // Start Key Generation Flow const KeyGenFlow = new dKeyGenerationFlow(this.orkInfo); - const {sortedShares, timestamp, gKCiphers} = await KeyGenFlow.GenShard(uid, 2); // GenShard - const {gKntest, R2, gMultiplied, gKn, ephKeys} = await KeyGenFlow.SendShard(uid, sortedShares, gKCiphers, [null, passwordPoint_R]); + const {sortedShares, timestamp, R2} = await KeyGenFlow.GenShard(uid, 2); // GenShard + const {S, encCommitStatei, gMultiplied} = await KeyGenFlow.SendShard(uid, sortedShares, R2, [null, passwordPoint_R], timestamp); // Do Prism Flow const prismFlow = new PrismFlow(this.orkInfo); @@ -114,7 +113,6 @@ export default class SignUp { const prismAuthi = await prismFlow.GetPrismAuths(gMultiplied[1], random); // but later on, we'll only need one or the other, so i'm keeping them seperate // Resume Key Generation Flow - const {S, encCommitStatei} = await KeyGenFlow.SetKey(uid, gKntest, gKn, R2, timestamp, this.orkInfo.map(ork => ork[2]), ephKeys); const CVK = await KeyGenFlow.Commit(uid, S, encCommitStatei, prismAuthi, gPRISMAuth) return {CVK: CVK, UID: uid} diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js index 634aa04..ec7f983 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js @@ -1,7 +1,6 @@ import Point from "../Ed25519/point.js"; import GenShardResponse from "../Models/GenShardResponse.js"; import SendShardResponse from "../Models/SendShardResponse.js"; -import SetKeyResponse from "../Models/SetKeyResponse.js"; import { createAESKey, decryptData, encryptData } from "../Tools/AES.js"; import { SHA256_Digest, SHA512_Digest } from "../Tools/Hash.js"; import { BigIntFromByteArray, BigIntToByteArray, bytesToBase64, ConcatUint8Arrays, median, mod, StringToUint8Array } from "../Tools/Utils.js"; @@ -12,80 +11,41 @@ import { GetLi } from "./SecretShare.js"; */ export function GenShardReply(genShardResponses){ const sortedShares = SortShares(genShardResponses.map(resp => resp.YijCiphers)); // sort shares so they can easily be sent to respective orks - const gKCiphers = genShardResponses.map(resp => resp.GKnCipher); // we need to send all gKCiphers to every ork const timestamp = median(genShardResponses.map(resp => resp.Timestampi)); - return {sortedShares: sortedShares, timestamp: timestamp, gKCiphers: gKCiphers}; + const R2 = genShardResponses.reduce((sum, next) => next.GRi.add(sum), Point.infinity); + return {sortedShares: sortedShares, timestamp: timestamp, R2: R2}; } /** + * @param {string} keyId * @param {SendShardResponse[]} sendShardResponses - * @param {string[]} orkIds - * @param {string[][]} gKCiphers - */ -export async function SendShardReply(sendShardResponses, orkIds, gKCiphers){ - // Assert all ork returned same number of responses - const equalLengthCheck = sendShardResponses.every(resp => resp.gKtesti.length == sendShardResponses[0].gKtesti.length && resp.gMultiplied.length == sendShardResponses[0].gMultiplied.length); - if(!equalLengthCheck) throw new Error("SendShardReply: An ORK returned a different number of points that others"); - const cipherLengthCheck = gKCiphers.every(cipher => cipher.length == gKCiphers[0].length); - if(!cipherLengthCheck) throw new Error("SendShardReply: ORKs returned different number of ciphers") - - // Decrypts the partial publics - const pre_ephKeys = sendShardResponses.map(async resp => await createAESKey(BigIntToByteArray(BigInt(resp.ephKeyi)), ["decrypt"])); - const ephKeys = await Promise.all(pre_ephKeys); - const pre_gKni = gKCiphers[0].map(async (_, i) => await Promise.all(gKCiphers.map(async (cipher, j) => Point.fromB64(await decryptData(cipher[i], ephKeys[j]))))); // Resolving a double array of promises - quite confusing - const gKni = await Promise.all(pre_gKni); - const gKn = gKni.map(p => p.reduce((sum, next) => sum.add(next))); - - // Calculate all lagrange coefficients for all the shards - const ids = orkIds.map(id => BigInt(id)); - const lis = ids.map(id => GetLi(id, ids, Point.order)); - - // Interpolate the key public - const gKntest = sendShardResponses[0].gKtesti.map((_, i) => sendShardResponses.reduce((sum, next, j) => sum.add(next.gKtesti[i].times(lis[j])), Point.infinity)); - - // Interpolate the gMultipliers - const gMultiplied = sendShardResponses[0].gMultiplied.map((m, i) => m == null ? null : sendShardResponses.reduce((sum, next) => sum.add(next.gMultiplied[i]), Point.infinity)); - - // Generate the partial EdDSA R - const R2 = sendShardResponses.reduce((sum, next) => sum.add(next.gRi), Point.infinity); - - //Check gKntest with gKn - const gKtestCHECK = gKn.every((p, i) => p.isEqual(gKntest[i])); - if(!gKtestCHECK) throw new Error("SendShardReply: GKTest check failed"); - - return {gKntest: gKntest, R2: R2, gMultiplied: gMultiplied, gKn: gKn, ephKeys: sendShardResponses.map(resp => resp.ephKeyi)}; -} - -/** - * - * @param {SetKeyResponse[]} setKeyResponses - * @param {string} keyID - * @param {Point[]} gKn - * @param {Point[]} gKntest - * @param {bigint} timestamp * @param {Point[]} mgORKi - * @param {Point} R2 + * @param {bigint} timestamp + * @param {Point} R2 */ -export async function SetKeyValidation(setKeyResponses, keyID, gKn, gKntest, timestamp, mgORKi, R2){ +export async function SendShardReply(keyId, sendShardResponses, mgORKi, timestamp, R2){ + // Verify all GK1s are the same + if(!sendShardResponses.every(resp => resp.gK1.isEqual(sendShardResponses[0]))) throw new Error("SendShardReply: Not all GK1s returned are the same."); + // Aggregate the signature - const S = mod(setKeyResponses.map(resp => BigInt(resp.S)).reduce((sum, next) => sum + next), Point.order); // sum all responses in finite field of Point.order + const S = mod(sendShardResponses.reduce((sum, next) => next.Si + sum, BigInt(0))); // Generate EdDSA R from all the ORKs publics - const M_data_to_hash = ConcatUint8Arrays([gKn[0].compress(), StringToUint8Array(timestamp.toString()), StringToUint8Array(keyID)]); + const M_data_to_hash = ConcatUint8Arrays([sendShardResponses[0].gK1.compress(), StringToUint8Array(timestamp.toString()), StringToUint8Array(keyId)]); const M = await SHA256_Digest(M_data_to_hash); const R = mgORKi.reduce((sum, next) => sum.add(next)).add(R2); // Prepare the signature message - const H_data_to_hash = ConcatUint8Arrays([R.compress(), gKntest[0].compress(), M]); + const H_data_to_hash = ConcatUint8Arrays([R.compress(), sendShardResponses[0].gK1.compress(), M]); const H = mod(BigIntFromByteArray(await SHA512_Digest(H_data_to_hash)), Point.order); // Verify signature validates - if(!(Point.g.times(S).isEqual(R.add(gKntest[0].times(H))))) throw new Error("SetKeyValidation: Signature test failed"); + if(!(Point.g.times(S).isEqual(R.add(sendShardResponses[0].gK1.times(H))))) throw new Error("SetKeyValidation: Signature test failed"); - // Create Encrypted State list - const encCommitStatei = setKeyResponses.map(resp => resp.EncCommitStatei); + // Interpolate the gMultipliers + const gMultiplied = sendShardResponses[0].gMultiplied.map((m, i) => m == null ? null : sendShardResponses.reduce((sum, next) => sum.add(next.gMultiplied[i]), Point.infinity)); - return {S: S, encCommitStatei: encCommitStatei}; + return {S: S, encCommitStatei: sendShardResponses.map(resp => resp.encCommitStatei), gMultiplied: gMultiplied}; } /** diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js index 9eeed93..95092d0 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js @@ -3,17 +3,18 @@ import Point from "../Ed25519/point.js" export default class GenShardResponse{ /** * @param {string[]} YijCiphers - * @param {string[]} gKnCipher + * @param {Point} GRi * @param {bigint} Timestampi */ - constructor(YijCiphers, gKnCipher, Timestampi){ + constructor(YijCiphers, GRi, Timestampi){ this.YijCiphers = YijCiphers - this.GKnCipher = gKnCipher + this.GRi = GRi this.Timestampi = Timestampi } static from(data){ const obj = JSON.parse(data); const timestampi = BigInt(obj.Timestampi); + const gRi = Point.fromB64(obj.GRi) return new GenShardResponse(obj.YijCiphers, obj.GKnCiphers, timestampi); } } \ No newline at end of file diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SendShardResponse.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SendShardResponse.js index 780cdef..36a95d6 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SendShardResponse.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SendShardResponse.js @@ -1,24 +1,25 @@ import Point from "../Ed25519/point.js"; +import { BigIntFromByteArray, base64ToBytes } from "../Tools/Utils.js"; export default class SendShardResponse{ /** - * @param {Point[]} gKtesti - * @param {Point} gRi + * @param {bigint} Si + * @param {Point} gK1 + * @param {string} encCommitStatei * @param {Point[]} gMultiplied - * @param {string} ephKeyi */ - constructor(gKtesti, gRi, gMultiplied, ephKeyi){ - this.gKtesti = gKtesti - this.gRi = gRi + constructor(Si, gK1, encCommitStatei, gMultiplied){ + this.Si = Si + this.gK1 = gK1 + this.encCommitStatei = encCommitStatei this.gMultiplied = gMultiplied - this.ephKeyi = ephKeyi } static from(data){ const obj = JSON.parse(data); - const gKtesti = obj.GKntesti.map(p => Point.fromB64(p)); - const gRi = Point.fromB64(obj.GRi); + const si = BigIntFromByteArray(base64ToBytes(obj.Si)); + const gK1 = Point.fromB64(obj.GK1); const gMultiplied = obj.GMultiplied.map(p => p == null ? null : Point.fromB64(p)); - return new SendShardResponse(gKtesti, gRi, gMultiplied, obj.EphKeyi); + return new SendShardResponse(si, gK1, obj.EncCommitStatei, gMultiplied); } } \ No newline at end of file diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SetKeyResponse.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SetKeyResponse.js deleted file mode 100644 index aa1ef05..0000000 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/SetKeyResponse.js +++ /dev/null @@ -1,21 +0,0 @@ -import Point from "../Ed25519/point.js"; - -export default class SetKeyResponse{ - /** - * - * @param {bigint} s - * @param {string} encCommitStatei - * @param {Point[]} gKn - */ - constructor(s, encCommitStatei, gKn){ - this.S = s - this.EncCommitStatei = encCommitStatei - this.gKn = gKn - } - - static from(data){ - const obj = JSON.parse(data); - const gKn = obj.GKn.map(p => Point.fromB64(p)); - return new SetKeyResponse(BigInt(obj.Si), obj.EncCommitState_Encrypted, gKn); - } -} \ No newline at end of file diff --git a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs index e42b66c..ef383a3 100644 --- a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs +++ b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs @@ -121,7 +121,8 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) GenShardResponse response = new GenShardResponse { YijCiphers = YCiphers, - GRi = gRi.ToByteArray() + GRi = gRi.ToByteArray(), + Timestampi = timestampi }; _cachingManager.AddOrGetCache("KeyGen:" + keyID, cacheState).GetAwaiter().GetResult(); // add state to memory @@ -337,6 +338,7 @@ internal class CacheState_GenShard internal class GenShardResponse { + public long Timestampi { get; set; } public string[] YijCiphers { get; set; } public byte[] GRi { get; set; } } From bf2cb3eff4f334ebec065d7edc761a1bd1bd5541 Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 26 Apr 2023 16:54:05 +1000 Subject: [PATCH 4/9] finished implementation of key gen 3.1 --- .../H4x2-Node/Controllers/CreateController.cs | 21 ++------------ H4x2-Node/H4x2-Node/H4x2-Node.csproj | 2 +- H4x2-Node/H4x2-Node/Program.cs | 2 +- .../modules/H4x2-TideJS/Clients/NodeClient.js | 2 +- .../modules/H4x2-TideJS/Math/KeyGeneration.js | 4 +-- .../H4x2-TideJS/Models/GenShardResponse.js | 2 +- .../H4x2-Simulator/appsettings.json | 2 +- H4x2-TinySDK/H4x2-TinySDK/H4x2-TinySDK.csproj | 11 +++++++- .../H4x2-TinySDK/Tools/KeyGenerator.cs | 28 ++++++++----------- 9 files changed, 31 insertions(+), 43 deletions(-) diff --git a/H4x2-Node/H4x2-Node/Controllers/CreateController.cs b/H4x2-Node/H4x2-Node/Controllers/CreateController.cs index 5b1b121..b520317 100644 --- a/H4x2-Node/H4x2-Node/Controllers/CreateController.cs +++ b/H4x2-Node/H4x2-Node/Controllers/CreateController.cs @@ -63,31 +63,14 @@ public async Task GenShard([FromQuery] string uid, int numKeys, I } [HttpPost] - public IActionResult SendShard([FromQuery] string uid, string[] yijCipher, string[] gKnCipher, string[] gMultipliers) + public IActionResult SendShard([FromQuery] string uid, string[] yijCipher, string[] gMultipliers, Point R2) { try { if (uid == null) throw new ArgumentNullException("uid cannot be null"); - string[][] gKnCiphers = gKnCipher.Select(c => c.Split(",")).ToArray(); // when we need to pass double array - consider cleaning up in future Point[] gMultiplier = Utils.GetPointList(gMultipliers); - var response = _keyGenerator.SendShard(uid, gKnCiphers, yijCipher, gMultiplier); - return Ok(response); - }catch(Exception ex){ - return Ok("--FAILED--:" + ex.Message); - } - } - - [HttpPost] - public IActionResult SetKey([FromQuery] string uid, string[] gKntesti, Point R2, string[] ephKeyj) - { - try - { - if (uid == null) throw new ArgumentNullException("uid cannot be null"); - - Point[] gKntesti_P = Utils.GetPointList(gKntesti).ToArray(); - - var response = _keyGenerator.SetKey(uid, gKntesti_P, R2, ephKeyj); + var response = _keyGenerator.SendShard(uid, yijCipher, gMultiplier, R2); return Ok(response); }catch(Exception ex){ return Ok("--FAILED--:" + ex.Message); diff --git a/H4x2-Node/H4x2-Node/H4x2-Node.csproj b/H4x2-Node/H4x2-Node/H4x2-Node.csproj index 7013949..ead5dd8 100644 --- a/H4x2-Node/H4x2-Node/H4x2-Node.csproj +++ b/H4x2-Node/H4x2-Node/H4x2-Node.csproj @@ -14,7 +14,7 @@ - + diff --git a/H4x2-Node/H4x2-Node/Program.cs b/H4x2-Node/H4x2-Node/Program.cs index 90fb636..abc958a 100644 --- a/H4x2-Node/H4x2-Node/Program.cs +++ b/H4x2-Node/H4x2-Node/Program.cs @@ -27,7 +27,7 @@ var builder = WebApplication.CreateBuilder(args); -var version = "H4x2-ORK:3.0"; +var version = "H4x2-ORK:3.1"; var isThrottled = true; var key = new Key(BigInteger.Parse(args.Length == 0 ? Environment.GetEnvironmentVariable("TIDE_KEY") : args[0])); var threshold = 3; diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js index fef4355..b50f672 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Clients/NodeClient.js @@ -85,7 +85,7 @@ export default class NodeClient extends ClientBase { const data = this._createFormData( { 'yijCipher': shares, - 'R2': R2, + 'R2': R2.toBase64(), 'gMultipliers': gMultipliers.map(p => p == null ? "" : p.toBase64()) }); const response = await this._post(`/Create/SendShard?uid=${uid}`, data); diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js index ec7f983..949053f 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Math/KeyGeneration.js @@ -25,7 +25,7 @@ export function GenShardReply(genShardResponses){ */ export async function SendShardReply(keyId, sendShardResponses, mgORKi, timestamp, R2){ // Verify all GK1s are the same - if(!sendShardResponses.every(resp => resp.gK1.isEqual(sendShardResponses[0]))) throw new Error("SendShardReply: Not all GK1s returned are the same."); + if(!sendShardResponses.every(resp => resp.gK1.isEqual(sendShardResponses[0].gK1))) throw new Error("SendShardReply: Not all GK1s returned are the same."); // Aggregate the signature const S = mod(sendShardResponses.reduce((sum, next) => next.Si + sum, BigInt(0))); @@ -40,7 +40,7 @@ export async function SendShardReply(keyId, sendShardResponses, mgORKi, timestam const H = mod(BigIntFromByteArray(await SHA512_Digest(H_data_to_hash)), Point.order); // Verify signature validates - if(!(Point.g.times(S).isEqual(R.add(sendShardResponses[0].gK1.times(H))))) throw new Error("SetKeyValidation: Signature test failed"); + if(!(Point.g.times(S).isEqual(R.add(sendShardResponses[0].gK1.times(H))))) throw new Error("SendShard: Signature test failed"); // Interpolate the gMultipliers const gMultiplied = sendShardResponses[0].gMultiplied.map((m, i) => m == null ? null : sendShardResponses.reduce((sum, next) => sum.add(next.gMultiplied[i]), Point.infinity)); diff --git a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js index 95092d0..2cee536 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js +++ b/H4x2-Node/H4x2-Node/wwwroot/modules/H4x2-TideJS/Models/GenShardResponse.js @@ -15,6 +15,6 @@ export default class GenShardResponse{ const obj = JSON.parse(data); const timestampi = BigInt(obj.Timestampi); const gRi = Point.fromB64(obj.GRi) - return new GenShardResponse(obj.YijCiphers, obj.GKnCiphers, timestampi); + return new GenShardResponse(obj.YijCiphers, gRi, timestampi); } } \ No newline at end of file diff --git a/H4x2-Simulator/H4x2-Simulator/appsettings.json b/H4x2-Simulator/H4x2-Simulator/appsettings.json index 5802242..7d17127 100644 --- a/H4x2-Simulator/H4x2-Simulator/appsettings.json +++ b/H4x2-Simulator/H4x2-Simulator/appsettings.json @@ -11,7 +11,7 @@ }, "AllowedHosts": "*", "Ork": { - "Version": "3.0" + "Version": "3.1" } } diff --git a/H4x2-TinySDK/H4x2-TinySDK/H4x2-TinySDK.csproj b/H4x2-TinySDK/H4x2-TinySDK/H4x2-TinySDK.csproj index 01d21fd..b5a5a3a 100644 --- a/H4x2-TinySDK/H4x2-TinySDK/H4x2-TinySDK.csproj +++ b/H4x2-TinySDK/H4x2-TinySDK/H4x2-TinySDK.csproj @@ -9,9 +9,18 @@ $(AssemblyName) Tide https://github.com/tide-foundation/Tide-h4x2 - 0.1.10 + 0.1.11 H4x2-TinySDK + tcocl-2_0_txt.txt + True + + + + True + \ + + diff --git a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs index ef383a3..83173d7 100644 --- a/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs +++ b/H4x2-TinySDK/H4x2-TinySDK/Tools/KeyGenerator.cs @@ -59,9 +59,9 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) { throw new Exception("GenShard: Number of ork keys provided must be greater than 1"); } - if (numKeys < 1) + if (numKeys < 1 || numKeys > 5) { - throw new Exception("GenShard: Number of keys requested must be at minimum 1"); + throw new Exception("GenShard: Number of keys requested must be at minimum 1, maximum 4"); } @@ -122,7 +122,7 @@ public string GenShard(string keyID, Point[] mgORKj, int numKeys) { YijCiphers = YCiphers, GRi = gRi.ToByteArray(), - Timestampi = timestampi + Timestampi = timestampi.ToString() }; _cachingManager.AddOrGetCache("KeyGen:" + keyID, cacheState).GetAwaiter().GetResult(); // add state to memory @@ -188,18 +188,14 @@ public string SendShard(string keyID, string[] yijCiphers, Point[] gMultiplier, } // Validating the Zero Knowledge Proof - for (int j = 0; j < MaxAmount; j++) + if (!decryptedShares.All(share => { - if (!decryptedShares.All(share => - { - gR_S = share.RPubs[i].Concat(share.Si[i]).ToArray(); // concact R and S TODO: Maybe do this before? - Y_Pub = Point.FromBytes(share.SharePubs[i]); - gKn[i] = gKn[i] + Y_Pub; - return EdDSA.Verify(Array.Empty(), gR_S, Y_Pub); - })) throw new Exception("SendShard: Not all public signatures pass verification"); - } + gR_S = share.RPubs[i].Concat(share.Si[i].PadRight(32)).ToArray(); // concact R and S TODO: Maybe do this before? + Y_Pub = Point.FromBytes(share.SharePubs[i]); + gKn[i] = gKn[i] + Y_Pub; + return EdDSA.Verify(Array.Empty(), gR_S, Y_Pub); + })) throw new Exception("SendShard: Not all public signatures pass verification"); } - // This is done only on first key Point R = state.MgORKj.Select(p => Point.From64Bytes(p)) .Aggregate(Curve.Infinity, (sum, next) => sum + next) + R2; @@ -210,7 +206,7 @@ public string SendShard(string keyID, string[] yijCiphers, Point[] gMultiplier, byte[] HData_To_Hash = R.ToByteArray().Concat(gKn[0].ToByteArray()).Concat(M).ToArray(); BigInteger H = Utils.Mod(new BigInteger(SHA512.HashData(HData_To_Hash), true, false), Curve.N); - BigInteger ri = new BigInteger(state.Ri, true, true); // restablish little r + BigInteger ri = new BigInteger(state.Ri, true, false); // restablish little r // Generate the partial signature with ORK's lagrange BigInteger li = new BigInteger(state.Li, true, true); @@ -232,7 +228,7 @@ public string SendShard(string keyID, string[] yijCiphers, Point[] gMultiplier, GMultiplied = gMultiplied.Select(point => point is null ? null : point.ToByteArray()).ToArray(), Si = si.ToByteArray(true, false), - GK1 = gKn[1].ToByteArray(), + GK1 = gKn[0].ToByteArray(), EncCommitStatei = stateData }); @@ -338,7 +334,7 @@ internal class CacheState_GenShard internal class GenShardResponse { - public long Timestampi { get; set; } + public string Timestampi { get; set; } public string[] YijCiphers { get; set; } public byte[] GRi { get; set; } } From 0a05015a258bf4db91a6013bce6decb7de233fb3 Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 26 Apr 2023 18:40:12 +1000 Subject: [PATCH 5/9] updated sim url for staging --- H4x2-Node/H4x2-Node/appsettings.json | 2 +- H4x2-Vendor/H4x2-Vendor/appsettings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/H4x2-Node/H4x2-Node/appsettings.json b/H4x2-Node/H4x2-Node/appsettings.json index 75a6a31..cdbeb76 100644 --- a/H4x2-Node/H4x2-Node/appsettings.json +++ b/H4x2-Node/H4x2-Node/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://new-simulator.australiaeast.cloudapp.azure.com" + "Api": "https://h4x-staging-simulator.azurewebsites.net" } } } \ No newline at end of file diff --git a/H4x2-Vendor/H4x2-Vendor/appsettings.json b/H4x2-Vendor/H4x2-Vendor/appsettings.json index db7fc20..f0645b7 100644 --- a/H4x2-Vendor/H4x2-Vendor/appsettings.json +++ b/H4x2-Vendor/H4x2-Vendor/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://new-simulator.australiaeast.cloudapp.azure.com" + "Api": "https://h4x-staging-simulator.azurewebsites.net" } } } From 0c1632f0d1c80529824406c671c03ce1fdd8bfcf Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 26 Apr 2023 19:00:16 +1000 Subject: [PATCH 6/9] test --- H4x2-Simulator/H4x2-Simulator/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/H4x2-Simulator/H4x2-Simulator/Program.cs b/H4x2-Simulator/H4x2-Simulator/Program.cs index c72865f..af40db4 100644 --- a/H4x2-Simulator/H4x2-Simulator/Program.cs +++ b/H4x2-Simulator/H4x2-Simulator/Program.cs @@ -1,6 +1,8 @@ using H4x2_Simulator.Helpers; using H4x2_Simulator.Services; +Console.WriteLine("Hello!"); + var builder = WebApplication.CreateBuilder(args); // Add services to the container. From b35ce48baa224755585c084bf8e16393c08f55ea Mon Sep 17 00:00:00 2001 From: sundayScoop <87186823+sundayScoop@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:19:14 +1000 Subject: [PATCH 7/9] Update appsettings.json --- H4x2-Node/H4x2-Node/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/H4x2-Node/H4x2-Node/appsettings.json b/H4x2-Node/H4x2-Node/appsettings.json index cdbeb76..596681e 100644 --- a/H4x2-Node/H4x2-Node/appsettings.json +++ b/H4x2-Node/H4x2-Node/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://h4x-staging-simulator.azurewebsites.net" + "Api": "https://h4x-simulator-staging.azurewebsites.net" } } -} \ No newline at end of file +} From 3683a1896c9a39d0fca90502acd153b1685e4b5a Mon Sep 17 00:00:00 2001 From: sundayScoop <87186823+sundayScoop@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:19:34 +1000 Subject: [PATCH 8/9] Update appsettings.json --- H4x2-Vendor/H4x2-Vendor/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/H4x2-Vendor/H4x2-Vendor/appsettings.json b/H4x2-Vendor/H4x2-Vendor/appsettings.json index f0645b7..9bb192c 100644 --- a/H4x2-Vendor/H4x2-Vendor/appsettings.json +++ b/H4x2-Vendor/H4x2-Vendor/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://h4x-staging-simulator.azurewebsites.net" + "Api": "https://h4x-simulator-staging.azurewebsites.net" } } } From ab94faeab710126858695b0f929249e38a5cc78b Mon Sep 17 00:00:00 2001 From: sundayScoop <87186823+sundayScoop@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:04:07 +1000 Subject: [PATCH 9/9] updated urls for production --- H4x2-Node/H4x2-Node/appsettings.json | 2 +- H4x2-Node/H4x2-Node/wwwroot/js/main.js | 8 ++++---- H4x2-Vendor/H4x2-Vendor/appsettings.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/H4x2-Node/H4x2-Node/appsettings.json b/H4x2-Node/H4x2-Node/appsettings.json index 596681e..2c7281a 100644 --- a/H4x2-Node/H4x2-Node/appsettings.json +++ b/H4x2-Node/H4x2-Node/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://h4x-simulator-staging.azurewebsites.net" + "Api": "https://new-simulator.australiaeast.cloudapp.azure.com" } } } diff --git a/H4x2-Node/H4x2-Node/wwwroot/js/main.js b/H4x2-Node/H4x2-Node/wwwroot/js/main.js index 955a1fa..bdf7e9a 100644 --- a/H4x2-Node/H4x2-Node/wwwroot/js/main.js +++ b/H4x2-Node/H4x2-Node/wwwroot/js/main.js @@ -162,7 +162,7 @@ import { SignIn, SimulatorFlow, SignUp, Point } from "../modules/H4x2-TideJS/ind $('#loader').show(); var config = { simulatorUrl: 'https://new-simulator.australiaeast.cloudapp.azure.com/', - vendorUrl: 'https://h4x-staging-vendor.azurewebsites.net/' + vendorUrl: 'https://h4x22vendor.azurewebsites.net/' } var signin = new SignIn(config); var signinResponse = signin.start_Heimdall(user, pass); @@ -184,7 +184,7 @@ import { SignIn, SimulatorFlow, SignUp, Point } from "../modules/H4x2-TideJS/ind $('#loader').show(); var config = { simulatorUrl: 'https://new-simulator.australiaeast.cloudapp.azure.com/', - vendorUrl: 'https://h4x-staging-vendor.azurewebsites.net/' + vendorUrl: 'https://h4x22vendor.azurewebsites.net/' } var signin = new SignIn(config); var signinResponse = signin.start(user, pass); @@ -216,7 +216,7 @@ import { SignIn, SimulatorFlow, SignUp, Point } from "../modules/H4x2-TideJS/ind var config = { orkInfo: orkUrls.sort((a, b) => a[0].localeCompare(b[0])), //Sorting orklist based on ork Id, simulatorUrl: 'https://new-simulator.australiaeast.cloudapp.azure.com/', - vendorUrl: 'https://h4x-staging-vendor.azurewebsites.net/' + vendorUrl: 'https://h4x22vendor.azurewebsites.net/' } var signup = new SignUp(config); @@ -248,7 +248,7 @@ import { SignIn, SimulatorFlow, SignUp, Point } from "../modules/H4x2-TideJS/ind var config = { orkInfo: orkUrls.sort((a, b) => a[0].localeCompare(b[0])), //Sorting orklist based on ork Id, simulatorUrl: 'https://new-simulator.australiaeast.cloudapp.azure.com/', - vendorUrl: 'https://h4x-staging-vendor.azurewebsites.net/' + vendorUrl: 'https://h4x22vendor.azurewebsites.net/' } var signup = new SignUp(config); diff --git a/H4x2-Vendor/H4x2-Vendor/appsettings.json b/H4x2-Vendor/H4x2-Vendor/appsettings.json index 9bb192c..db7fc20 100644 --- a/H4x2-Vendor/H4x2-Vendor/appsettings.json +++ b/H4x2-Vendor/H4x2-Vendor/appsettings.json @@ -12,7 +12,7 @@ }, "Endpoints": { "Simulator": { - "Api": "https://h4x-simulator-staging.azurewebsites.net" + "Api": "https://new-simulator.australiaeast.cloudapp.azure.com" } } }