diff options
author | Pauli <pauli@openssl.org> | 2022-11-14 13:13:44 +1100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-11-15 12:10:39 +0100 |
commit | fe84acc22757e77d48fb6ccc31abe4c72264c877 (patch) | |
tree | a805576fc4054fdcafbb8ce3019dec2bb0fd18c1 | |
parent | e5202fbd461cb6c067874987998e91c6093e5267 (diff) |
test: add two comparision options to fips version test utility code
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19666)
-rw-r--r-- | test/testutil.h | 2 | ||||
-rw-r--r-- | test/testutil/provider.c | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/test/testutil.h b/test/testutil.h index fde9ff046b..3a3aafc655 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -257,7 +257,9 @@ void cleanup_tests(void); int fips_provider_version_eq(OSSL_LIB_CTX *libctx, int major, int minor, int patch); int fips_provider_version_ne(OSSL_LIB_CTX *libctx, int major, int minor, int patch); int fips_provider_version_le(OSSL_LIB_CTX *libctx, int major, int minor, int patch); +int fips_provider_version_lt(OSSL_LIB_CTX *libctx, int major, int minor, int patch); int fips_provider_version_gt(OSSL_LIB_CTX *libctx, int major, int minor, int patch); +int fips_provider_version_ge(OSSL_LIB_CTX *libctx, int major, int minor, int patch); /* * This function matches fips provider version with (potentially multiple) diff --git a/test/testutil/provider.c b/test/testutil/provider.c index c8b5dfc061..199e4f03af 100644 --- a/test/testutil/provider.c +++ b/test/testutil/provider.c @@ -129,6 +129,19 @@ int fips_provider_version_le(OSSL_LIB_CTX *libctx, int major, int minor, int pat || (prov.minor == minor && prov.patch <= patch))); } +int fips_provider_version_lt(OSSL_LIB_CTX *libctx, int major, int minor, int patch) +{ + FIPS_VERSION prov; + int res; + + if ((res = fips_provider_version(libctx, &prov)) <= 0) + return res == 0; + return prov.major < major + || (prov.major == major + && (prov.minor < minor + || (prov.minor == minor && prov.patch < patch))); +} + int fips_provider_version_gt(OSSL_LIB_CTX *libctx, int major, int minor, int patch) { FIPS_VERSION prov; @@ -142,12 +155,25 @@ int fips_provider_version_gt(OSSL_LIB_CTX *libctx, int major, int minor, int pat || (prov.minor == minor && prov.patch > patch))); } +int fips_provider_version_ge(OSSL_LIB_CTX *libctx, int major, int minor, int patch) +{ + FIPS_VERSION prov; + int res; + + if ((res = fips_provider_version(libctx, &prov)) <= 0) + return res == 0; + return prov.major > major + || (prov.major == major + && (prov.minor > minor + || (prov.minor == minor && prov.patch >= patch))); +} + int fips_provider_version_match(OSSL_LIB_CTX *libctx, const char *versions) { const char *p; int major, minor, patch, r; enum { - MODE_EQ, MODE_NE, MODE_LE, MODE_GT + MODE_EQ, MODE_NE, MODE_LE, MODE_LT, MODE_GT, MODE_GE } mode; while (*versions != '\0') { @@ -166,6 +192,12 @@ int fips_provider_version_match(OSSL_LIB_CTX *libctx, const char *versions) } else if (*p == '<' && p[1] == '=') { mode = MODE_LE; p += 2; + } else if (*p == '>' && p[1] == '=') { + mode = MODE_GE; + p += 2; + } else if (*p == '<') { + mode = MODE_LT; + p++; } else if (*p == '>') { mode = MODE_GT; p++; @@ -189,9 +221,15 @@ int fips_provider_version_match(OSSL_LIB_CTX *libctx, const char *versions) case MODE_LE: r = fips_provider_version_le(libctx, major, minor, patch); break; + case MODE_LT: + r = fips_provider_version_lt(libctx, major, minor, patch); + break; case MODE_GT: r = fips_provider_version_gt(libctx, major, minor, patch); break; + case MODE_GE: + r = fips_provider_version_ge(libctx, major, minor, patch); + break; } if (r < 0) { TEST_info("Error matching FIPS version: internal error\n"); |