Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
A pointless problem?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Davis  
View profile  
 More options Nov 17 2012, 12:02 pm
From: Steve Davis <steven.charles.da...@gmail.com>
Date: Sat, 17 Nov 2012 11:02:22 -0600
Local: Sat, Nov 17 2012 12:02 pm
Subject: [erlang-questions] A pointless problem?

I am intrigued by what is arguably a pointless problem.

Looking at the tiny encryption algorithm aka XXTEA it seemed easy enough to implement in Erlang. I have an implementation (attached with source and all references inside the module) which encodes and decodes successfully... BUT the cipher text doesn't match the test vectors...

What makes this pointless is that I should "just make it a NIF" etc. But it's likely that I am misunderstanding some aspect of either Erlang or C, however I am confounded as to what that problem is... why does the attached implementation not generate the same ciphertext as in the test vectors from the C implementation? Can anyone spot my error?

Thanks,
/s

  xxtea.erl.txt
9K Download

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmitry Kolesnikov  
View profile  
 More options Nov 17 2012, 12:28 pm
From: Dmitry Kolesnikov <dmkolesni...@gmail.com>
Date: Sat, 17 Nov 2012 19:28:42 +0200
Local: Sat, Nov 17 2012 12:28 pm
Subject: Re: [erlang-questions] A pointless problem?

Hello,

This looks as endianness problem. You have to keep in-mind that binaries is big-endian by default, which contrasts with C memory. You have to be very careful of C algorithms mapping.

I've made a small fixes to int32list_xxx routines (see bold text):

int32list_from_binary(Bin) ->
        int32list_from_binary(Bin, []).
int32list_from_binary(<<X:32/little, Bin/binary>>, Acc) ->
        int32list_from_binary(Bin, [X|Acc]);
int32list_from_binary(<<>>, Acc) ->
        lists:reverse(Acc).

int32list_to_binary(List) ->
        list_to_binary([<<X:32/little>> || X <- List]).

Some of tests got passed. Unfortunately, some of tests are failed I hope you can easily validate rest of you code agains endian.  

{test,true,true,{<<"ab043705808c5d57">>,<<"ab043705808c5d57">>}}
{test,false,true,{<<"26e3868b9d66a048">>,<<"d1e78be2c746728a">>}}
{test,false,true,{<<"2a70e36b99941f2d">>,<<"67ed0ea8e8973fc5">>}}
{test,false,true,{<<"a30d3870c0873c23">>,<<"8c3707c01c7fccc4">>}}
{test,true,true,
      {<<"b2601cefb078b772abccba6a">>,<<"b2601cefb078b772abccba6a">>}}
{test,false,true,
      {<<"ddbcb4b88b2c5a268081a8b4">>,<<"579016d143ed6247ac6710dd">>}}
{test,true,true,
      {<<"c0a19f06ebb0d63925aa27f74cc6b2d0">>,
       <<"c0a19f06ebb0d63925aa27f74cc6b2d0">>}}
{test,false,true,
      {<<"bd28749d4fc20b73a79d59a25d55ab27">>,
       <<"01b815fd2e4894d13555da434c9d868a">>}}

Best Regards,
Dmitry

On Nov 17, 2012, at 7:02 PM, Steve Davis wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Armstrong  
View profile  
 More options Nov 17 2012, 12:33 pm
From: Joe Armstrong <erl...@gmail.com>
Date: Sat, 17 Nov 2012 18:33:22 +0100
Local: Sat, Nov 17 2012 12:33 pm
Subject: Re: [erlang-questions] A pointless problem?

On Sat, Nov 17, 2012 at 6:02 PM, Steve Davis <steven.charles.da...@gmail.com

> wrote:
> I am intrigued by what is arguably a pointless problem.

Not really

> Looking at the tiny encryption algorithm aka XXTEA it seemed easy enough
> to implement in Erlang. I have an implementation (attached with source and
> all references inside the module) which encodes and decodes successfully...
> BUT the cipher text doesn't match the test vectors...

I had exactly the same problem with tea a few years ago ...

I'd really like to see:

a) an algebraic spec
b) reference implementations in more than one language that I can reproduce

I'm more interested in inter-operability than performance - (think client
in Javascript
backend in C / Erlang) - so compliance with the spec is more important than
performance.
(which is why I like RSA implemented in erlang bignums - no chance of
backdoors in the code)

> What makes this pointless is that I should "just make it a NIF" etc. But
> it's likely that I am misunderstanding some aspect of either Erlang or C,
> however I am confounded as to what that problem is... why does the attached
> implementation not generate the same ciphertext as in the test vectors from
> the C implementation? Can anyone spot my error?

Before you ask this you might ask "can the test vectors be reproduced in
any other
language/implementation than the reference implementation?"

Cheers

/Joe

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Davis  
View profile  
 More options Nov 17 2012, 12:39 pm
From: Steve Davis <steven.charles.da...@gmail.com>
Date: Sat, 17 Nov 2012 11:39:45 -0600
Local: Sat, Nov 17 2012 12:39 pm
Subject: Re: [erlang-questions] A pointless problem?

Ah - insight. Endianness did occur to me as a problem but I think I maybe went "too far" in compensating for it previously.

From the tests now I can see that it's the Key endianness that is the remaining issue...

Thank you so much!

Regards,
/s

On Nov 17, 2012, at 11:28 AM, Dmitry Kolesnikov <dmkolesni...@gmail.com> wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Slava Yurin  
View profile  
 More options Nov 17 2012, 12:41 pm
From: Slava Yurin <Yuri...@yandex.ru>
Date: Sun, 18 Nov 2012 00:40:59 +0700
Local: Sat, Nov 17 2012 12:40 pm
Subject: Re: [erlang-questions] A pointless problem?

I confirm this.
О©╫
18.11.2012, 00:28, "Dmitry Kolesnikov" <dmkolesnikov@gmail.com>:
Hello,
This looks as endianness problem. You have to keep in-mind that binaries is big-endianО©╫by default, which contrasts with C memory. You have to be very careful of C algorithms mapping.
О©╫
s/:32/:32\/little/g make test work.
My 5 cents:
О©╫ You can write list_to_binary([<<X:32/little>> || X <- List]) as << <<X:32/little>> || X <- List >>.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Davis  
View profile  
 More options Nov 17 2012, 12:45 pm
From: Steve Davis <steven.charles.da...@gmail.com>
Date: Sat, 17 Nov 2012 11:45:12 -0600
Local: Sat, Nov 17 2012 12:45 pm
Subject: Re: [erlang-questions] A pointless problem?

once I made an additional small mod to the key decoding

i.e.
encode(Key, Plaintext) ->
        K = list_to_tuple(int32list_from_binary(Key)),

I got success:

73> ice_crypto_btea:test().
{test,true,true,{<<"ab043705808c5d57">>,<<"ab043705808c5d57">>}}
{test,true,true,{<<"d1e78be2c746728a">>,<<"d1e78be2c746728a">>}}
{test,true,true,{<<"67ed0ea8e8973fc5">>,<<"67ed0ea8e8973fc5">>}}
{test,true,true,{<<"8c3707c01c7fccc4">>,<<"8c3707c01c7fccc4">>}}
{test,true,true,
      {<<"b2601cefb078b772abccba6a">>,<<"b2601cefb078b772abccba6a">>}}
{test,true,true,
      {<<"579016d143ed6247ac6710dd">>,<<"579016d143ed6247ac6710dd">>}}
{test,true,true,
      {<<"c0a19f06ebb0d63925aa27f74cc6b2d0">>,
       <<"c0a19f06ebb0d63925aa27f74cc6b2d0">>}}
{test,true,true,
      {<<"01b815fd2e4894d13555da434c9d868a">>,
       <<"01b815fd2e4894d13555da434c9d868a">>}}

My thanks to you for saving my sanity!

Best regards,
/s

On Nov 17, 2012, at 11:28 AM, Dmitry Kolesnikov <dmkolesni...@gmail.com> wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic