make tampered tests fail less by modifying more bytes
This commit is contained in:
		
							parent
							
								
									d7eb516fc4
								
							
						
					
					
						commit
						1e4c56e58a
					
				@ -53,6 +53,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
                    associatedData,
 | 
			
		||||
@ -105,6 +107,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.tag.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecryptDetached(
 | 
			
		||||
                    encrypted.data,
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
@ -156,6 +160,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.chaCha20Poly1305IetfDecrypt(
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
                    associatedData,
 | 
			
		||||
@ -207,6 +213,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.tag.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.chaCha20Poly1305IetfDecryptDetached(
 | 
			
		||||
                    encrypted.data,
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
@ -257,6 +265,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.chaCha20Poly1305Decrypt(
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
                    associatedData,
 | 
			
		||||
@ -307,6 +317,8 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
 | 
			
		||||
            assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
 | 
			
		||||
                val tamperedTag = encrypted.tag.copyOf()
 | 
			
		||||
                tamperedTag[3] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                AuthenticatedEncryptionWithAssociatedData.chaCha20Poly1305DecryptDetached(
 | 
			
		||||
                    encrypted.data,
 | 
			
		||||
                    tamperedTag,
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,8 @@ class SecretBoxTest {
 | 
			
		||||
            assertFailsWith(SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey::class) {
 | 
			
		||||
                val tamperedTag = encrypted.copyOf()
 | 
			
		||||
                tamperedTag[2] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                SecretBox.openEasy(tamperedTag, nonce, key)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -73,6 +75,8 @@ class SecretBoxTest {
 | 
			
		||||
            assertFailsWith(SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey::class) {
 | 
			
		||||
                val tamperedTag = encrypted.tag.copyOf()
 | 
			
		||||
                tamperedTag[2] = 0U
 | 
			
		||||
                tamperedTag[1] = 0U
 | 
			
		||||
                tamperedTag[0] = 0U
 | 
			
		||||
                SecretBox.openDetached(encrypted.data, tamperedTag, nonce, key)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -75,6 +75,8 @@ class SecretStreamTest {
 | 
			
		||||
            }
 | 
			
		||||
            assertFailsWith(SecretStreamCorruptedOrTamperedDataException::class) {
 | 
			
		||||
                encrypted[encrypted.size - 5] = 0U
 | 
			
		||||
                encrypted[encrypted.size - 4] = 0U
 | 
			
		||||
                encrypted[encrypted.size - 3] = 0U
 | 
			
		||||
                val decryptState = SecretStream.xChaCha20Poly1305InitPull(key, stateAndHeader.header)
 | 
			
		||||
                val decrypted =
 | 
			
		||||
                    SecretStream.xChaCha20Poly1305Pull(decryptState.state, encrypted, ubyteArrayOf())
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,8 @@ class SignatureTest {
 | 
			
		||||
            assertFailsWith(InvalidSignatureException::class) {
 | 
			
		||||
                val tamperedMessage = signedMessage.copyOf()
 | 
			
		||||
                tamperedMessage[crypto_sign_BYTES + 1] = 0U
 | 
			
		||||
                tamperedMessage[crypto_sign_BYTES + 2] = 0U
 | 
			
		||||
                tamperedMessage[crypto_sign_BYTES + 3] = 0U
 | 
			
		||||
                Signature.open(tamperedMessage, keys.publicKey)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -65,6 +67,8 @@ class SignatureTest {
 | 
			
		||||
            assertFailsWith(InvalidSignatureException::class) {
 | 
			
		||||
                val tamperedSignature = signature.copyOf()
 | 
			
		||||
                tamperedSignature[crypto_sign_BYTES - 1] = 0U
 | 
			
		||||
                tamperedSignature[crypto_sign_BYTES - 2] = 0U
 | 
			
		||||
                tamperedSignature[crypto_sign_BYTES - 3] = 0U
 | 
			
		||||
                Signature.finalVerify(verificationState, tamperedSignature, keys.publicKey)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user