diff --git a/circuits/test/gfmulint/nistgfmul.test.ts b/circuits/test/gfmulint/nistgfmul.test.ts index 7baf55b..f0a7ea4 100644 --- a/circuits/test/gfmulint/nistgfmul.test.ts +++ b/circuits/test/gfmulint/nistgfmul.test.ts @@ -31,6 +31,18 @@ describe("NistGMulByte", () => { const expected = [0xe6, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03]; await circuit.expectPass({ X: X, Y: Y }, { out: expected }); }); + it("Should Compute NistGMulByte of LSB=1 Correctly", async () => { + + // x = "aae06992acbf52a3e8f4a96ec9300bd7" + // y = "98e7247c07f0fe411c267e4384b0f600" + // expected = "90e87315fb7d4e1b4092ec0cbfda5d7d" + let X = [0xaa, 0xe0, 0x69, 0x92, 0xac, 0xbf, 0x52, 0xa3, 0xe8, 0xf4, 0xa9, 0x6e, 0xc9, 0x30, 0x0b, 0xd7]; + let Y = [0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00]; + + const expected = [0x90, 0xe8, 0x73, 0x15, 0xfb, 0x7d, 0x4e, 0x1b, 0x40, 0x92, 0xec, 0x0c, 0xbf, 0xda, 0x5d, 0x7d]; + await circuit.expectPass({ X: X, Y: Y }, { out: expected }); + }); + }); describe("debug1", () => { diff --git a/src/main.rs b/src/main.rs index 882f2cd..7318140 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,7 +107,7 @@ mod tests { }; use hex_literal::hex; - // first byte is 00000001 + // first bit is 1 const H: [u8; 16] = hex!("80000000000000000000000000000000"); const X: [u8; 16] = hex!("80000000000000000000000000000000"); @@ -116,15 +116,26 @@ mod tests { ghash.update(&[X.into()]); let result = ghash.finalize(); + // last bit is 1 const H_1: [u8; 16] = hex!("00000000000000000000000000000001"); const X_1: [u8; 16] = hex!("00000000000000000000000000000001"); - // Alternative. + let mut ghash2 = GHash::new(&H_1.into()); ghash2.update(&[X_1.into()]); let result2 = ghash2.finalize(); - println!("GHASH result_1: {:?}", hex::encode(result.as_slice())); - println!("GHASH result_2: {:?}", hex::encode(result2.as_slice())); + // test vector of pain + const H_2: [u8; 16] = hex!("aae06992acbf52a3e8f4a96ec9300bd7"); + const X_2: [u8; 16] = hex!("98e7247c07f0fe411c267e4384b0f600"); + + let mut ghash3 = GHash::new(&H_2.into()); + ghash3.update(&[X_2.into()]); + let result3 = ghash3.finalize(); + + println!("GHASH Test vector 1: {:?}", hex::encode(result.as_slice())); + println!("GHASH Test vector 2: {:?}", hex::encode(result2.as_slice())); + println!("GHASH Test vector 3: {:?}", hex::encode(result3.as_slice())); + // println!("expected: {:?}", hex::encode(expected)); }