Skip to content

Commit

Permalink
HOTFIX/v1.1.0.28-2
Browse files Browse the repository at this point in the history
  • Loading branch information
livebe01 committed May 1, 2023
1 parent 19b124b commit 4b21222
Show file tree
Hide file tree
Showing 30 changed files with 2,030 additions and 1,551 deletions.
20 changes: 6 additions & 14 deletions gen-val/json-files/LMS-sigVer-1.0/expectedResults.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
},
{
"tcId": 2,
"testPassed": false
},
{
"tcId": 3,
"testPassed": true
},
{
"tcId": 4,
"tcId": 3,
"testPassed": false
},
{
"tcId": 5,
"tcId": 4,
"testPassed": false
}
]
},
{
"tgId": 2,
"tests": [
{
"tcId": 5,
"testPassed": true
},
{
"tcId": 6,
"testPassed": false
Expand All @@ -44,14 +44,6 @@
{
"tcId": 8,
"testPassed": false
},
{
"tcId": 9,
"testPassed": true
},
{
"tcId": 10,
"testPassed": false
}
]
}
Expand Down
80 changes: 33 additions & 47 deletions gen-val/json-files/LMS-sigVer-1.0/internalProjection.json

Large diffs are not rendered by default.

60 changes: 25 additions & 35 deletions gen-val/json-files/LMS-sigVer-1.0/prompt.json

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions gen-val/json-files/LMS-sigVer-1.0/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
{
"tcId": 8,
"result": "passed"
},
{
"tcId": 9,
"result": "passed"
},
{
"tcId": 10,
"result": "passed"
}
]
}

Large diffs are not rendered by default.

1,550 changes: 814 additions & 736 deletions gen-val/json-files/RSA-DecryptionPrimitive-Sp800-56Br2/internalProjection.json

Large diffs are not rendered by default.

1,153 changes: 713 additions & 440 deletions gen-val/json-files/RSA-DecryptionPrimitive-Sp800-56Br2/prompt.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -361,30 +361,6 @@
{
"tcId": 90,
"result": "passed"
},
{
"tcId": 91,
"result": "passed"
},
{
"tcId": 92,
"result": "passed"
},
{
"tcId": 93,
"result": "passed"
},
{
"tcId": 94,
"result": "passed"
},
{
"tcId": 95,
"result": "passed"
},
{
"tcId": 96,
"result": "passed"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public KeyPair ComposeKey(BigInteger e, PrimePair primes)
DMQ1 = d % (primes.Q - 1),
IQMP = primes.Q.ModularInverse(primes.P),
P = primes.P,
Q = primes.Q
Q = primes.Q,
D = d
},
PubKey = new PublicKey
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NIST.CVP.ACVTS.Libraries.Common.Helpers;
using NIST.CVP.ACVTS.Libraries.Crypto.Common.Asymmetric.DSA.FFC.Enums;
Expand Down Expand Up @@ -31,7 +30,6 @@ public Task<List<TestGroup>> BuildTestGroupsAsync(Parameters parameters)
N = capability.N,
HashAlg = ShaAttributes.GetHashFunctionFromName(hashAlg),
PQTestCaseExpectationProvider = new PQTestCaseExpectationProvider(parameters.IsSample),

