Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
0020bff2
Commit
0020bff2
authored
May 25, 2015
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto/shachain: enforce that indexes have to be added incrementally.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
9fc07111
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
ccan/crypto/shachain/shachain.c
ccan/crypto/shachain/shachain.c
+8
-2
ccan/crypto/shachain/shachain.h
ccan/crypto/shachain/shachain.h
+1
-0
No files found.
ccan/crypto/shachain/shachain.c
View file @
0020bff2
...
...
@@ -44,9 +44,10 @@ void shachain_from_seed(const struct sha256 *seed, shachain_index_t index,
derive
((
shachain_index_t
)
-
1ULL
,
index
,
seed
,
hash
);
}
void
shachain_init
(
struct
shachain
*
sha
chain
)
void
shachain_init
(
struct
shachain
*
chain
)
{
shachain
->
num_valid
=
0
;
chain
->
num_valid
=
0
;
chain
->
max_index
=
0
;
}
bool
shachain_add_hash
(
struct
shachain
*
chain
,
...
...
@@ -54,6 +55,10 @@ bool shachain_add_hash(struct shachain *chain,
{
int
i
;
/* You have to insert them in order! */
assert
(
index
==
chain
->
max_index
+
1
||
(
index
==
0
&&
chain
->
num_valid
==
0
));
for
(
i
=
0
;
i
<
chain
->
num_valid
;
i
++
)
{
/* If we could derive this value, we don't need it,
* not any others (since they're in order). */
...
...
@@ -74,6 +79,7 @@ bool shachain_add_hash(struct shachain *chain,
chain
->
known
[
i
].
index
=
index
;
chain
->
known
[
i
].
hash
=
*
hash
;
chain
->
num_valid
=
i
+
1
;
chain
->
max_index
=
index
;
return
true
;
}
...
...
ccan/crypto/shachain/shachain.h
View file @
0020bff2
...
...
@@ -15,6 +15,7 @@ void shachain_from_seed(const struct sha256 *seed, shachain_index_t index,
struct
sha256
*
hash
);
struct
shachain
{
shachain_index_t
max_index
;
unsigned
int
num_valid
;
struct
{
shachain_index_t
index
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment