-
Notifications
You must be signed in to change notification settings - Fork 13
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
GHASH multiplication result #202
Comments
Are you trying to use |
In GHash, there are no direct mul operation. But as I see, I can do multiplication in terms of Polyval, by mulx and reverse byte order. |
Okay, that's not going to make things easy. It looks like you're not reversing the inputs or outputs, for starters. |
let mut a = hex!("34904055 11BE3297 1343724C 5AB793E9");
let mut b = hex!("22481783 8761A9D6 E3EC9689 110FB0F3");
let mut c = hex!("0001D107 FC67DE40 04DC2C80 3DFD95C3");
let a_block = Block::from(a);
let b_block = Block::from(b);
let b_block = crate::mulx(&b_block);
let u = U64x2::from(&a_block);
let v = U64x2::from(&b_block);
let w = u * v;
let w_bytes = [w.0.to_le_bytes(), w.1.to_le_bytes()].concat();
println!("w: {:02X?}", w_bytes);
let mut a = hex!("34904055 11BE3297 1343724C 5AB793E9");
a.reverse();
let mut b = hex!("22481783 8761A9D6 E3EC9689 110FB0F3");
b.reverse();
let mut c = hex!("0001D107 FC67DE40 04DC2C80 3DFD95C3");
Looks like, im doing something wrong :) |
It still seems like you aren't reversing the inputs. Perhaps you should try to get the basic GHASH working before you move on? |
I have already tried. But for * operation, I have test values. |
GHASH has test vectors. The
Do you mean that the lower code example in the latest comment replaces the top? It's very confusing. You need to reverse both of the inputs before multiplying, then reverse the output. |
let mut u = hex!("34904055 11BE3297 1343724C 5AB793E9");
let mut v = hex!("22481783 8761A9D6 E3EC9689 110FB0F3");
let mut ghash = GHash::new(&Key::<GHash>::from(v));
ghash.update_padded(&u);
let r = ghash.finalize();
println!("{:02X?}", r);
Is that correct, to perform multiply u * v in terms of polyval? |
I meant that you should try to implement GHASH itself in terms of the |
Okay. But we have already correct GHash crate :) |
There's a bug somewhere in your code, and since your examples aren't complete / runnable I can't tell where. That's why I was suggesting you at least get GHASH right, since that should be easy to compare to the working |
The following test added to #[test]
fn belt_test() {
use hex_literal::hex;
let mut a = Block::clone_from_slice(&hex!("34904055 11BE3297 1343724C 5AB793E9"));
a.reverse();
let mut b = Block::clone_from_slice(&hex!("22481783 8761A9D6 E3EC9689 110FB0F3"));
b.reverse();
let mut res = Block::clone_from_slice(&hex!("0001D107 FC67DE40 04DC2C80 3DFD95C3"));
res.reverse();
let mut val = Element::new();
val.mul_sum(&a, &b);
assert_eq!(res, val.into_bytes());
} MGM uses big endian order, thus the need for reverses. So the issue is with order of bits. It should be possible to do it with |
We could potentially add a |
For now, I think the easiest solution for |
I think this should be fine solution. Thank you so much for helping. And you, @tarcieri. |
Hello. I have two words:
u:
34904055 11BE3297 1343724C 5AB793E9
v:
22481783 8761A9D6 E3EC9689 110FB0F3
u * v is defined:
𝑤(𝑥) = 𝑢(𝑥)𝑣(𝑥) mod 𝑥 ^ 128 + 𝑥 ^ 7 + 𝑥 ^ 2 + 𝑥 + 1
u * v should be:
0001D107 FC67DE40 04DC2C80 3DFD95C3
As i suggest, code should be like this:
But result is like:
[43, EF, 88, F0, CA, C0, 21, F9, D1, BD, 33, 94, A0, E4, C0, DE]
Also, tried to reverse output bytes, but no luck with that. Any ideas how to deal with that?
Thank you.
The text was updated successfully, but these errors were encountered: