@ -51,26 +51,30 @@ bool derive_basepoints(const struct secret *seed,
return true ;
return true ;
}
}
void per_commit_secret ( const struct sha256 * shaseed ,
bool per_commit_secret ( const struct sha256 * shaseed ,
struct secret * commit_secret ,
struct secret * commit_secret ,
u64 per_commit_index )
u64 per_commit_index )
{
{
struct sha256 s ;
struct sha256 s ;
if ( per_commit_index > = ( 1ULL < < SHACHAIN_BITS ) )
return false ;
shachain_from_seed ( shaseed , shachain_index ( per_commit_index ) , & s ) ;
shachain_from_seed ( shaseed , shachain_index ( per_commit_index ) , & s ) ;
BUILD_ASSERT ( sizeof ( s ) = = sizeof ( * commit_secret ) ) ;
BUILD_ASSERT ( sizeof ( s ) = = sizeof ( * commit_secret ) ) ;
memcpy ( commit_secret , & s , sizeof ( s ) ) ;
memcpy ( commit_secret , & s , sizeof ( s ) ) ;
return true ;
}
}
bool per_commit_point ( const struct sha256 * shaseed ,
bool per_commit_point ( const struct sha256 * shaseed ,
struct pubkey * commit_point ,
struct pubkey * commit_point ,
u64 per_commit_index )
u64 per_commit_index )
{
{
struct sha256 per_commit_ secret ;
struct secret secret ;
/* Derive new per-commitment-point. */
if ( ! per_commit_secret ( shaseed , & secret , per_commit_index ) )
shachain_from_seed ( shaseed , shachain_index ( per_commit_index ) ,
return false ;
& per_commit_secret ) ;
/* BOLT #3:
/* BOLT #3:
*
*
@ -81,7 +85,7 @@ bool per_commit_point(const struct sha256 *shaseed,
*/
*/
if ( secp256k1_ec_pubkey_create ( secp256k1_ctx ,
if ( secp256k1_ec_pubkey_create ( secp256k1_ctx ,
& commit_point - > pubkey ,
& commit_point - > pubkey ,
per_commit_ secret. u . u8 ) ! = 1 )
secret . data ) ! = 1 )
return false ;
return false ;
return true ;
return true ;
@ -235,6 +239,9 @@ bool shachain_get_secret(const struct shachain *shachain,
{
{
struct sha256 sha ;
struct sha256 sha ;
if ( commit_num > = ( 1ULL < < SHACHAIN_BITS ) )
return false ;
if ( ! shachain_get_hash ( shachain , shachain_index ( commit_num ) , & sha ) )
if ( ! shachain_get_hash ( shachain , shachain_index ( commit_num ) , & sha ) )
return false ;
return false ;
BUILD_ASSERT ( sizeof ( * preimage ) = = sizeof ( sha ) ) ;
BUILD_ASSERT ( sizeof ( * preimage ) = = sizeof ( sha ) ) ;