rewrite: update default dumb and smart prefixes
[elinks/elinks-j605.git] / src / util / sha1.h
blob9948a3a7fed8ee7983b1df7291bfc8effa706f93
1 #ifndef EL__UTIL_SHA1_H
2 #define EL__UTIL_SHA1_H
4 /* The contents of this file are subject to the Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is SHA 180-1 Header File
16 * The Initial Developer of the Original Code is Paul Kocher of
17 * Cryptography Research. Portions created by Paul Kocher are
18 * Copyright (C) 1995-9 by Cryptography Research, Inc. All
19 * Rights Reserved.
21 * Contributor(s):
23 * Paul Kocher
25 * Alternatively, the contents of this file may be used under the
26 * terms of the GNU General Public License Version 2 or later (the
27 * "GPL"), in which case the provisions of the GPL are applicable
28 * instead of those above. If you wish to allow use of your
29 * version of this file only under the terms of the GPL and not to
30 * allow others to use your version of this file under the MPL,
31 * indicate your decision by deleting the provisions above and
32 * replace them with the notice and other provisions required by
33 * the GPL. If you do not delete the provisions above, a recipient
34 * may use your version of this file under either the MPL or the
35 * GPL. */
37 /* Optionally SHA1 support can depend on external implementation when linking
38 * against a SSL library that supports it. */
39 #if defined(CONFIG_OWN_LIBC)
40 #define CONFIG_SHA1 1
41 #elif defined(CONFIG_OPENSSL)
42 #include <openssl/sha.h>
43 #else
44 #define CONFIG_SHA1 1
45 #endif
47 #ifndef SHA_DIGEST_LENGTH
48 #define SHA_DIGEST_LENGTH 20
49 #endif
51 #define SHA_HEX_DIGEST_LENGTH (SHA_DIGEST_LENGTH * 2)
53 typedef unsigned char sha1_digest_bin_T[SHA_DIGEST_LENGTH];
54 typedef unsigned char sha1_digest_hex_T[SHA_HEX_DIGEST_LENGTH];
56 struct sha1_context {
57 unsigned int H[5];
58 unsigned int W[80];
59 int lenW;
60 unsigned int sizeHi,sizeLo;
63 void init_sha1(struct sha1_context *context);
64 void update_sha1(struct sha1_context *context, const unsigned char *data, unsigned long length);
65 void done_sha1(struct sha1_context *context, sha1_digest_bin_T digest);
67 unsigned char *
68 digest_sha1(const unsigned char *data, unsigned long length, sha1_digest_bin_T digest);
70 #ifdef CONFIG_SHA1
71 /* Provide compatibility with the OpenSSL interface: */
73 typedef struct sha1_context SHA_CTX;
74 #define SHA1_Init(context) init_sha1(context)
75 #define SHA1_Update(context, data, len) update_sha1(context, data, len)
76 #define SHA1_Final(sha1, context) done_sha1(context, sha1)
77 #define SHA1(data, len, sha1) digest_sha1(data, len, sha1)
79 #endif /* CONFIG_SHA1 */
81 #endif