To integrate Security Builder Engine for OpenSSL into your own OpenSSL based applications, you need to include code to load the engine.
A convenience function is provided to load the engine. You must also ensure that the operating system will be able to find the dynamically-loaded Security Builder Engine for OpenSSL library at runtime.
The convenience function ENGINE_load_sb() is defined in the header file sbengine.h. Its use is optional; you can also directly call OpenSSL APIs to load the engine.
You must call the OpenSSL ENGINE_cleanup() function before program exit, to avoid memory leaks.
#include <openssl/engine.h>
#include "sbengine.h"
/* sbengine variables */
ENGINE * engine = NULL;
/* Register the error strings for all OpenSSL functions */
ERR_load_crypto_strings();
/* Load all the OpenSSL bundled ENGINEs into memory and
make them visible */
ENGINE_load_builtin_engines();
/* Load the Security Builder ENGINE (for OpenSSL) into memory
and make it visible.
The ENGINE_METHOD_ALL parameter will configure OpenSSL to make
the Security Builder ENGINE default for all algorithms
supported by the Security Builder ENGINE.
If ENGINE_METHOD_NONE was used instead then the Security
Builder ENGINE would not be configured as default.
See documentation for ENGINE_load_sb(). */
ENGINE_load_sb( ENGINE_METHOD_ALL );
/* Obtain an ENGINE instance of the Security Builder ENGINE */
engine = ENGINE_by_id(SBENGINE_ID);
if (!engine){
fprintf(stderr," %s - find engine by id '%s': %s\n", __FILE__,
SBENGINE_ID, !engine ?"failed" : "success");
exit(1);
}
/* end sbengine code */
ENGINE_cleanup();