annotate src/lib/sha1.h @ 23007:36e01285b5b8

lib: buffer - Improve header comment for buffer_insert() and buffer_delete().
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Mon, 18 Mar 2019 00:52:37 +0100
parents f0e431db73d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* $FreeBSD: src/sys/crypto/sha1.h,v 1.8 2002/03/20 05:13:50 alfred Exp $ */
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 /* $KAME: sha1.h,v 1.5 2000/03/27 04:36:23 sumikawa Exp $ */
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 /*
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 * All rights reserved.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 *
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 * are met:
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 * 1. Redistributions of source code must retain the above copyright
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 * notice, this list of conditions and the following disclaimer.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 * notice, this list of conditions and the following disclaimer in the
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 * documentation and/or other materials provided with the distribution.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 * 3. Neither the name of the project nor the names of its contributors
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 * may be used to endorse or promote products derived from this software
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 * without specific prior written permission.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 *
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 * SUCH DAMAGE.
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 */
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 /*
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 * based on: http://csrc.nist.gov/fips/fip180-1.txt
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 */
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 4778
diff changeset
38 #ifndef SHA1_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 4778
diff changeset
39 #define SHA1_H
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
12307
368fd1cce4d6 liblib: Added a common API for accessing all hash methods.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
41 #include "hash-method.h"
368fd1cce4d6 liblib: Added a common API for accessing all hash methods.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
42
4667
4cd8792b5fcb Let's be nice and work with older libmysqlclient libraries.
Timo Sirainen <tss@iki.fi>
parents: 2628
diff changeset
43 /* libmysqlclient really should try to keep its internal stuff internal so
4cd8792b5fcb Let's be nice and work with older libmysqlclient libraries.
Timo Sirainen <tss@iki.fi>
parents: 2628
diff changeset
44 they won't conflict with the actual programs that are trying to use it.
4cd8792b5fcb Let's be nice and work with older libmysqlclient libraries.
Timo Sirainen <tss@iki.fi>
parents: 2628
diff changeset
45 This particular instance has been fixed in 4.1.18 and 5.0.19, but there
4cd8792b5fcb Let's be nice and work with older libmysqlclient libraries.
Timo Sirainen <tss@iki.fi>
parents: 2628
diff changeset
46 are others. */
4778
055deed128b7 Make it possible to take address of sha1_result() function.
Timo Sirainen <tss@iki.fi>
parents: 4667
diff changeset
47 #define sha1_result sha1_result_libmysqlclient_craps_all_over
4667
4cd8792b5fcb Let's be nice and work with older libmysqlclient libraries.
Timo Sirainen <tss@iki.fi>
parents: 2628
diff changeset
48
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 struct sha1_ctxt {
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 union {
2385
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
51 uint8_t b8[20];
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
52 uint32_t b32[5];
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 } h;
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 union {
2385
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
55 uint8_t b8[8];
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
56 uint64_t b64[1];
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 } c;
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 union {
2385
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
59 uint8_t b8[64];
161a9e818ad6 Changed to use standard uint* types rather than u_int*. Also removed
Timo Sirainen <tss@iki.fi>
parents: 2370
diff changeset
60 uint32_t b32[16];
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 } m;
2386
2f58b0ae7d20 one more u_int..
Timo Sirainen <tss@iki.fi>
parents: 2385
diff changeset
62 uint8_t count;
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 };
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 extern void sha1_init(struct sha1_ctxt *);
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 extern void sha1_pad(struct sha1_ctxt *);
2628
59059ea978b2 Change src from unsigned char* toi void* so callers don't have to do
Timo Sirainen <tss@iki.fi>
parents: 2386
diff changeset
67 extern void sha1_loop(struct sha1_ctxt *, const void *, size_t);
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 extern void sha1_result(struct sha1_ctxt *, void *);
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 /* compatibilty with other SHA1 source codes */
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 typedef struct sha1_ctxt SHA1_CTX;
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 #define SHA1Init(x) sha1_init((x))
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 #define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 #define SHA1Final(x, y) sha1_result((y), (x))
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 #define SHA1_RESULTLEN (160/8)
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
20536
f0e431db73d8 lib: Potential compiling fix.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20328
diff changeset
79 extern void sha1_get_digest(const void *data, size_t size,
f0e431db73d8 lib: Potential compiling fix.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20328
diff changeset
80 unsigned char result[STATIC_ARRAY SHA1_RESULTLEN]);
2370
eda658b1557e Forgot from last dovecotpw commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
12307
368fd1cce4d6 liblib: Added a common API for accessing all hash methods.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
82 extern const struct hash_method hash_method_sha1;
368fd1cce4d6 liblib: Added a common API for accessing all hash methods.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
83
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 4778
diff changeset
84 #endif