mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
test_onion: minor protocol change; use single SHA to create both IVs.
Suggested-by: Anthony Towns <aj@erisian.com.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
0c4eb06e26
commit
beb702054b
@ -12,6 +12,7 @@
|
||||
#include <err.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/crypto/sha256/sha256.h>
|
||||
@ -73,22 +74,14 @@ static struct hmackey hmackey_from_secret(const unsigned char secret[32])
|
||||
}
|
||||
|
||||
|
||||
static struct iv iv_from_secret(const unsigned char secret[32])
|
||||
static void ivs_from_secret(const unsigned char secret[32],
|
||||
struct iv *iv, struct iv *pad_iv)
|
||||
{
|
||||
struct iv iv;
|
||||
struct sha256 sha;
|
||||
sha_with_seed(secret, 2, &sha);
|
||||
memcpy(iv.iv, sha.u.u8, sizeof(iv.iv));
|
||||
return iv;
|
||||
}
|
||||
|
||||
static struct iv pad_iv_from_secret(const unsigned char secret[32])
|
||||
{
|
||||
struct iv iv;
|
||||
struct sha256 sha;
|
||||
sha_with_seed(secret, 3, &sha);
|
||||
memcpy(iv.iv, sha.u.u8, sizeof(iv.iv));
|
||||
return iv;
|
||||
BUILD_ASSERT(sizeof(*iv) + sizeof(*pad_iv) == sizeof(sha));
|
||||
memcpy(iv->iv, sha.u.u8, sizeof(iv->iv));
|
||||
memcpy(pad_iv->iv, sha.u.u8 + sizeof(iv->iv), sizeof(pad_iv->iv));
|
||||
}
|
||||
|
||||
/* Not really! */
|
||||
@ -411,8 +404,7 @@ bool create_onion(const secp256k1_pubkey pubkey[],
|
||||
|
||||
hmackeys[i] = hmackey_from_secret(memcheck(secret, 32));
|
||||
enckeys[i] = enckey_from_secret(secret);
|
||||
ivs[i] = iv_from_secret(secret);
|
||||
pad_ivs[i] = pad_iv_from_secret(secret);
|
||||
ivs_from_secret(secret, &ivs[i], &pad_ivs[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -525,8 +517,7 @@ bool decrypt_onion(const struct seckey *myseckey, struct onion *onion,
|
||||
|
||||
hmackey = hmackey_from_secret(secret);
|
||||
*enckey = enckey_from_secret(secret);
|
||||
iv = iv_from_secret(secret);
|
||||
*pad_iv = pad_iv_from_secret(secret);
|
||||
ivs_from_secret(secret, &iv, pad_iv);
|
||||
|
||||
/* Check HMAC. */
|
||||
#if 0
|
||||
|
@ -175,7 +175,7 @@ class Onion(object):
|
||||
enckey = cls.tweak_sha(sec, b'\x00')[:16]
|
||||
hmac = cls.tweak_sha(sec, b'\x01')
|
||||
iv = cls.tweak_sha(sec, b'\x02')[:16]
|
||||
pad_iv = cls.tweak_sha(sec, b'\x03')[:16]
|
||||
pad_iv = cls.tweak_sha(sec, b'\x02')[16:]
|
||||
|
||||
return enckey, hmac, iv, pad_iv
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user