I’m trying to perform CTR DRBG and here is my code.
mbedtls_ctr_drbg_context ctr_ctx; unsigned char entropy[512]; memset( entropy, 0x00, 512 ); strncpy(entropy, entropyInput, entropyLength); strncpy(entropy + entropyLength, entropyInputPR1, entropyLength); strncpy(entropy + (2*entropyLength), entropyInputPR2, entropyLength); mbedtls_ctr_drbg_init(&ctr_ctx); mbedtls_ctr_drbg_seed( &ctr_ctx, mbedtls_entropy_func, entropy, pString, pStringLength ); if ( predResist == 1 ) { mbedtls_ctr_drbg_set_prediction_resistance( &ctr_ctx, MBEDTLS_CTR_DRBG_PR_ON ); } mbedtls_ctr_drbg_random_with_add( &ctr_ctx, result, sizeof(result), addInput1, addInputLength ); if ( predResist == 0 ) { mbedtls_ctr_drbg_reseed( &ctr_ctx, NULL, 0 ); } mbedtls_ctr_drbg_random_with_add( &ctr_ctx, result, sizeof(result), addInput2, addInputLength );
My input is the request file from NIST (shown below):
> [AES-128 no df]
> [PredictionResistance = True]
> [EntropyInputLen = 256]
> [NonceLen = 0]
> [PersonalizationStringLen = 0]
> [AdditionalInputLen = 0]
> [ReturnedBitsLen = 2048]
>
> COUNT = 0
> EntropyInput = 64e1936f7fd634031b5d8944e28be0cc14b32f1e741d17a012ac84cd7890cc1e
> Nonce =
> PersonalizationString =
> AdditionalInput =
> EntropyInputPR = ecd7aaa7a1183e70fb19df20f70f56ce6870c56fe4af7f0b090125db7a04d68d
> AdditionalInput =
> EntropyInputPR = 636d9a4cff514bdfb557a44d3ec5fa3c16878e3f52c1a949924063637eacfc90
Few things I wanted to check:
- There are 3 entropy fields, so I’ve concatenated them. EntropyInput+EntropyInputPR+EntropyInputPR. Is that order correct?
- There is also a “nonce” field and I don’t see an example of how this can be used in the test suites. In my current example it is zero length but there are instances where this field has a value. Does this need to be concatenated with any of the other strings?
- Are any DRBG calls missing in my code or is something not in right order? Because with the current code, “result” just has the value 0.
THANKS in advance!