Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEA in ECB and CBC modes decryption failure #553

Closed
3 tasks done
guidovranken opened this issue Nov 9, 2020 · 0 comments
Closed
3 tasks done

TEA in ECB and CBC modes decryption failure #553

guidovranken opened this issue Nov 9, 2020 · 0 comments

Comments

@guidovranken
Copy link

guidovranken commented Nov 9, 2020

Prerequisites

Description

The TEA cipher in ECB and CBC modes does not encrypt, then decrypt into the original plaintext.

Steps to Reproduce

This is a reproducer for TEA+ECB. It should decrypt into the original plaintext (16 zero bytes), but instead it decrypts into:

89 0B D3 76 28 BB E5 C2 89 0B D3 76 28 BB E5 C2
#include <tomcrypt.h>

#define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; }
#define CF_CHECK_NE(expr, res) if ( (expr) == (res) ) { goto end; }

int main(void)
{
    const unsigned char in[16] = {0};
    const unsigned char key[16] = {0};
    unsigned char encrypted[16], decrypted[16];
    symmetric_ECB ecb1, ecb2;

    CF_CHECK_NE(register_all_ciphers(), -1);

    CF_CHECK_EQ(ecb_start(find_cipher("tea"), key, sizeof(key), 0, &ecb1), CRYPT_OK);
    CF_CHECK_EQ(ecb_encrypt(in, encrypted, sizeof(in), &ecb1), CRYPT_OK);
    CF_CHECK_EQ(ecb_done(&ecb1), CRYPT_OK);

    printf("Encrypted:\n");
    for (size_t i = 0; i < sizeof(encrypted); i++) {
        printf("%02X ", encrypted[i]);
    }
    printf("\n");

    CF_CHECK_EQ(ecb_start(find_cipher("tea"), key, sizeof(key), 0, &ecb2), CRYPT_OK);
    CF_CHECK_EQ(ecb_decrypt(encrypted, decrypted, sizeof(encrypted), &ecb2), CRYPT_OK);
    CF_CHECK_EQ(ecb_done(&ecb2), CRYPT_OK);

    printf("Decrypted:\n");
    for (size_t i = 0; i < sizeof(decrypted); i++) {
        printf("%02X ", decrypted[i]);
    }
    printf("\n");

end:
    return 0;
}

Version

Latest develop branch checkout, Clang, Linux 64 bit.

Additional Information

I've been testing all combinations of ciphers + modes for correctness. All operate as expected, the sole exceptions are TEA+ECB and TEA+CBC.

sjaeckel added a commit that referenced this issue Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant