You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Possible bug around Org.BouncyCastle.Crypto.Fips.FipsAes.Service and Org.BouncyCastle.Crypto.BlockCipherBuilderImpl<Org.BouncyCastle.Crypto.Fips.FipsAes.ParametersWithIV>
#583
I don't have an easy and straightforward way to reproduce so don't file a bug. Though it seems to be something wrong there.
I have a following code for aes encryption/decryption:
public byte[] ProcessBlock(byte[] inp, int inpOff, int inpLen, bool forEncryption, byte[] key, byte[] initVector) {
FipsAes.Key aesKey = new FipsAes.Key(key);
IBlockCipherBuilder<IParameters<Algorithm>> cipherBuilder = createBuilder(forEncryption, aesKey, initVector);
MemoryOutputStream memoryStream = new MemoryOutputStream();
IBlockCipher blockCipher = cipherBuilder.BuildBlockCipher(memoryStream);
if (inpLen % blockCipher.BlockSize != 0) {
throw new ArgumentException("Not multiple of block: " + inpLen);
}
using (Stream stream = blockCipher.Stream) {
stream.Write(inp, inpOff, inpLen);
}
return memoryStream.ToArray();
}
private static IBlockCipherBuilder<IParameters<Algorithm>> createBuilder(bool forEncryption, FipsAes.Key aesKey, byte[] initVector) {
IBlockCipherService provider = CryptoServicesRegistrar.CreateService<IBlockCipherService>(
(ICryptoServiceType<IBlockCipherService>) aesKey);
IBlockCipherBuilder<IParameters<Algorithm>> cipherBuilder;
if (forEncryption) {
cipherBuilder = provider.CreateBlockEncryptorBuilder<FipsAes.ParametersWithIV>(FipsAes.Cbc.WithIV(initVector));
} else {
cipherBuilder = provider.CreateBlockDecryptorBuilder<FipsAes.ParametersWithIV>(FipsAes.Cbc.WithIV(initVector));
}
return cipherBuilder;
}
It all works as expected. Application is heavily doing encryption/decryption (mostly encryption) calls for some data (16 bytes everywhere AFAICT).
But sometimes under heavy conditions (huge CPU/memory usage) it produces different result for the same input data. You might notice that 2 bc fips calls are moved to a separate method createBuilder. If I disable optimization by using
[MethodImplAttribute(MethodImplOptions.NoOptimization)]
for that 1 method, the issue is not reproducible anymore.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I don't have an easy and straightforward way to reproduce so don't file a bug. Though it seems to be something wrong there.
I have a following code for aes encryption/decryption:
It all works as expected. Application is heavily doing encryption/decryption (mostly encryption) calls for some data (16 bytes everywhere AFAICT).
But sometimes under heavy conditions (huge CPU/memory usage) it produces different result for the same input data. You might notice that 2 bc fips calls are moved to a separate method createBuilder. If I disable optimization by using
[MethodImplAttribute(MethodImplOptions.NoOptimization)]
for that 1 method, the issue is not reproducible anymore.
Does it sound familiar to anyone?
Beta Was this translation helpful? Give feedback.
All reactions