INNER CODE UNIT · C#
CONTEXT_BUFFER_LENGTH
sdrapkin/SecurityDriven.Inferno · EtM_CBC.cs:21
static readonly int CONTEXT_BUFFER_LENGTH = CONTEXT_TWEAK_LENGTH + AES_IV_LENGTH;
static readonly ThreadLocal<byte[]> _iv = new ThreadLocal<byte[]>(() => new byte[AES_IV_LENGTH]);
static readonly ThreadLocal<byte[]> _contextBuffer = new ThreadLocal<byte[]>(() => new byte[CONTEXT_BUFFER_LENGTH]);
static readonly ThreadLocal<byte[]> _encKey = new ThreadLocal<byte[]>(() => new byte[ENC_KEY_LENGTH]);
static readonly ThreadLocal<byte[]> _macKey = new ThreadLocal<byte[]>(() => new byte[MAC_KEY_LENGTH]);
static readonly ThreadLocal<byte[]> _sessionKey = new ThreadLocal<byte[]>(() => new byte[HMAC_LENGTH]);
public static int CalculateCiphertextLength(ArraySegment<byte> plaintext)
{
int finalBlockLength = plaintext.Count - (plaintext.Count & (-Cipher.AesConstants.AES_BLOCK_SIZE));
int paddingLength = AES_IV_LENGTH - finalBlockLength;
return CONTEXT_BUFFER_LENGTH + plaintext.Count + paddingLength + MAC_LENGTH;
}
static void ValidateAes(Aes aes) // detect & fix any Mode/Padding deviation
{
if (aes.Mode == CipherMode.CBC && aes.Padding == PaddingMode.PKCS7) return;