Skip to content

Commit

Permalink
Expand openssl sign verify parsing (microsoft#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangpanMS authored Dec 21, 2023
1 parent 3c5acb4 commit 93701ee
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pipelines/azure-pipelines-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources:
options: --entrypoint=""

variables:
VcVersion : 1.13.11
VcVersion : 1.13.12
ROOT: $(Build.SourcesDirectory)
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
ENABLE_PRS_DELAYSIGN: 1
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pool:
vmImage: windows-latest

variables:
VcVersion : 1.13.11
VcVersion : 1.13.12
ROOT: $(Build.SourcesDirectory)
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
ENABLE_PRS_DELAYSIGN: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Forked child 0
Forked child 1
Forked child 2
Forked child 3
Forked child 4
Forked child 5
Forked child 6
Forked child 7
Forked child 8
Forked child 9
Forked child 10
Forked child 11
Forked child 12
Forked child 13
Forked child 14
Forked child 15
Got: +F6:0:253:Ed25519:16489.200000:5105.600000 from 0
Got: +F6:0:253:Ed25519:16327.400000:4928.400000 from 1
Got: +F6:0:253:Ed25519:16509.400000:4777.200000 from 2
Got: +F6:0:253:Ed25519:16471.257485:4928.600000 from 3
Got: +F6:0:253:Ed25519:16538.600000:4936.600000 from 4
Got: +F6:0:253:Ed25519:16152.800000:4873.000000 from 5
Got: +F6:0:253:Ed25519:16498.400000:4752.400000 from 6
Got: +F6:0:253:Ed25519:15695.800000:4706.000000 from 7
Got: +F6:0:253:Ed25519:16496.000000:4926.746507 from 8
Got: +F6:0:253:Ed25519:15967.600000:4884.231537 from 9
Got: +F6:0:253:Ed25519:16496.200000:4911.800000 from 10
Got: +F6:0:253:Ed25519:16526.400000:4882.600000 from 11
Got: +F6:0:253:Ed25519:16437.325349:4779.800000 from 12
Got: +F6:0:253:Ed25519:16442.600000:4889.800000 from 13
Got: +F6:0:253:Ed25519:16186.600000:4914.600000 from 14
Got: +F6:0:253:Ed25519:15880.600000:4805.800000 from 15
version: 3.0.0-beta3-dev
built on: built on: Thu Aug 5 18:45:56 2021 UTC
options:bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
CPUINFO: OPENSSL_ia32cap=0xfffa32235f8bffff:0x415f46f1bf2fbb
sign verify sign/s verify/s
253 bits EdDSA (Ed25519) 0.0000s 0.0000s 261116.2 78003.2
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ sha256 98952.23k 300483.21k 717624.35k 1098886.72k 1296898.18k
IEnumerable<Metric> metrics = parser.Parse();

Assert.IsNotNull(metrics);
Assert.IsTrue(metrics.Count() == 6);
Assert.AreEqual(6, metrics.Count());
Assert.IsTrue(metrics.All(m => m.Unit == MetricUnit.KilobytesPerSecond));

OpenSslMetricsParserTests.AssertMetricsMatch("aes-256-cbc", metrics, new Dictionary<string, double>
OpenSslMetricsParserTests.AssertMetricsMatch("AES-256-CBC", metrics, new Dictionary<string, double>
{
{ "aes-256-cbc 16-byte", 1109022.36 },
{ "aes-256-cbc 64-byte", 1209391.13 },
{ "aes-256-cbc 256-byte", 1232451.87 },
{ "aes-256-cbc 1024-byte", 1237247.28 },
{ "aes-256-cbc 8192-byte", 1239375.05 },
{ "aes-256-cbc 16384-byte", 1239090.79 },
{ "AES-256-CBC 16-byte", 1109022.36 },
{ "AES-256-CBC 64-byte", 1209391.13 },
{ "AES-256-CBC 256-byte", 1232451.87 },
{ "AES-256-CBC 1024-byte", 1237247.28 },
{ "AES-256-CBC 8192-byte", 1239375.05 },
{ "AES-256-CBC 16384-byte", 1239090.79 },
});
}

Expand Down Expand Up @@ -194,6 +194,34 @@ rsa 2048 bits 0.000820s 0.000024s 1219.7 41003.9
});
}

