Re: Salsa20 test vectors

Discussion in 'C Programming' started by Noob, Aug 6, 2012.

  1. Noob

    Noob Guest

    [ Adding comp.lang.c so they can correct me ]

    Paul Rubin wrote:

    > Cristiano wrote:
    >
    >> static const char sigma[16] = "expand 32-byte k";
    >> static const char tau[16] = "expand 16-byte k";

    >
    > This makes a 32-byte block in memory whose contents are
    > |expand 32-byte kexpand 16-byte k|
    > where the vertical bars delimit block.


    This is incorrect. The compiler has no obligation to store
    sigma and tau contiguously.

    In other words, assert(tau == sigma + sizeof sigma) may fail.
    Noob, Aug 6, 2012
    #1
    1. Advertising

  2. Noob

    Mark Bluemel Guest

    On 06/08/2012 09:48, Noob wrote:
    > [ Adding comp.lang.c so they can correct me ]
    >
    > Paul Rubin wrote:
    >
    >> Cristiano wrote:
    >>
    >>> static const char sigma[16] = "expand 32-byte k";
    >>> static const char tau[16] = "expand 16-byte k";

    >>
    >> This makes a 32-byte block in memory whose contents are
    >> |expand 32-byte kexpand 16-byte k|
    >> where the vertical bars delimit block.

    >
    > This is incorrect. The compiler has no obligation to store
    > sigma and tau contiguously.
    >
    > In other words, assert(tau == sigma + sizeof sigma) may fail.


    Indeed.
    Mark Bluemel, Aug 6, 2012
    #2
    1. Advertising

  3. Noob

    Paul Rubin Guest

    Noob <root@127.0.0.1> writes:
    >> This makes a 32-byte block in memory whose contents are
    >> |expand 32-byte kexpand 16-byte k|
    >> where the vertical bars delimit block.

    > This is incorrect. The compiler has no obligation to store
    > sigma and tau contiguously.


    You are right, and of course DJB would not have made such a silly error.
    It looks like I read the keysetup function incorrectly for some reason.
    It actually chooses between sigma and tau based on the key size, and
    doesn't use both or rely on them being contiguous.

    So I guess we still don't know why Cristiano's tests are getting wrong
    results. I may spend a little time investigating further later, but
    have other things going on right now.
    Paul Rubin, Aug 6, 2012
    #3
  4. Noob

    Cristiano Guest

    On 06/08/2012 22:27, Paul Rubin wrote:
    > So I guess we still don't know why Cristiano's tests are getting wrong
    > results.


    But I posted 10 hours ago... I said: "To get the right result I need to
    do a single call to ECRYPT_encrypt_bytes() with a 512-byte plaintext."

    > I may spend a little time investigating further later, but
    > have other things going on right now.


    Thank you, but the problem is solved. :)

    Cristiano
    Cristiano, Aug 6, 2012
    #4
  5. Cristiano <> writes:
    > On 06/08/2012 22:27, Paul Rubin wrote:
    >> So I guess we still don't know why Cristiano's tests are getting wrong
    >> results.

    >
    > But I posted 10 hours ago... I said: "To get the right result I need to
    > do a single call to ECRYPT_encrypt_bytes() with a 512-byte plaintext."


    You only posted that to sci.crypt.

    Your original article was posted only to sci.crypt. "Noob"
    cross-posted a followup to sci.crypt and comp.lang.c, which resulted
    in comp.lang.c readers seeing only part of the thread (and probably
    not being aware of it).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Will write code for food.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Aug 6, 2012
    #5
  6. Noob

    Paul Rubin Guest

    Cristiano <> writes:
    > Thank you, but the problem is solved. :)


    Oh good, I see it now. Thanks for the update.
    Paul Rubin, Aug 6, 2012
    #6
  7. On Tue, 7 Aug 2012 10:22:30 +0200, "io_x" <> wrote:

    >
    >"Noob" <root@127.0.0.1> ha scritto nel messaggio
    >news:jvo0bp$tbo$...
    >>[ Adding comp.lang.c so they can correct me ]
    >>
    >> Paul Rubin wrote:
    >>
    >>> Cristiano wrote:
    >>>
    >>>> static const char sigma[16] = "expand 32-byte k";
    >>>> static const char tau[16] = "expand 16-byte k";

    >
    >because the string is 16 char + \0 it has to be >=17


    The two definitions above define character arrays that do not contain
    strings. Unless they need to be strings, there is nothing wrong with
    the definitions. They only need to have 17 elements if they are
    indeed strings.

    --
    Remove del for email
    Barry Schwarz, Aug 7, 2012
    #7
  8. On Aug 7, 9:22 am, "io_x" <> wrote:
    > "Noob" <r...@127.0.0.1> ha scritto nel messaggionews:jvo0bp$tbo$...
    > > Paul Rubin wrote:
    > >> Cristiano wrote:



    > >>>    static const char sigma[16] = "expand 32-byte k";
    > >>>    static const char tau[16] = "expand 16-byte k";

    >
    > because the string is 16 char + \0 it has to be >=17
    >
    > it has to be
    > static const char sigma[17] = "expand 32-byte k";


    no. The compiler simply omits the '\0' if the array size is
    the same as the number of characters. As Barry remarks it isn't
    a string tho'

    [C++ behaves differently]

    > or if that number scare you
    > static const char sigma[18] = "expand 32-byte k";


    ? why would 17 scare me? Do you have a phobia about prime numbers?

    <snip>
    Nick Keighley, Aug 8, 2012
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lily
    Replies:
    16
    Views:
    1,328
    Bob Jenkins
    May 10, 2004
  2. Replies:
    14
    Views:
    774
    Gabriel Genellina
    Feb 11, 2008
  3. Replies:
    3
    Views:
    693
    Shadowman
    Mar 26, 2008
  4. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    694
    Skybuck Flying
    Oct 4, 2009
  5. Guest
    Replies:
    0
    Views:
    439
    Guest
    Sep 14, 2005
Loading...

Share This Page