System Considerations In Crypto-C

information it is looking for. This information, though, belongs to Crypto-C; subsequent Crypto-C calls can alter or erase it. If an application needs to save the information, it should copy it into its own buffer or allocated space. See “Distributing Diffie-Hellman Parameters” on page 253 for an example.

Note: Crypto-C will sometimes call for an unsigned int argument and other times an unsigned int *. For unsigned int, Crypto-C is expecting a number; for unsigned int *, Crypto-C will supply the number, so you just supply the address of an int variable.

Memory-Management Routines

Crypto-C uses the following memory-management routines:

T_malloc

T_realloc

T_free

T_memset

T_memcpy

T_memmove

T_memcmp

Sample implementations of these routines reside in the memory management file, tstdlib.c, supplied with Crypto-C. See the final section of Chapter 4 in the Reference Manual for descriptions and prototypes of these routines. You can also write your own versions of these routines to satisfy the needs of your operating system or application. It is a good idea to examine tstdlib.c before writing your own code.

Supplying memory management routines with Crypto-C provides several advantages:

Reduced dependency on standard C libraries

Increased control over memory allocation

Increased ability to handle binary data

Memory-Management Routines and Standard C Libraries

The memory-management routines in tstdlib.c organize the arguments to the standard call to best suit Crypto-C’s purposes. They do type checking and verify that the arguments follow the Crypto-C conventions. This helps you to keep your code portable, because any call to these routines will behave uniformly, regardless of platform. This uniform behavior best suits the needs of Crypto-C.

1 2 2

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 144
Image 144
RSA Security 5.2.2 manual Memory-Management Routines and Standard C Libraries