RSA Security 5.2.2 manual System Considerations In Crypto-C

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 147
Image 147

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.

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);

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.

C h a p t e r 4 U s i n g C r y p t o - C

1 2 5

Page 147
Image 147
RSA Security 5.2.2 manual System Considerations In Crypto-C