Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maamoun TK
nettle
Commits
03dd45f5
Commit
03dd45f5
authored
Apr 19, 2020
by
Dmitry Baryshkov
Committed by
Niels Möller
Apr 19, 2020
Browse files
Options
Downloads
Patches
Plain Diff
gosthash94: switch to using MD_UPDATE() macro
parent
43b5a727
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gosthash94.c
+9
-34
9 additions, 34 deletions
gosthash94.c
gosthash94.h
+3
-2
3 additions, 2 deletions
gosthash94.h
with
12 additions
and
36 deletions
gosthash94.c
+
9
−
34
View file @
03dd45f5
...
...
@@ -283,6 +283,8 @@ gost_compute_sum_and_hash (struct gosthash94_ctx *ctx, const uint8_t *block,
gost_block_compress
(
ctx
,
block_le
,
sbox
);
}
#define COMPRESS(ctx, block) gost_compute_sum_and_hash((ctx), (block), sbox);
/**
* Calculate message hash.
* Can be called repeatedly with chunks of the message to be hashed.
...
...
@@ -296,33 +298,7 @@ gosthash94_update_int (struct gosthash94_ctx *ctx,
size_t
length
,
const
uint8_t
*
msg
,
const
uint32_t
sbox
[
4
][
256
])
{
unsigned
index
=
(
unsigned
)
ctx
->
length
&
31
;
ctx
->
length
+=
length
;
/* fill partial block */
if
(
index
)
{
unsigned
left
=
GOSTHASH94_BLOCK_SIZE
-
index
;
memcpy
(
ctx
->
message
+
index
,
msg
,
(
length
<
left
?
length
:
left
));
if
(
length
<
left
)
return
;
/* process partial block */
gost_compute_sum_and_hash
(
ctx
,
ctx
->
message
,
sbox
);
msg
+=
left
;
length
-=
left
;
}
while
(
length
>=
GOSTHASH94_BLOCK_SIZE
)
{
gost_compute_sum_and_hash
(
ctx
,
msg
,
sbox
);
msg
+=
GOSTHASH94_BLOCK_SIZE
;
length
-=
GOSTHASH94_BLOCK_SIZE
;
}
if
(
length
)
{
/* save leftovers */
memcpy
(
ctx
->
message
,
msg
,
length
);
}
MD_UPDATE
(
ctx
,
length
,
msg
,
COMPRESS
,
ctx
->
count
++
);
}
/**
...
...
@@ -368,21 +344,20 @@ gosthash94_write_digest (struct gosthash94_ctx *ctx,
size_t
length
,
uint8_t
*
result
,
const
uint32_t
sbox
[
4
][
256
])
{
unsigned
index
=
ctx
->
length
&
31
;
uint32_t
msg32
[
8
];
uint32_t
msg32
[
GOSTHASH94_BLOCK_SIZE
/
4
];
assert
(
length
<=
GOSTHASH94_DIGEST_SIZE
);
/* pad the last block with zeroes and hash it */
if
(
index
>
0
)
if
(
ctx
->
index
>
0
)
{
memset
(
ctx
->
message
+
index
,
0
,
32
-
index
);
gost_compute_sum_and_hash
(
ctx
,
ctx
->
message
,
sbox
);
memset
(
ctx
->
block
+
ctx
->
index
,
0
,
GOSTHASH94_BLOCK_SIZE
-
ctx
->
index
);
gost_compute_sum_and_hash
(
ctx
,
ctx
->
block
,
sbox
);
}
/* hash the message length and the sum */
msg32
[
0
]
=
ctx
->
length
<<
3
;
msg32
[
1
]
=
ctx
->
length
>>
2
9
;
msg32
[
0
]
=
(
ctx
->
count
<<
8
)
|
(
ctx
->
index
<<
3
)
;
msg32
[
1
]
=
ctx
->
count
>>
2
4
;
memset
(
msg32
+
2
,
0
,
sizeof
(
uint32_t
)
*
6
);
gost_block_compress
(
ctx
,
msg32
,
sbox
);
...
...
This diff is collapsed.
Click to expand it.
gosthash94.h
+
3
−
2
View file @
03dd45f5
...
...
@@ -89,8 +89,9 @@ struct gosthash94_ctx
{
uint32_t
hash
[
8
];
/* algorithm 256-bit state */
uint32_t
sum
[
8
];
/* sum of processed message blocks */
uint64_t
length
;
/* number of processed bytes */
uint8_t
message
[
GOSTHASH94_BLOCK_SIZE
];
/* 256-bit buffer for leftovers */
uint64_t
count
;
/* Block count */
unsigned
index
;
/* Into buffer */
uint8_t
block
[
GOSTHASH94_BLOCK_SIZE
];
/* 256-bit buffer for leftovers */
};
#define gosthash94cp_ctx gosthash94_ctx
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment