diff options
author | Pauli <pauli@openssl.org> | 2022-11-14 13:13:44 +1100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-11-15 12:11:29 +0100 |
commit | 6953cda1edfd80c8d49269ce13314fbaff0d4532 (patch) | |
tree | bfc01ae1c6e7ba3a79882a722825eab7c9138523 /test | |
parent | 08715aaa249fd9b3e6cf848ae452b6bce77dadcb (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)
(cherry picked from commit fe84acc22757e77d48fb6ccc31abe4c72264c877)
Diffstat (limited to 'test')
-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 d9c9826982..443d01d7fb 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -256,7 +256,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 69b81363b6..0f46077a32 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"); |