Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New encryption functions #184

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

Merged
Necktrox merged 7 commits into multitheftauto:master from SDraw:master
Feb 11, 2018
Merged

New encryption functions #184

Necktrox merged 7 commits into multitheftauto:master from SDraw:master
Feb 11, 2018

Conversation

@SDraw
Copy link
Contributor

@SDraw SDraw commented Jan 12, 2018
edited
Loading

Based on @Elengar 's tests teaEncode works as intended, but teaDecode was pushing decoded data as null-terminated string into VM. Clearly, that's not good for decoded binary data.
Sorry, but I can't compile this for testing because of outdated version of Visual Studio.

Elengar and Disinterpreter reacted with thumbs up emoji
Based on Elengar#3846's tests teaEncode works as intended, but teaDecode was pushing decoded data as null-terminated string into VM. Clearly, that's not good for decoded binary data.
Sorry, but I can't compile this for testing because of outdated version of Visual Studio.
Copy link
Contributor Author

SDraw commented Jan 12, 2018
edited
Loading

Now I see that decoding makes data to be 4 bytes aligned. Need to find workaround for this situation.

Copy link

Elengar commented Jan 12, 2018
edited
Loading

It's because XTEA is a block cipher and block size is 4 bytes.
There are a lot of ways to pad data and then remove padding correctly, may be we need to choose one them
https://en.wikipedia.org/wiki/Padding_%28cryptography%29#Byte_padding
https://www.di-mgt.com.au/cryptopad.html

I guess that the best way is to use PKCS7 (https://en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS7)

Or even better way, (thanks stm#9360 from discord) -- just leave padding as is.
If someone need his own better padding - he can pad data himself and not allow MTA to pad zeros to the end.

Copy link
Contributor Author

SDraw commented Jan 12, 2018

I've thought that encoding/decoding compatibilty will be lost for data that was passed in previous MTA versions, so it's a problem.

What can be done:

  • Add padding in source code
  • Throw off the burden of padding on scripters

In both cases scripters must be informed about this change.

Copy link
Member

ccw808 commented Jan 12, 2018

Wiki example on this page shows how to handle binary data

Copy link
Contributor Author

SDraw commented Jan 12, 2018
edited
Loading

Wiki example on this page shows how to handle binary data

That was the main reason to fix teaDecode in a first place. TEA/XTEA should work with any data, and problem with wrong decoding only present in MTA.
Besides, full data manipulation with wiki example is:

  • Encoding: data -> base64 (from script) -> TEA/XTEA (in source) -> base64 (in source)
  • Decoding: data -> base64 (in source) -> TEA/XTEA (in source) -> base64 (from script)

This is not good at all.

As @Necktrox has suggested it's better to keep teaDecode as it is and make separated functions for encryption/decryption, like

encodeString(string algorithm, string input, table options)
decodeString(string algorithm, string input, table options)

I agree that this way will be far better than lost compatibility.

Copy link

Elengar commented Jan 13, 2018
edited
Loading

@ccw808 but with using base64 it doubles file size.
Okay if we don't want to lost backward compatibility, we can use here lua_pushlstring but before pushing we can trim all trailing zero bytes, instead of using lua_pushstring which cut off all after first found zero byte. So now we have both, backward compatibility, and the possibility to use teaEncode/teaDecode with byte data directly.
And if you worried about what if someone will encrypts data that have a lot of trailing zeros and it matters - again, he can pad the data himself and not allow MTA to eat any trailing zero in the end.

Copy link
Contributor

4O4 commented Jan 13, 2018

Fixing teaEncode is good idea because of ~30% of file size overhead when using b64, but IMO native AES support would be much better for binary files anyway.

Copy link
Contributor Author

SDraw commented Jan 13, 2018
edited
Loading

Need to decide:

  • Should function be backward compatible?
  • Should it care about padding?
  • Or leave it as it is and make new one?

@SDraw SDraw changed the title (削除) teaDecode string pushing fix (削除ここまで) (追記) teaEncode/Decode fix (追記ここまで) Jan 13, 2018
Copy link

Elengar commented Jan 13, 2018

@4O4 not 30%, full 100%, it doubles size.

Copy link
Contributor

4O4 commented Jan 13, 2018

@Elengar I was talking about additional size overhead introduced by the Base64 itself and it's known for a fact that it's always around 30%. teaEncode adds the rest ;)

Elengar reacted with thumbs up emoji

Copy link
Member

ccw808 commented Jan 13, 2018

I agree with @Necktrox's suggestion of new functions like encodeString/decodeString

SDraw added 2 commits January 14, 2018 13:11
Added encryptString and decryptString with TEA algorithm, no padding
@SDraw SDraw changed the title (削除) teaEncode/Decode fix (削除ここまで) (追記) New encryption functions (追記ここまで) Jan 14, 2018
Copy link
Member

Anyone. Watch last PR commits

Copy link

Look at the passwordHash function and use an option table (with a key member for TEA) instead of the key string.

@Necktrox Necktrox added enhancement New feature or request in progress labels Jan 16, 2018
Copy link

Hello, I'm a creator one of the biggest Russian project https://smotramta.ru/ with average daily online about 1000 players. Now we have a lot of custom replaced models and I think this pull request will be very useful for us, because so we can develop our project without fear that someone can steal all our models.

Proof: https://image.ibb.co/mF0FpR/online.jpg

Disinterpreter and PrototypeX reacted with thumbs up emoji

Copy link
Member

What with Travis? It is frozen?

Copy link
Contributor

qaisjp commented Feb 4, 2018

Looks like it. I've restarted the job.

Disinterpreter reacted with thumbs up emoji

Copy link

Necktrox commented Feb 5, 2018

Looks fine, should be merged after a test.

@Necktrox Necktrox merged commit c27fcaa into multitheftauto:master Feb 11, 2018
@patrikjuvonen patrikjuvonen added this to the 1.5.6 milestone Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Labels

enhancement New feature or request

Projects

None yet

Milestone

1.5.6

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /