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

Binary keys are not supported correctly. #3

Open
maxux opened this issue Aug 10, 2018 · 0 comments
Open

Binary keys are not supported correctly. #3

maxux opened this issue Aug 10, 2018 · 0 comments

Comments

@maxux
Copy link

maxux commented Aug 10, 2018

The README claims that plain raw binary keys are accepted, but it's not true.

You can see line 87 to 92, to build the « fixed key » (the key padded), you look for any 0x00 and assume this is the end of a string. This break binary compatibility.

You need to receive the key length from the user, and pad if it's < 16 bytes.
I didn't fixed this issue in a proper way, since keys I use are always 16 bytes. But this is a major issue.

My quick fix is adding two functions (to not break call compatibility):

void * xxtea_encrypt_bkey(const void * data, size_t len, const void * key, size_t key_len, size_t * out_len) {
    if(key_len < 16)
        return NULL;

    return xxtea_ubyte_encrypt((const uint8_t *)data, len, key, out_len);
}

void * xxtea_decrypt_bkey(const void * data, size_t len, const void * key, size_t key_len, size_t * out_len) {
    if(key_len < 16)
        return NULL;

    return xxtea_ubyte_encrypt((const uint8_t *)data, len, key, out_len);
}

And call _bkey version when passing (safe) binary keys.

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