Skip to content

Add Multilinear Galois Mode #185

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
merged 9 commits into from
Aug 1, 2020
Merged

Add Multilinear Galois Mode #185

merged 9 commits into from
Aug 1, 2020

Conversation

newpavlov
Copy link
Member

@newpavlov newpavlov commented Jul 31, 2020

For now it uses standalone code for simplification reasons, but in future hopefully it will use the same code base as ghash and polyval. I haven't ported soft_u32 and probably I will postpone it until unification with polyval.

MGM can also work with 64-bit wide block ciphers, but I doubt I will bother implementing it.

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2020

Codecov Report

Merging #185 into master will decrease coverage by 3.14%.
The diff coverage is 80.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #185      +/-   ##
==========================================
- Coverage   93.95%   90.80%   -3.15%     
==========================================
  Files          28       32       +4     
  Lines         827     1066     +239     
==========================================
+ Hits          777      968     +191     
- Misses         50       98      +48     
Impacted Files Coverage Δ
mgm/src/gf/pclmulqdq.rs 0.00% <0.00%> (ø)
mgm/src/gf/u64_soft.rs 97.67% <97.67%> (ø)
mgm/src/lib.rs 98.24% <98.24%> (ø)
mgm/tests/mod.rs 100.00% <100.00%> (ø)
aes-gcm-siv/src/lib.rs 86.36% <0.00%> (-3.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36a7e8b...b608b89. Read the comment docs.

///
/// When carries do occur, they wind up in a "hole" and are subsequently masked
/// out of the result.
fn bmul64(x: u64, y: u64) -> u128 {
Copy link
Member Author

@newpavlov newpavlov Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I am using u128 here instead of the reversing trick. It allows to simplify code a bit and it should be more performant on targets which support "wide" multiplication. Maybe it's worth to port this approacht to polyval?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

(I'm also curious why all of this can't be implemented in terms of POLYVAL?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also curious why all of this can't be implemented in terms of POLYVAL?

It could be, but I am not sure if it will have the same performance as an "inlined" version. Plus there are some annoying differences between algorithms, e.g. MGM does not chain values like GHASH and Polyval and it uses a "direct" order of bits for mapping binary string to polynomial. I will look into unifying code bases later, but not now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, ok!

@newpavlov newpavlov merged commit 55c0238 into master Aug 1, 2020
@newpavlov newpavlov deleted the mgm branch August 1, 2020 12:18
//! use mgm::aead::{Aead, NewAead, generic_array::GenericArray};
//!
//! let key = GenericArray::from_slice(b"an example very very secret key.");
//! let cipher = Mgm::<Kuznyechik>::new(key);;
Copy link

@kpp kpp Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double ;; at the end of the line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised clippy didn't catch that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently clippy does not check code examples, see: rust-lang/rust#56232

@newpavlov newpavlov mentioned this pull request Aug 7, 2020
@ethindp
Copy link

ethindp commented Sep 25, 2020

Does anyone know how secure this is? I can't seem to find any information on that, and I'm not good at reading papers on cryptographic algorithms or hash functions.

@newpavlov
Copy link
Member Author

newpavlov commented Sep 25, 2020

AFAIK the construction was not properly analyzed by independent cryptographers yet. The authors claim some improvements compared to GCM, but in my understanding they are mostly theoretical. On a con side those properties are achieved by significantly degrading performance, if m is number of blocks in authenticated data and n in plaintext, GCM ecryption requires n+1 applications of a block cipher, while MGM requires 2*n + m + 3, i.e. asymptotic performance is similar to SIV.

Contrary to MGM and GCM, SIV can not be fully parallelized (but it can be fixed by using PMAC-SIV) and requires two passes instead of one (assuming you are not saturating your memory bus it should not be a big problem thanks to prefetching), but it has a really nice property of misuse resistance, which (as far as I understand) is much more important in practice than the theoretical improvements of MGM.

Also MGM authors made, let's say, an "interesting" decision to use nonces with length not multiple of 8 bits (127 and 63 bits for 128 and 64 bit block ciphers respectively), which adds some additional headache when generating nonces (current implementation will return an error if the most significant bit in 128 bit nonce is not equal to zero).

So unless you target Russian crypto standards, I think it is better to choose between GCM and SIV modes.

@tarcieri
Copy link
Member

Also note: AES-GCM-SIV provides both parallelism and AES-GCM equivalent performance (with a ~20% encryption performance penalty, but decryption at equivalent-or-faster speeds to AES-GCM)

@ethindp
Copy link

ethindp commented Sep 25, 2020 via email

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

Successfully merging this pull request may close these issues.

5 participants