Giter Club home page Giter Club logo

Comments (7)

arktronic avatar arktronic commented on August 30, 2024

You're right, I was assuming that empty plaintext would make n equal to 0 and therefore trigger the AES-CMAC(K, <one>) case. But if that's not what should happen, then I'm not sure how that case could ever occur. This begs the question of why it's in the RFC pseudocode in the first place...

Can you point to other implementation(s) that handle this case differently? I'm definitely interested in having correct code here. (We need more test vectors, too.)

from aes-siv.

dchest avatar dchest commented on August 30, 2024

I think RFC includes this because they define S2V as a key derivation function (1.3.3), and thus need the complete and self-contained function, which can be implemented separately from SIV.

Here are some implementations I found:

I agree with you about test vectors, I was looking for more of them myself.

from aes-siv.

arktronic avatar arktronic commented on August 30, 2024

This is really interesting. The Go code just panics if there's nothing there:

if numStrings == 0 {
    panic("strings vector must be non-empty.")
}

The NetBSD code actually appears to do the RFC's <one> thing:

if (!num_elem) {
    os_memcpy(tmp, zero, sizeof(zero));
    tmp[AES_BLOCK_SIZE - 1] = 1;
    return omac1_aes_128(key, tmp, sizeof(tmp), mac);
}

Finally, both the authsae code and Botan seem to be unconcerned with the possibility of size zero.

I have no idea what the correct approach is. On one hand, there's the RFC. The <one> reference is present since the first draft. On the other, there's the info from NIST, where I'm not seeing anything like that in any of the SIV links there.

from aes-siv.

dchest avatar dchest commented on August 30, 2024

NetBSD code has this case, however it's not triggered, as num_elem is never zero, see aes_siv_encrypt:

    if (aes_s2v(k1, num_elem + 1, _addr, _len, v))
        return -1;

Same with other implementations: they all consider zero-length plaintext as the last vector, which is present, and which gets padded with 0x80.

In the linked page (thanks, I didn't see it), there's http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/siv/keywrap.pdf, which has CMAC* without this case [page 12]:

screen shot 2015-05-27 at 10 19 40

Edited: the full S2V is NIST document includes this case (when the number of vectors is zero) [page 10]:

screen shot 2015-05-27 at 11 15 28

But as you can see, they dropped this case in CMAC*, as it's obvious that it's never zero.

from aes-siv.

dchest avatar dchest commented on August 30, 2024

FYI, here's how RFC algorithm would be written if ported from your code, which is incorrect even for the full S2V:

S2V(K, S1, ..., Sn) {
  if (n-1) = 0 and len(Sn) = 0 then
    return V = AES-CMAC(K, <one>)
  fi
  D = AES-CMAC(K, <zero>)
  for i = 1 to n-1 do
    D = dbl(D) xor AES-CMAC(K, Si)
  done
  if len(Sn) >= 128 then
    T = Sn xorend D
  else
    T = dbl(D) xor pad(Sn)
  fi
  return V = AES-CMAC(K, T)
}

from aes-siv.

arktronic avatar arktronic commented on August 30, 2024

That's fair. Do you think I should just get rid of that if clause then?

from aes-siv.

dchest avatar dchest commented on August 30, 2024

@arktronic yes, and this part should be removed https://github.com/arktronic/aes-siv/blob/master/aes-siv/aes256-siv.cpp#L46:L51

from aes-siv.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.