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