Skip to main content

encoder-reseed


//--------------------------------------
// Get the Encoder DRBG reseed counter
// This is the MTE's current seed count
ulong currentSeed = mteEncoder.GetReseedCounter();

//------------------------------------------
// Get the Encoder DRBG max reseed interval
ulong maxSeed = mteBase.GetDrbgsReseedInterval(mteEncoder.GetDrbg());

//---------------------------------------------------------
// If the current seed is greater than 90% of the max seed
// Uninstantiate the MTE then Reinitialize the MTE
// with a new entropy and nonce to reseed
if (currentSeed > (maxSeed * 0.9)){
//---------------------------
// Uninstantiate the Encoder
MteStatus encoderStatus = mteEncoder.Uninstantiate();
if(encoderStatus != MteStatus.mte_status_success) {
//-------------------------------------------------
// MTE was not uninstantiated as desired so handle
// failure appropriately, below is only an example
throw new Exception("Failed to uninstantiate Encoder. Status: "
+ mteEncoder.GetStatusName(encoderStatus)+ " / "
+ mteEncoder.GetStatusDescription(encoderStatus));
}
//---------------------------------------
// Re-handshake to get new entropy value
// AND new nonce value
// Full code sample not here, to see example
// please see Diffie-Hellman Key Exchange
HandshakeModel handshake = MethodToHandshake();

//-------------------------------
// Set Encoder entropy and nonce
mteEncoder.SetEntropy(Encoding.UTF8.GetBytes(handshake.NewEncoderEntropy));
mteEncoder.SetNonce(handshake.NewNonce);
//------------------------
// Initialize MTE Encoder
MteStatus encoderStatus = mteEncoder.Instantiate(personalizationString);
if(encoderStatus !=MteStatus.mte_status_success) {
//-----------------------------------------------------
// MTE cannot continue so handle failure appropriately
// Below is just an example
throw new ApplicationException($"Failed to initialize the MTE Encoder engine." +
$"Status: {mteEncoder.GetStatusName(encoderStatus)} / " +
$"{mteEncoder.GetStatusDescription(encoderStatus)}");
}
}