Reference Guide

Chapter 3: Resource Management 21
RSA BSAFE Crypto-C Micro Edition 3.x to 4.1.4 Migration Guide
/* Causes the FIPS 140-2 libraries to be loaded from the
* R_SHLIB_LD_LIBRARY_PATH environment variable
*/
ret = R_LIB_CTX_new(list,
R_RES_FLAG_DEFAULT, &lib_ctx);
if (R_ERROR_NONE != ret)
goto end;
/* Cryptographic operations */
end:
R_LIB_CTX_free(lib_ctx);
return 0;
}
FIPS 140-2 Application - Crypto-C ME 4.1.4
/* Loaded from configuration in real application */
const char *lib_path = "path_to_fips_libs";
int main(int argc, char **argv)
{
int ret;
R_LIB_CTX *lib_ctx = NULL;
const R_RES_LIST *list =
R_PROV_SOFTWARE_get_default_resource_list();
R_PROV *fips = NULL;
ret = R_STATE_init_defaults();
if (R_ERROR_NONE != ret)
return 1;
ret = R_LIB_CTX_new_ef(list, NULL, &lib_ctx);
if (R_ERROR_NONE != ret)
goto end;
ret = R_LIB_CTX_set_mode(lib_ctx, &R_MODE_FILTER_FIPS140);
if (R_ERROR_NONE != ret)
goto end;
ret = R_PROV_FIPS140_new(NULL, NULL, &fips);
if (R_ERROR_NONE != ret)
goto end;
ret = R_PROV_FIPS140_set_path(fips, lib_path);
if (R_ERROR_NONE != ret)
goto end;
ret = R_PROV_FIPS140_load(fips);
if (R_ERROR_NONE != ret)
{
int reason;
const char *desc;
R_PROV_FIPS140_get_reason(fips, &reason);
desc = R_PROV_FIPS140_reason_string(reason);
printf("Failed to load FIPS provider %s\n", desc);
goto end;
}