Chapter 4 Using Crypto-C 125
System Considerations In Crypto-C
Crypto-C returns a pointer to the location where we can find the
info
, not the
info
itself. When we destroy the object, that
info
will disappear. If we want to save it, we
have to copy it over into our own buffer, the memory for which we must allocate.
Remember to use
T_free to free any memory you allocated with T_malloc when you
are done with it.
Now, if we need to let anyone know what algorithm we used to encrypt, we can send
the BER-encoded algorithm identifier.
For additional examples that use BER, see “Distributing an RSA Public Key” on
page 223 and “Distributing Diffie-Hellman Parameters” on page 253.
Note: BER-encoding does not put data into an ASCII string; it is simply a standard
way of describing certain universal objects. To convert binary data to and
from an ASCII string (to e-mail it, for example) see “Converting Data Between
Binary and ASCII” on page 172.
Note: Conversion into BER or DER is known as BER-encoding or DER-encoding;
the conversion between binary and ASCII is known as encoding and
decoding. This may get confusing, but the word encoding, without a BER in
front of it, generally means binary to ASCII. If the encoding is BER- or DER-
encoding, the BER or DER should be explicitly stated.
ITEM *getInfoBER;
ITEM infoBER;
infoBER.data = NULL_PTR;
if ((status = B_GetAlgorithmInfo
((POINTER *)&getInfoBER, encryptionObject,
AI_RC4_BER)) != 0)
break;
infoBER.len = getInfoBER–>len;
infoBER.data = T_malloc (infoBER.len);
if ((status = (infoBER.data == NULL_PTR)) != 0)
break;
T_memcpy (infoBER.data, getInfoBER->data, infoBER.len);