Reference Guide
42 Chapter 5: Cryptographic API Changes
RSA BSAFE Crypto-C Micro Edition 3.x to 4.1.4 Migration Guide
Pseudo-random Number Generation
Cryptographic objects, R_CR, implementing a pseudo-random number generator
(PRNG) now require initialization, the same as for other cryptographic objects. This
change was introduced to allow more advanced configuration of cryptographic
objects, such as requesting that an implementation come from a specific provider.
For compatibility, initialization for most usages of PRNG cryptographic objects
occurs automatically. However, RSA recommends an explicit call to
R_CR_random_init() be added wherever these objects are created.
The following code examples show a cryptographic object implementing a PRNG for
Crypto-C ME 3.x and Crypto-C ME 4.1.4.
Implementing a PRNG - Crypto-C ME 3.x
int function(R_CR_CTX *ctx)
{
int ret;
R_CR *rng = NULL;
ret = R_CR_new(crypto_ctx, R_CR_TYPE_RANDOM,
R_CR_ID_RANDOM_DEFAULT, 0, &rng);
if (R_ERROR_NONE != ret)
goto end;
ret = R_CR_random_seed(rng, seed_data, seed_len);
if (R_ERROR_NONE != ret)
goto end;
ret = R_CR_random_bytes(rng, sizeof(buf), buf, &len);
if (R_ERROR_NONE != ret)
goto end;
/* Use the random data */
end:
R_CR_free(rng);
return ret;
}