Reference Guide

Chapter 1: Library and Header File Changes 9
RSA BSAFE Crypto-C Micro Edition 3.x to 4.1.4 Migration Guide
Library Initialization
Crypto-C ME 4.0 introduced explicit library initialization and cleanup.
A new function,
R_STATE_init(), configures the low-level memory allocator that
is required for other interfaces to work correctly.
R_STATE_cleanup() releases any
internal state after the application is finished with the library. Every call to
R_STATE_init() requires a corresponding call to R_STATE_cleanup().
The convenience function,
R_STATE_init_defaults(), is also available to
perform the initialization with the default memory allocator for the current platform.
When updating an application for Crypto-C ME 4.1.4, a call to
R_STATE_init_defaults() should be added prior to the library use, and
R_STATE_cleanup() added after all calls are completed.
Note:
Crypto-C ME 4.1.4 also provides R_STATE_init_defaults_mt()
for multithreaded applications. For more information about multithreading
support, see
Multithreading Support
.
The following table code examples show library initialization for Crypto-C ME 3.x and
Crypto-C ME 4.1.4.
Library Initialization - Crypto-C ME 3.x
int main(int argc, char **argv)
{
int ret = R_LIB_CTX_new(…);
/* Perform cryptographic operations */
R_LIB_CTX_free(lib_ctx);
return 0;
}
Library Initialization - Crypto-C ME 4.1.4
int main(int argc, char **argv)
{
int ret;
ret = R_STATE_init_defaults();
if (R_ERROR_NONE != ret)
return 1;
ret = R_LIB_CTX_new_ef(…);
/* Perform cryptographic operations */
R_LIB_CTX_free(lib_ctx);
R_STATE_cleanup();
return 0;
}
For a sample program that demonstrates implementing and using a custom memory
allocator, see Sample Programs > Custom Memory Allocator in the RSA BSAFE
Crypto-C Micro Edition Developers Guide.