Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Wim Lewis
nettle
Commits
5cb171eb
Commit
5cb171eb
authored
Jan 09, 2002
by
Niels Möller
Browse files
(Hash functions): Update for the changed
interface without *_final. Document sha256. Rev: src/nettle/nettle.texinfo:1.9
parent
d9d72c36
Changes
1
Hide whitespace changes
Inline
Side-by-side
nettle.texinfo
View file @
5cb171eb
...
...
@@ -251,7 +251,7 @@ its SHA1 checksum on stdout should give the flavour of Nettle.
#include <stdio.h>
#include <stdlib.h>
#include <nettle/sha
1
.h>
#include <nettle/sha.h>
#define BUF
_
SIZE 1000
...
...
@@ -286,7 +286,6 @@ main(int argc, char **argv)
if (ferror(stdin))
return EXIT
_
FAILURE;
sha1
_
finish(
&
ctx);
sha1
_
digest(
&
ctx, SHA1
_
DIGEST
_
SIZE, digest);
display
_
hex(SHA1
_
DIGEST
_
SIZE, digest);
...
...
@@ -361,30 +360,29 @@ Initialize the MD5 state.
Hash some more data.
@end deftypefun
@deftypefun void md5
_
final (struct md5
_
ctx *@var
{
ctx
}
)
Performs final processing that is needed after all input data has been
processed with @code
{
md5
_
update
}
.
@end deftypefun
@deftypefun void md5
_
digest (struct md5
_
ctx *@var
{
ctx
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
digest
}
)
Extracts the message digest, writing it to @var
{
digest
}
. @var
{
length
}
may be smaller than @code
{
MD5
_
DIGEST
_
SIZE
}
, in which case only the first
@var
{
length
}
octets of the digest are written.
Performs final processing and extracts the message digest, writing it
to @var
{
digest
}
. @var
{
length
}
may be smaller than
@code
{
MD5
_
DIGEST
_
SIZE
}
, in which case only the first @var
{
length
}
octets of the digest are written.
This functions doesn't change the state in any way.
This function also resets the context in the same way as
@code
{
md5
_
init
}
.
@end deftypefun
The normal way to use MD5 is to call the functions in order: First
@code
{
md5
_
init
}
, then @code
{
md5
_
update
}
zero or more times, then
@code
{
md5
_
final
}
, and at last @code
{
md5
_
digest
}
zero or more times.
@code
{
md5
_
init
}
, then @code
{
md5
_
update
}
zero or more times, and finally
@code
{
md5
_
digest
}
. After @code
{
md5
_
digest
}
, the context is reset to
its initial state, so you can start over calling @code
{
md5
_
update
}
to
hash new data.
To start over, you can call @code
{
md5
_
init
}
at any time.
@subsection @acronym
{
SHA1
}
SHA1 is a hash function specified by @dfn
{
NIST
}
(The U.S. National Institute
for Standards and Technology. It outputs hash values of 160 bits, or 20
octets. Nettle defines SHA1 in @file
{
<nettle/sha
1
.h>
}
.
for Standards and Technology
)
. It outputs hash values of 160 bits, or 20
octets. Nettle defines SHA1 in @file
{
<nettle/sha.h>
}
.
The functions are analogous to the MD5 ones.
...
...
@@ -408,17 +406,53 @@ Initialize the SHA1 state.
Hash some more data.
@end deftypefun
@deftypefun void sha1
_
final (struct sha1
_
ctx *@var
{
ctx
}
)
Performs final processing that is needed after all input data has been
processed with @code
{
sha1
_
update
}
.
@deftypefun void sha1
_
digest (struct sha1
_
ctx *@var
{
ctx
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
digest
}
)
Performs final processing and extracts the message digest, writing it
to @var
{
digest
}
. @var
{
length
}
may be smaller than
@code
{
SHA1
_
DIGEST
_
SIZE
}
, in which case only the first @var
{
length
}
octets of the digest are written.
This function also resets the context in the same way as
@code
{
sha1
_
init
}
.
@end deftypefun
@deftypefun void sha1
_
digest (struct sha1
_
ctx *@var
{
ctx
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
digest
}
)
Extracts the digest, writing it to @var
{
digest
}
. @var
{
length
}
may be smaller than
@code
{
SHA1
_
DIGEST
_
SIZE
}
, in which case only the first @var
{
length
}
octets
of the digest are written.
@subsection @acronym
{
SHA256
}
SHA256 is another hash function specified by @dfn
{
NIST
}
, intended as a
replacement for @acronym
{
SHA1
}
, generating larger digests. It outputs
hash values of 256 bits, or 32 octets. Nettle defines SHA256 in
@file
{
<nettle/sha.h>
}
.
The functions are analogous to the MD5 ones.
@deftp
{
Context struct
}
{
struct sha256
_
ctx
}
@end deftp
@defvr Constant SHA256
_
DIGEST
_
SIZE
The size of an SHA256 digest, i.e. 20.
@end defvr
@defvr Constant SHA256
_
DATA
_
SIZE
The internal block size of SHA256. Useful for some special constructions,
in particular HMAC-SHA256.
@end defvr
@deftypefun void sha256
_
init (struct sha256
_
ctx *@var
{
ctx
}
)
Initialize the SHA256 state.
@end deftypefun
@deftypefun void sha256
_
update (struct sha256
_
ctx *@var
{
ctx
}
, unsigned @var
{
length
}
, const uint8
_
t *@var
{
data
}
)
Hash some more data.
@end deftypefun
@deftypefun void sha256
_
digest (struct sha256
_
ctx *@var
{
ctx
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
digest
}
)
Performs final processing and extracts the message digest, writing it
to @var
{
digest
}
. @var
{
length
}
may be smaller than
@code
{
SHA256
_
DIGEST
_
SIZE
}
, in which case only the first @var
{
length
}
octets of the digest are written.
This functions doesn't change the state in any way.
This function also resets the context in the same way as
@code
{
sha256
_
init
}
.
@end deftypefun
@node Cipher functions, Cipher Block Chaining, Hash functions, Reference
...
...
@@ -555,7 +589,6 @@ my_arcfour_set_key(struct arcfour_ctx *ctx,
sha1
_
init(
&
hash);
sha1
_
update(
&
hash, length, key);
sha1
_
final(
&
hash);
sha1
_
digest(
&
hash, SHA1
_
DIGEST
_
SIZE, digest);
arcfour
_
set
_
key(ctx, SHA1
_
DIGEST
_
SIZE, digest);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment