Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 1017 Bytes

GUID-6C0C6211-EA7D-4B96-9954-04C2E2638D4E.md

File metadata and controls

56 lines (35 loc) · 1017 Bytes

CRYPT_RNG_Get Function

Parent topic:MPLAB® Harmony Crypto Library

C

int CRYPT_RNG_Get(
CRYPT_RNG_CTX* rng, 
unsigned char* b
);

Description

This function gets one random number from the random number generator.

Preconditions

RNG context was initialized using the CRYPT_RNG_Initialize function.

Parameters

Parameters Description
rng Pointer to context which saves state between calls.
b Pointer to 8-bit location to store the result.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

  • Less than 0 - An error occurred.

  • 0 or greater - Success.

Remarks

None.

Example

#define RANDOM_BYTE_SZ 32

int           ret;
CRYPT_RNG_CTX mcRng;
byte          out[RANDOM_BYTE_SZ];

ret = CRYPT_RNG_Initialize(&mcRng);
ret = CRYPT_RNG_Get(&mcRng, &out[0]);
ret = CRYPT_RNG_BlockGenerate(&mcRng, out, RANDOM_BYTE_SZ);
ret = CRYPT_RNG_Deinitialize(&mcRng);