Skip to content

Commit 9c9d73e

Browse files
committed
chore: extract ChameleonHash and ChameleonSignature domain model
1 parent 33dba49 commit 9c9d73e

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

EccSDK/ChameleonHashHelper.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,44 @@ public static class ChameleonHashHelper
99
// Kn = public key
1010
// kn = private key
1111

12-
public static BigInteger Sign(ChameleonHashRequest request)
12+
public static ChameleonSignature Sign(ChameleonHashRequest request)
1313
{
1414
// sign = (sessionKey - dn) mod n
1515
// dn = H(m) * kn
1616
var msgHash = HashHelper.Sha256(request.Message);
1717
var dn = msgHash.Multiply(request.KeyPair.PrivateKey);
18-
return request.SessionKey.Add(dn).Mod(request.Order);
18+
return new ChameleonSignature()
19+
{
20+
Value = request.SessionKey.Add(dn).Mod(request.Order)
21+
};
1922
}
2023

2124
public static bool Verify(ChameleonHashRequest request, ECPoint rightChameleonHash)
2225
{
23-
return GetChameleonHash(request).Equals(rightChameleonHash);
26+
var chameleohHash = GetChameleonHash(request);
27+
return chameleohHash.Value.Equals(rightChameleonHash);
2428
}
2529

26-
public static ECPoint GetChameleonHash(ChameleonHashRequest request)
30+
public static ChameleonHash GetChameleonHash(ChameleonHashRequest request)
2731
{
2832
// chameleonHash = [Kn x H(m)] + [P x sessionKey]
2933
var msgHash = HashHelper.Sha256(request.Message);
3034
var rP = request.KeyPair.BasePoint.Multiply(request.Signature);
31-
var chameleonHash = request.KeyPair.PublicKey.Multiply(msgHash).Add(rP).Normalize();
32-
return chameleonHash;
35+
36+
return new ChameleonHash()
37+
{
38+
Value = request.KeyPair.PublicKey.Multiply(msgHash).Add(rP).Normalize()
39+
};
3340
}
3441

42+
}
43+
44+
public class ChameleonHash
45+
{
46+
public ECPoint Value { get; set; }
47+
}
48+
49+
public class ChameleonSignature
50+
{
51+
public BigInteger Value { get; set; }
3552
}

EccSdkUnitTest/EccSdkTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public void should_pass_verification()
3232
Message = "Hello World",
3333
Order = _keyPair.PublicKey.Curve.Order,
3434
SessionKey = new BigInteger("1234567890"),
35-
Signature = sign
35+
Signature = sign.Value
3636
});
3737

3838
var result = ChameleonHashHelper.Verify(new ChameleonHashRequest
3939
{
4040
KeyPair = _keyPair,
4141
Message = "Hello World",
4242
Order = _keyPair.PublicKey.Curve.Order,
43-
Signature = sign
44-
}, chameleonHash);
43+
Signature = sign.Value
44+
}, chameleonHash.Value);
4545

4646
Assert.That(result, Is.True);
4747
}
@@ -63,16 +63,16 @@ public void should_not_pass()
6363
Message = "Hello World",
6464
Order = _keyPair.PublicKey.Curve.Order,
6565
SessionKey = new BigInteger("1234567890"),
66-
Signature = sign
66+
Signature = sign.Value
6767
});
6868

6969
var result = ChameleonHashHelper.Verify(new ChameleonHashRequest
7070
{
7171
KeyPair = _keyPair,
7272
Message = "Hello World123",
7373
Order = _keyPair.PublicKey.Curve.Order,
74-
Signature = sign
75-
}, chameleonHash);
74+
Signature = sign.Value
75+
}, chameleonHash.Value);
7676

7777
Assert.That(result, Is.False);
7878

0 commit comments

Comments
 (0)