TestType = TEST_TYPE
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public TestCaseExpectationProvider(bool isSample = false)
{
new(LmsSignatureDisposition.None),
new(LmsSignatureDisposition.ModifySignature),
new(LmsSignatureDisposition.ModifyKey),
new(LmsSignatureDisposition.ModifyMessage),
new(LmsSignatureDisposition.ModifyHeader)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestCaseGeneratorAft : ITestCaseGeneratorAsync<TestGroup, TestCase>
{
private readonly IOracle _oracle;

public int NumberOfTestCasesToGenerate => 5;
public int NumberOfTestCasesToGenerate => 4;

public TestCaseGeneratorAft(IOracle oracle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ protected override Predicate<object> TestCaseSerialization(JsonProperty jsonProp
var stdIncludeProperties = new[]
{
nameof(TestCase.TestCaseId),
nameof(TestCase.CipherText)
};

var aftIncludeProperties = new[]
{
nameof(TestCase.CipherText),
nameof(TestCase.N),
nameof(TestCase.E),
nameof(TestCase.P),
nameof(TestCase.Q),
nameof(TestCase.D)
};

var crtIncludeProperties = new[]
{
nameof(TestCase.Dmp1),
Expand Down Expand Up @@ -62,11 +60,6 @@ protected override Predicate<object> TestCaseSerialization(JsonProperty jsonProp
return false;
}
if (aftIncludeProperties.Contains(jsonProperty.UnderlyingName, StringComparer.OrdinalIgnoreCase))
{
return true;
}
return false;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
namespace NIST.CVP.ACVTS.Libraries.Generation.RSA.Sp800_56Br2.DpComponent.ContractResolvers
{
public class ResultProjectionContractResolver : ProjectionContractResolverBase<TestGroup, TestCase>
{
public ResultProjectionContractResolver()
{
}

{
protected override Predicate<object> TestGroupSerialization(JsonProperty jsonProperty)
{
var includeProperties = new[]
Expand All @@ -32,7 +28,8 @@ protected override Predicate<object> TestCaseSerialization(JsonProperty jsonProp
var includeProperties = new[]
{
nameof(TestCase.TestCaseId),
nameof(TestCase.PlainText)
nameof(TestCase.PlainText),
nameof(TestCase.TestPassed)
};

if (includeProperties.Contains(jsonProperty.UnderlyingName, StringComparer.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Numerics;
using Newtonsoft.Json;
using NIST.CVP.ACVTS.Libraries.Crypto.Common.Asymmetric.RSA.Keys;
using NIST.CVP.ACVTS.Libraries.Generation.Core;
using NIST.CVP.ACVTS.Libraries.Math;

Expand All @@ -18,12 +17,13 @@ public class TestCase : ITestCase<TestGroup, TestCase>

[JsonProperty(PropertyName = "pt")]
public BitString PlainText { get; set; }

public BigInteger Dmp1 { get; set; }
public BigInteger Dmq1 { get; set; }
public BigInteger Iqmp { get; set; }
public BigInteger P { get; set; }
public BigInteger Q { get; set; }
public BigInteger D { get; set; }
public BigInteger N { get; set; }
public BigInteger E { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NIST.CVP.ACVTS.Libraries.Common.Helpers;
using NIST.CVP.ACVTS.Libraries.Generation.Core;
using NIST.CVP.ACVTS.Libraries.Oracle.Abstractions.DispositionTypes;

namespace NIST.CVP.ACVTS.Libraries.Generation.RSA.Sp800_56Br2.DpComponent.TestCaseExpectations{
public class TestCaseExpectationReason : ITestCaseExpectationReason<RsaDpDisposition>
{
private readonly RsaDpDisposition _reason;

public TestCaseExpectationReason(RsaDpDisposition reason)
{
_reason = reason;
}

public string GetName()
{
return EnumHelpers.GetEnumDescriptionFromEnum(_reason);
}

public RsaDpDisposition GetReason()
{
return _reason;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using NIST.CVP.ACVTS.Libraries.Common.ExtensionMethods;
using NIST.CVP.ACVTS.Libraries.Generation.Core;
using NIST.CVP.ACVTS.Libraries.Oracle.Abstractions.DispositionTypes;

namespace NIST.CVP.ACVTS.Libraries.Generation.RSA.Sp800_56Br2.DpComponent.TestCaseExpectations
{
public class TestCaseExpectationProvider : ITestCaseExpectationProvider<RsaDpDisposition>
{
private readonly ConcurrentQueue<TestCaseExpectationReason> _expectationReasons;

public int ExpectationCount { get; set; }
private int NumberOfTestCasesToGenerate { get; set; } = 15;

public TestCaseExpectationProvider(bool isSample = false)
{
List<TestCaseExpectationReason> expectationReasons = new List<TestCaseExpectationReason>();

if (isSample)
{
NumberOfTestCasesToGenerate -= 5;
}

// We always want 4 failing test cases per group, randomized throughout the test case list
expectationReasons.Add(new TestCaseExpectationReason(RsaDpDisposition.CtEqual0));
expectationReasons.Add(new TestCaseExpectationReason(RsaDpDisposition.CtEqual1));
expectationReasons.Add(new TestCaseExpectationReason(RsaDpDisposition.CtEqualNMinusOne));
expectationReasons.Add(new TestCaseExpectationReason(RsaDpDisposition.CtGreaterNMinusOne));

int i = 4;
// Add the remaining passing cases
while (i++ < NumberOfTestCasesToGenerate)
{
expectationReasons.Add(new TestCaseExpectationReason(RsaDpDisposition.None));
}

// Randomize list and stuff it into the Queue for easier iteration/bounds checking
_expectationReasons = new ConcurrentQueue<TestCaseExpectationReason>(expectationReasons.Shuffle());
ExpectationCount = _expectationReasons.Count;
}

// Is random since it's shuffled in the constructor
public ITestCaseExpectationReason<RsaDpDisposition> GetRandomReason()
{
if (_expectationReasons.TryDequeue(out var reason))
{
return reason;
}

throw new IndexOutOfRangeException($"No {nameof(_expectationReasons)} remaining to pull");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Threading.Tasks;
using NIST.CVP.ACVTS.Libraries.Crypto.Common.Asymmetric.RSA.Enums;
using System.Threading.Tasks;
using NIST.CVP.ACVTS.Libraries.Generation.Core;
using NIST.CVP.ACVTS.Libraries.Generation.Core.Async;
using NIST.CVP.ACVTS.Libraries.Oracle.Abstractions;
using NIST.CVP.ACVTS.Libraries.Oracle.Abstractions.ParameterTypes;
using NIST.CVP.ACVTS.Libraries.Oracle.Abstractions.ResultTypes;
using NLog;

namespace NIST.CVP.ACVTS.Libraries.Generation.RSA.Sp800_56Br2.DpComponent
{
public class TestCaseGenerator : ITestCaseGeneratorWithPrep<TestGroup, TestCase>
{
private readonly IOracle _oracle;

public int NumberOfTestCasesToGenerate { get; private set; } = 16;
public int NumberOfTestCasesToGenerate { get; private set; } = 15;

public TestCaseGenerator(IOracle oracle)
{
Expand All @@ -24,43 +23,29 @@ public GenerateResponse PrepareGenerator(TestGroup @group, bool isSample)
{
if (isSample)
{
NumberOfTestCasesToGenerate = 8;
NumberOfTestCasesToGenerate = 10;
}

return new GenerateResponse();
}

public async Task<TestCaseGenerateResponse<TestGroup, TestCase>> GenerateAsync(TestGroup group, bool isSample, int caseNo = 0)
{
var testCase = new TestCase();
var reason = group.TestCaseExpectationProvider.GetRandomReason();

var rsaDpParams = new RsaDecryptionPrimitiveParameters()
{
Modulo = group.Modulo,
Mode = group.KeyMode,
Disposition = reason.GetName()
};

try
{
var dpResult = await _oracle.GetRsaDecryptionPrimitiveSp800B56Br2Async(rsaDpParams);

testCase.CipherText = dpResult.CipherText;
testCase.PlainText = dpResult.PlainText;
testCase.TestPassed = dpResult.TestPassed;

// Set key properties
if (group.KeyMode == PrivateKeyModes.Crt)
{
testCase.Dmp1 = dpResult.Key.PrivKey.DMP1;
testCase.Dmq1 = dpResult.Key.PrivKey.DMQ1;
testCase.Iqmp = dpResult.Key.PrivKey.IQMP;
}
else
{
testCase.Q = dpResult.Key.PrivKey.Q;
testCase.P = dpResult.Key.PrivKey.P;
testCase.D = dpResult.Key.PrivKey.D;
}
SetTestCaseData(testCase, dpResult);
}
catch (Exception ex)
{
Expand All @@ -70,7 +55,22 @@ public GenerateResponse PrepareGenerator(TestGroup @group, bool isSample)

return new TestCaseGenerateResponse<TestGroup, TestCase>(testCase);
}


private static void SetTestCaseData(TestCase testCase, RsaDecryptionPrimitiveResult dpResult)
{
testCase.CipherText = dpResult.CipherText;
testCase.PlainText = dpResult.PlainText;
testCase.TestPassed = dpResult.TestPassed;
testCase.N = dpResult.Key.PubKey.N;
testCase.E = dpResult.Key.PubKey.E;
testCase.Q = dpResult.Key.PrivKey.Q;
testCase.P = dpResult.Key.PrivKey.P;
testCase.Dmp1 = dpResult.Key.PrivKey.DMP1;
testCase.Dmq1 = dpResult.Key.PrivKey.DMQ1;
testCase.Iqmp = dpResult.Key.PrivKey.IQMP;
testCase.D = dpResult.Key.PrivKey.D;
}

private static ILogger ThisLogger => LogManager.GetCurrentClassLogger();
}
}
Loading

0 comments on commit 4b21222

Please sign in to comment.