Reference Guide

Chapter 3: Resource Management 23
RSA BSAFE Crypto-C Micro Edition 3.x to 4.1.4 Migration Guide
The next step is to load the PKCS #11 driver shared library so that the PKCS #11
provider can access its functionality and configure the hardware devices. In previous
releases of Crypto-C ME, this was done using an environment variable that was then
parsed by the Crypto-C ME library.
In Crypto-C ME 4.1.4, use of the environment variable is deprecated and it is strongly
recommended to store the PKCS #11 driver location and any other information in an
external source, such as a configuration file or registry variable, and pass the
information into Crypto-C ME using the
R_PROV_PKCS11_driver_path() and
R_PROV_PKCS11_driver_name() functions.
For more information, see Environment Variable.
Examples of setting up and loading a PKCS #11 library are shown below. Although
the Crypto-C ME 4.1.4 method has more steps, it is more flexible and any
Crypto-C ME 3.x setups (which depend on the environment variable) remain
unaffected.
PKCS #11 - Crypto-C ME 3.x
int main(int argc, char **argv)
{
int ret;
R_LIB_CTX *lib_ctx = NULL;
R_CR_CTX cr_ctx;
/* Default resource list contains hardware operations */
R_RES_LIST *list = PRODUCT_DEFAULT_RESOURCE_LIST();
ret = R_LIB_CTX_new(list, R_RES_FLAG_DEFAULT, &lib_ctx);
if (R_ERROR_NONE != ret)
goto end;
/* Load the PKCS #11 driver from the environment variable
* and scan for devices
*/
ret = R_CR_CTX_new(lib_ctx, R_RES_FLAG_DEF, &cr_ctx);
if (R_ERROR_NONE != ret)
goto end;
/* Perform cryptographic operations */
end:
R_LIB_CTX_free(lib_ctx);
return 0;
}