|
@@ -1,7 +1,11 @@
|
|
|
.TH SECHASH 2
|
|
|
.SH NAME
|
|
|
-md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle, sha1unpickle \- cryptographically secure hashes
|
|
|
+md4, md5, sha1, aes, hmac_md5, hmac_sha1, hmac_aes, md5pickle, md5unpickle, sha1pickle, sha1unpickle \- cryptographically secure hashes
|
|
|
.SH SYNOPSIS
|
|
|
+.de Ti
|
|
|
+.in +0.5i
|
|
|
+.ti -0.5i
|
|
|
+..
|
|
|
.B #include <u.h>
|
|
|
.br
|
|
|
.B #include <libc.h>
|
|
@@ -10,15 +14,13 @@ md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle, sha1unp
|
|
|
.br
|
|
|
.B #include <libsec.h>
|
|
|
.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
-DigestState* md4(uchar *data, ulong dlen, uchar *digest,
|
|
|
-.B
|
|
|
- DigestState *state)
|
|
|
+DigestState* md4(uchar *data, ulong dlen, uchar *digest, DigestState *state)
|
|
|
.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
-DigestState* md5(uchar *data, ulong dlen, uchar *digest,
|
|
|
-.B
|
|
|
- DigestState *state)
|
|
|
+DigestState* md5(uchar *data, ulong dlen, uchar *digest, DigestState *state)
|
|
|
.PP
|
|
|
.B
|
|
|
char* md5pickle(MD5state *state)
|
|
@@ -26,10 +28,9 @@ char* md5pickle(MD5state *state)
|
|
|
.B
|
|
|
MD5state* md5unpickle(char *p);
|
|
|
.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
-DigestState* sha1(uchar *data, ulong dlen, uchar *digest,
|
|
|
-.B
|
|
|
- DigestState *state)
|
|
|
+DigestState* sha1(uchar *data, ulong dlen, uchar *digest, DigestState *state)
|
|
|
.PP
|
|
|
.B
|
|
|
char* sha1pickle(MD5state *state)
|
|
@@ -37,26 +38,27 @@ char* sha1pickle(MD5state *state)
|
|
|
.B
|
|
|
MD5state* sha1unpickle(char *p);
|
|
|
.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
-DigestState* hmac_md5(uchar *data, ulong dlen,
|
|
|
-.br
|
|
|
-.B
|
|
|
- uchar *key, ulong klen,
|
|
|
-.br
|
|
|
+DigestState* aes(uchar *data, ulong dlen, uchar *digest, DigestState *state)
|
|
|
+.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
- uchar *digest, DigestState *state)
|
|
|
+DigestState* hmac_x(uchar *p, ulong len, uchar *key, ulong klen, uchar *digest, DigestState *s, DigestState*(*x)(uchar*, ulong, uchar*, DigestState*), int xlen)
|
|
|
.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
-DigestState* hmac_sha1(uchar *data, ulong dlen,
|
|
|
-.br
|
|
|
+DigestState* hmac_md5(uchar *data, ulong dlen, uchar *key, ulong klen, uchar *digest, DigestState *state)
|
|
|
+.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
- uchar *key, ulong klen,
|
|
|
-.br
|
|
|
+DigestState* hmac_sha1(uchar *data, ulong dlen, uchar *key, ulong klen, uchar *digest, DigestState *state)
|
|
|
+.PP
|
|
|
+.Ti
|
|
|
.B
|
|
|
- uchar *digest, DigestState *state)
|
|
|
+DigestState* hmac_aes(uchar *data, ulong dlen, uchar *key, ulong klen, uchar *digest, DigestState *state)
|
|
|
.SH DESCRIPTION
|
|
|
-.PP
|
|
|
-We support several secure hash functions. The output of the
|
|
|
+We support several secure hash functions. The output of a
|
|
|
hash is called a
|
|
|
.IR digest .
|
|
|
A hash is secure if, given the hashed data and the digest,
|
|
@@ -70,9 +72,11 @@ The routines
|
|
|
.IR md4 ,
|
|
|
.IR md5 ,
|
|
|
.IR sha1 ,
|
|
|
+.IR aes ,
|
|
|
.IR hmac_md5 ,
|
|
|
+.IR hmac_sha1 ,
|
|
|
and
|
|
|
-.I hmac_sha1
|
|
|
+.I hmac_aes
|
|
|
differ only in the length of the resulting digest
|
|
|
and in the security of the hash. Usage for each is the same.
|
|
|
The first call to the routine should have
|
|
@@ -81,33 +85,12 @@ as the
|
|
|
.I state
|
|
|
parameter. This call returns a state which can be used to chain
|
|
|
subsequent calls.
|
|
|
-The last call should have digest non-\fBnil\fR.
|
|
|
+The last call should have digest
|
|
|
+.RL non- nil .
|
|
|
.I Digest
|
|
|
must point to a buffer of at least the size of the digest produced.
|
|
|
This last call will free the state and copy the result into
|
|
|
.IR digest .
|
|
|
-For example, to hash a single buffer using
|
|
|
-.IR md5 :
|
|
|
-.EX
|
|
|
-
|
|
|
- uchar digest[MD5dlen];
|
|
|
-
|
|
|
- md5(data, len, digest, nil);
|
|
|
-.EE
|
|
|
-.PP
|
|
|
-To chain a number of buffers together,
|
|
|
-bounded on each end by some secret:
|
|
|
-.EX
|
|
|
-
|
|
|
- char buf[256];
|
|
|
- uchar digest[MD5dlen];
|
|
|
- DigestState *s;
|
|
|
-
|
|
|
- s = md5("my password", 11, nil, nil);
|
|
|
- while((n = read(fd, buf, 256)) > 0)
|
|
|
- md5(buf, n, nil, s);
|
|
|
- md5("drowssap ym", 11, digest, s);
|
|
|
-.EE
|
|
|
.PP
|
|
|
The constants
|
|
|
.IR MD4dlen ,
|
|
@@ -116,16 +99,23 @@ and
|
|
|
.I SHA1dlen
|
|
|
define the lengths of the digests.
|
|
|
.PP
|
|
|
-.I Hmac_md5
|
|
|
+.IR Hmac_md5 ,
|
|
|
+.IR hmac_sha1 .
|
|
|
and
|
|
|
-.I hmac_sha1
|
|
|
+.I hmac_aes
|
|
|
are used slightly differently. These hash algorithms are keyed and require
|
|
|
a key to be specified on every call.
|
|
|
The digest lengths for these hashes are
|
|
|
-.I MD5dlen
|
|
|
+.IR MD5dlen ,
|
|
|
+.IR SHA1dlen ,
|
|
|
and
|
|
|
-.I SHA1dlen
|
|
|
+.I AESdlen
|
|
|
respectively.
|
|
|
+These routines all call
|
|
|
+.I hmac_x
|
|
|
+internally, but
|
|
|
+.I hmac_x
|
|
|
+is not intended for general use.
|
|
|
.PP
|
|
|
The functions
|
|
|
.I md5pickle
|
|
@@ -139,6 +129,29 @@ unmarshal a pickled digest.
|
|
|
All four routines return a pointer to a newly
|
|
|
.IR malloc (2)'d
|
|
|
object.
|
|
|
+.SH EXAMPLES
|
|
|
+To hash a single buffer using
|
|
|
+.IR md5 :
|
|
|
+.IP
|
|
|
+.EX
|
|
|
+uchar digest[MD5dlen];
|
|
|
+
|
|
|
+md5(data, len, digest, nil);
|
|
|
+.EE
|
|
|
+.PP
|
|
|
+To chain a number of buffers together,
|
|
|
+bounded on each end by some secret:
|
|
|
+.IP
|
|
|
+.EX
|
|
|
+char buf[256];
|
|
|
+uchar digest[MD5dlen];
|
|
|
+DigestState *s;
|
|
|
+
|
|
|
+s = md5("my password", 11, nil, nil);
|
|
|
+while((n = read(fd, buf, 256)) > 0)
|
|
|
+ md5(buf, n, nil, s);
|
|
|
+md5("drowssap ym", 11, digest, s);
|
|
|
+.EE
|
|
|
.SH SOURCE
|
|
|
.B /sys/src/libsec
|
|
|
.SH SEE ALSO
|