BOLT 8: Add test vectors.#42
Conversation
| input: 0x00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a | ||
| # re=0x036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7 | ||
| # h=0x9e0e7de8bb75554f21db034633de04be41a2b8a18da7a319a03c803bf02b396c | ||
| # ss=0x1e2fb3c8fe8fb9f262f649f64d26ecf0f2c0a805a767cf02dc2d77a6ef1fdcc3 |
There was a problem hiding this comment.
I believe that you've used secp256k1's ecdh function which returns sha256(serialized compressed point) instead of point.x ? With this change I can generate your results with our own implementation.
There was a problem hiding this comment.
Indeed! Lets defer this pending results of #43
| e.pub: 0x036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7 | ||
| # Act One | ||
| # e.pub=0x036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7 e.priv=0x1212121212121212121212121212121212121212121212121212121212121212 | ||
| # h=0x9e0e7de8bb75554f21db034633de04be41a2b8a18da7a319a03c803bf02b396c |
There was a problem hiding this comment.
I think we should also specify what the starting h and ck values should be (for both sides before ActOne):
h = 0x8401b3fdcaaa710b5405400536a3d5fd7792fe8e7fe29cd8b687216fe323ecbd
ck = 2640f52eebcd9e882958951c794250eedb28002c05d7dc2ea0f195406042caf1
This'll help implementers to ensure they initialized the state properly.
There was a problem hiding this comment.
Good idea... and those numbers match mine.
| # t=0xe2699a63f350d1f255b883454a55112c | ||
| output: 0x00d0fedc211450dd9602b41081c9bd05328b8bf8c0238880f7b7cb8a34bb6d835408eba066c42574ce959ffbac6bd051c664e2699a63f350d1f255b883454a55112c | ||
| # HKDF(0x919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01,zero) | ||
| output: sk,rk=0x969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9,0xbb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442 |
There was a problem hiding this comment.
So everything lines up for me up until this point.
Instead I have:
sk=4438f22354d2620c3e7698c96bc880eee8101709baa6318e73ad799db173ca2d
rk=4453668c85a468a61fdfe661864fc543eaeac9ce0634dd827a5e2c0205c8edfb
There was a problem hiding this comment.
What are your full HKDF parameters for secret, salt, info?
There was a problem hiding this comment.
OK, here it is in the debugger.
Inputs to HKDF:
salt = 0x91, 0x92,
0x19, 0xdb, 0xb2, 0x92, 0xa, 0xfa, 0x8d, 0xb8, 0xf, 0x9a, 0x51, 0x78,
0x7a, 0x84, 0xb, 0xcf, 0x11, 0x1e, 0xd8, 0xd5, 0x88, 0xca, 0xf9, 0xab,
0x4b, 0xe7, 0x16, 0xe4, 0x2b, 0x1
saltlen: 32
IKM-len: 0
info-len: 0
Gives PRK: {0x54, 0xde,
0x99, 0x40, 0xe0, 0xbe, 0x34, 0x8d, 0x2, 0x4d, 0x40, 0xf6, 0xfd, 0x38,
0x5d, 0x64, 0x92, 0xf6, 0x1f, 0xb, 0x1d, 0xb5, 0x7, 0x64, 0xb4, 0xcb,
0x34, 0x11, 0x70, 0xcf, 0x9b, 0xcb}
T(0) = ""
T(1) = HMAC_SHA256(PRK || 0x01) = {0x96, 0x9a,
0xb3, 0x1b, 0x4d, 0x28, 0x8c, 0xed, 0xf6, 0x21, 0x88, 0x39, 0xb2,
0x7a, 0x3e, 0x21, 0x40, 0x82, 0x70, 0x47, 0xf2, 0xc0, 0xf0, 0x1b,
0xf5, 0xc0, 0x44, 0x35, 0xd4, 0x35, 0x11, 0xa9}
T(2) = HMAC_SHA256(PRK || T(1) || 0x2)
= {0xbb, 0x90,
0x20, 0xb8, 0x96, 0x5f, 0x4d, 0xf0, 0x47, 0xe0, 0x7f, 0x95, 0x5f,
0x3c, 0x4b, 0x88, 0x41, 0x89, 0x84, 0xaa, 0xdc, 0x5c, 0xdb, 0x35, 0x9,
0x6b, 0x9e, 0xa8, 0xfa, 0x5c, 0x34, 0x42}
|
OK, if I fix the nonce endian to le, I get: output: rk,sk=0x969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9,0xbb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442 If you concur @sstone , I'll regen the test vectors. |
|
I get the same results, with the following intermediate values for act 3: Initiator: Responder: |
|
After fixing the @sstone are you including the |
|
No you're right I left it out sorry... |
5459de7 to
75d950c
Compare
|
That's what I understood from the Noise specs: 32 bits of zeros followed by little-endian encoding of n (the first 32 bits of zeros make it compatible with the old ChaCha20 implementations that use a 64 bit nonce). |
|
Ahh, I must've skimmed over the nonce bit in the vectors! I implemented it the way way that @sstone did, so my nonce is |
|
Yay, now we seem to match! If no objections, I'll squash some commits together and merge. |
This follows the Noise spec. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
f677f62 to
4837c60
Compare
Needs @Roasbeef to check they work for him (at least, the success cases).