mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +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:
@@ -12,6 +12,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ccan/build_assert/build_assert.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
#include <ccan/crypto/sha256/sha256.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;
|
struct sha256 sha;
|
||||||
sha_with_seed(secret, 2, &sha);
|
sha_with_seed(secret, 2, &sha);
|
||||||
memcpy(iv.iv, sha.u.u8, sizeof(iv.iv));
|
BUILD_ASSERT(sizeof(*iv) + sizeof(*pad_iv) == sizeof(sha));
|
||||||
return iv;
|
memcpy(iv->iv, sha.u.u8, sizeof(iv->iv));
|
||||||
}
|
memcpy(pad_iv->iv, sha.u.u8 + sizeof(iv->iv), sizeof(pad_iv->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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not really! */
|
/* Not really! */
|
||||||
@@ -411,8 +404,7 @@ bool create_onion(const secp256k1_pubkey pubkey[],
|
|||||||
|
|
||||||
hmackeys[i] = hmackey_from_secret(memcheck(secret, 32));
|
hmackeys[i] = hmackey_from_secret(memcheck(secret, 32));
|
||||||
enckeys[i] = enckey_from_secret(secret);
|
enckeys[i] = enckey_from_secret(secret);
|
||||||
ivs[i] = iv_from_secret(secret);
|
ivs_from_secret(secret, &ivs[i], &pad_ivs[i]);
|
||||||
pad_ivs[i] = pad_iv_from_secret(secret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -525,8 +517,7 @@ bool decrypt_onion(const struct seckey *myseckey, struct onion *onion,
|
|||||||
|
|
||||||
hmackey = hmackey_from_secret(secret);
|
hmackey = hmackey_from_secret(secret);
|
||||||
*enckey = enckey_from_secret(secret);
|
*enckey = enckey_from_secret(secret);
|
||||||
iv = iv_from_secret(secret);
|
ivs_from_secret(secret, &iv, pad_iv);
|
||||||
*pad_iv = pad_iv_from_secret(secret);
|
|
||||||
|
|
||||||
/* Check HMAC. */
|
/* Check HMAC. */
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class Onion(object):
|
|||||||
enckey = cls.tweak_sha(sec, b'\x00')[:16]
|
enckey = cls.tweak_sha(sec, b'\x00')[:16]
|
||||||
hmac = cls.tweak_sha(sec, b'\x01')
|
hmac = cls.tweak_sha(sec, b'\x01')
|
||||||
iv = cls.tweak_sha(sec, b'\x02')[:16]
|
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
|
return enckey, hmac, iv, pad_iv
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user