// Expect NoSuchPaddingException /// <exception cref="System.Exception"/> public virtual void TestUpdateArguments() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); cipher.Init(OpensslCipher.EncryptMode, key, iv); // Require direct buffers ByteBuffer input = ByteBuffer.Allocate(1024); ByteBuffer output = ByteBuffer.Allocate(1024); try { cipher.Update(input, output); NUnit.Framework.Assert.Fail("Input and output buffer should be direct buffer."); } catch (ArgumentException e) { GenericTestUtils.AssertExceptionContains("Direct buffers are required", e); } // Output buffer length should be sufficient to store output data input = ByteBuffer.AllocateDirect(1024); output = ByteBuffer.AllocateDirect(1000); try { cipher.Update(input, output); NUnit.Framework.Assert.Fail("Output buffer length should be sufficient " + "to store output data" ); } catch (ShortBufferException e) { GenericTestUtils.AssertExceptionContains("Output buffer is not sufficient", e); } }
public OpensslAesCtrCryptoCodec() { string loadingFailureReason = OpensslCipher.GetLoadingFailureReason(); if (loadingFailureReason != null) { throw new RuntimeException(loadingFailureReason); } }
/// <exception cref="System.Exception"/> public virtual void TestDoFinalArguments() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); cipher.Init(OpensslCipher.EncryptMode, key, iv); // Require direct buffer ByteBuffer output = ByteBuffer.Allocate(1024); try { cipher.DoFinal(output); NUnit.Framework.Assert.Fail("Output buffer should be direct buffer."); } catch (ArgumentException e) { GenericTestUtils.AssertExceptionContains("Direct buffer is required", e); } }
/// <exception cref="System.Exception"/> public virtual void TestOpensslAesCtrCryptoCodec() { GenericTestUtils.AssumeInNativeProfile(); if (!NativeCodeLoader.BuildSupportsOpenssl()) { Log.Warn("Skipping test since openSSL library not loaded"); Assume.AssumeTrue(false); } Assert.Equal(null, OpensslCipher.GetLoadingFailureReason()); CryptoCodecTest(conf, seed, 0, opensslCodecClass, opensslCodecClass, iv); CryptoCodecTest(conf, seed, count, opensslCodecClass, opensslCodecClass, iv); CryptoCodecTest(conf, seed, count, opensslCodecClass, jceCodecClass, iv); // Overflow test, IV: xx xx xx xx xx xx xx xx ff ff ff ff ff ff ff ff for (int i = 0; i < 8; i++) { iv[8 + i] = unchecked ((byte)unchecked ((int)(0xff))); } CryptoCodecTest(conf, seed, count, opensslCodecClass, opensslCodecClass, iv); CryptoCodecTest(conf, seed, count, opensslCodecClass, jceCodecClass, iv); }
/// <exception cref="System.Exception"/> public virtual void TestGetInstance() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); try { cipher = OpensslCipher.GetInstance("AES2/CTR/NoPadding"); NUnit.Framework.Assert.Fail("Should specify correct algorithm."); } catch (NoSuchAlgorithmException) { } // Expect NoSuchAlgorithmException try { cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding2"); NUnit.Framework.Assert.Fail("Should specify correct padding."); } catch (NoSuchPaddingException) { } }
/// <exception cref="GeneralSecurityException"/> public OpensslAesCtrCipher(int mode) { this.mode = mode; cipher = OpensslCipher.GetInstance(Suite.GetName()); }