[Test]
public void OpenSslParserParsesResultsCorrectly_ed25519_Scenario()
{
/* In this scenario, we are evaluating a single cipher as well as all byte buffer sizes.
Example:
sign verify sign/s verify/s
253 bits EdDSA (Ed25519) 0.0000s 0.0000s 261116.2 78003.2
*/

OpenSslMetricsParser parser = new OpenSslMetricsParser(
File.ReadAllText(Path.Combine(OpenSslMetricsParserTests.examplesDir, "OpenSSL-speed-multi-ed25519.txt")),
"speed -multi 16 -seconds 5 ed25519");

IEnumerable<Metric> metrics = parser.Parse();

Assert.IsNotNull(metrics);
Assert.AreEqual(4, metrics.Count());

OpenSslMetricsParserTests.AssertMetricsMatch("253 bits EdDSA (Ed25519)", metrics, new Dictionary<string, double>
{
{ "253 bits EdDSA (Ed25519) sign", 0 },
{ "253 bits EdDSA (Ed25519) verify", 0 },
{ "253 bits EdDSA (Ed25519) sign/s", 261116.2 },
{ "253 bits EdDSA (Ed25519) verify/s", 78003.2 }
});
}

[Test]
public void OpenSslParserParsesResultsCorrectly_AllCiphers_Scenario()
{
Expand All @@ -213,7 +241,7 @@ sha256 98952.23k 300483.21k 717624.35k 1098886.72k 1296898.18k
IEnumerable<Metric> metrics = parser.Parse();

Assert.IsNotNull(metrics);
Assert.IsTrue(metrics.Count() == 112);
Assert.AreEqual(224, metrics.Count());
// Assert.IsTrue(metrics.All(m => m.Unit == MetricUnit.KilobytesPerSecond)); --> changed with inclusion of RSA coverage

OpenSslMetricsParserTests.AssertMetricsMatch("md5", metrics, new Dictionary<string, double>
Expand Down Expand Up @@ -432,7 +460,7 @@ sha256 1316783.17k
IEnumerable<Metric> metrics = parser.Parse();

Assert.IsNotNull(metrics);
Assert.IsTrue(metrics.Count() == 42);
Assert.AreEqual(154, metrics.Count());
// Assert.IsTrue(metrics.All(m => m.Unit == MetricUnit.KilobytesPerSecond)); --> changed with inclusion of RSA coverage

OpenSslMetricsParserTests.AssertMetricsMatch("md5", metrics, new Dictionary<string, double>
Expand Down Expand Up @@ -526,7 +554,7 @@ type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 1
IEnumerable<Metric> metrics = parser.Parse();

Assert.IsNotNull(metrics);
Assert.IsTrue(metrics.Count() == 94);
Assert.AreEqual(206, metrics.Count());
// Assert.IsTrue(metrics.All(m => m.Unit == MetricUnit.KilobytesPerSecond)); --> changed with inclusion of RSA coverage

OpenSslMetricsParserTests.AssertMetricsMatch("md5", metrics, new Dictionary<string, double>
Expand Down Expand Up @@ -650,6 +678,22 @@ type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 1
{ "rand 1024-byte", 1062619.07 },
{ "rand 8192-byte", 4221050.33 }
});

OpenSslMetricsParserTests.AssertMetricsMatch("rsa 512", metrics, new Dictionary<string, double>
{
{ "rsa 512 bits sign", 0.000038 },
{ "rsa 512 bits verify", 0.000002 },
{ "rsa 512 bits sign/s", 26538.8 },
{ "rsa 512 bits verify/s", 432400.4 }
});

OpenSslMetricsParserTests.AssertMetricsMatch("256 bits SM2 (CurveSM2)", metrics, new Dictionary<string, double>
{
{ "256 bits SM2 (CurveSM2) sign", 0.0003 },
{ "256 bits SM2 (CurveSM2) verify", 0.0003 },
{ "256 bits SM2 (CurveSM2) sign/s", 2862.3 },
{ "256 bits SM2 (CurveSM2) verify/s", 3079.5 }
});
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override IList<Metric> Parse()
this.CipherResults = cipherResults;
}

if (this.TryParseRSAPerformanceResults(out DataTable rsaResults))
if (this.TryParseSignVerifyPerformanceResults(out DataTable rsaResults))
{
rsaResultsValid = true;
this.RSAResults = rsaResults;
Expand All @@ -135,7 +135,7 @@ public override IList<Metric> Parse()
foreach (DataRow row in this.CipherResults.Rows)
{
// Ex: aes-256-cbc (8192 bytes)
string metricName = $"{row[OpenSslMetricsParser.ColumnCipher]} {row[OpenSslMetricsParser.ColumnBytes]}-byte".ToLowerInvariant();
string metricName = $"{row[OpenSslMetricsParser.ColumnCipher]} {row[OpenSslMetricsParser.ColumnBytes]}-byte";
double metricValue = (double)row[OpenSslMetricsParser.ColumnKilobytesPerSec];

// There is an anomaly that sometimes happens where the result is a negative number. It indicates
Expand All @@ -156,14 +156,14 @@ public override IList<Metric> Parse()
{
foreach (DataRow row in this.RSAResults.Rows)
{
string metricName = $"{row[OpenSslMetricsParser.ColumnCipher]} {row[OpenSslMetricsParser.ColumnUnit]}".ToLowerInvariant();
string metricName = $"{row[OpenSslMetricsParser.ColumnCipher]} {row[OpenSslMetricsParser.ColumnUnit]}";
double metricValue = (double)row[OpenSslMetricsParser.ColumnValue];

if (metricValue >= 0)
{
if (metricName.Contains("/"))
{
metrics.Add(new Metric(metricName, metricValue, $"row[OpenSslMetricsParser.ColumnUnit]", MetricRelativity.HigherIsBetter));
metrics.Add(new Metric(metricName, metricValue, $"{row[OpenSslMetricsParser.ColumnUnit]}", MetricRelativity.HigherIsBetter));
}
else
{
Expand Down Expand Up @@ -274,7 +274,7 @@ private bool TryParseCipherPerformanceResults(IEnumerable<int> cipherBytes, out
return parsedSuccessfully;
}

private bool TryParseRSAPerformanceResults(out DataTable results)
private bool TryParseSignVerifyPerformanceResults(out DataTable results)
{
results = null;
bool parsedSuccessfully = false;
Expand All @@ -290,7 +290,7 @@ private bool TryParseRSAPerformanceResults(out DataTable results)
// Example:
// sign verify sign/s verify/s
// rsa 2048 bits 0.000820s 0.000024s 1219.7 41003.9
MatchCollection rsaPerformanceResults = Regex.Matches(this.RawText, $@"(rsa\s*[0-9\.]+\s*bits)(\s*[0-9\.]+s)(\s*[0-9\.]+s)(\s*[0-9\.]+)(\s*[0-9\.]+)", RegexOptions.IgnoreCase);
MatchCollection rsaPerformanceResults = Regex.Matches(this.RawText, $@"((?:\w *\(*)+(?:bits|\)))(\s*[0-9\.]+s)(\s*[0-9\.]+s)(\s*[0-9\.]+)(\s*[0-9\.]+)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
if (rsaPerformanceResults?.Any() == true)
{
// return datatable with rsa name, column, value per row
Expand Down

0 comments on commit 93701ee

Please sign in to comment.