A SERVICE OF

logo

The Algorithm Chooser
10 RSA BSAFE Crypto-C Library Reference Manual
The Algorithm Chooser
The algorithm chooser lists all the algorithm methods that Crypto-C will use in the
application. In this way, you only link in the code you need, and thereby reduce the
executable size.
The BDEMO Algorithm Chooser
The BDEMO demonstration application supplied with Crypto-C defines an algorithm
chooser called
DEMO_ALGORITHM_CHOOSER. To use the BDEMO algorithm chooser,
compile and link the module that defines
DEMO_ALGORITHM_CHOOSER (as it is done for
BDEMO) and specify
DEMO_ALGORITHM_CHOOSER as the
algorithmChooser
argument.
Defining an Algorithm Chooser
The main reason for an application to define its own algorithm chooser is to make the
executable image smaller. The linker links in the object code for all algorithm methods
listed in the algorithm chooser. To illustrate, an application that only uses MD5 and
DES-CBC may define an algorithm chooser with only the MD5 and DES-CBC
methods. In this way, the linker will only link in the object code related to MD5 and
DES-CBC.
An algorithm chooser is an array of pointers to
B_ALGORITHM_METHOD values. The last
element of the array must be
(B_ALGORITHM_METHOD *)NULL_PTR. The following is an
example that defines an algorithm chooser called
MD5_DES_CBC_CHOOSER for the MD5
and DES-CBC algorithm methods needed when using the
AI_MD5WithDES_CBCPad
algorithm info type:
For additional examples of algorithm choosers, see “Algorithm Choosers” on
page 118 of the
User’s Manual
.
Notice that encryption/decryption algorithm methods (AMs) such as DES-CBC, have
separate entries for encryption and decryption. This separation of methods enables a
B_ALGORITHM_METHOD *MD5_DES_CBC_CHOOSER[] = {
&AM_MD5,
&AM_DES_CBC_ENCRYPT,
&AM_DES_CBC_DECRYPT,
(B_ALGORITHM_METHOD *)NULL_PTR
};