QTfrontend/sha1.h
author unc0rr
Mon, 05 Dec 2005 21:46:15 +0000
changeset 24 79c411363184
parent 21 dff476dcaaa3
child 33 d6363050cad0
permissions -rw-r--r--
Add theme objects to land
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     1
/*
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     2
 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     3
 * All rights reserved.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     4
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     5
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     6
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     7
 * Redistribution and use in source and binary forms, with or without
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     8
 * modification, are permitted provided that the following conditions
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     9
 * are met:
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    10
 * 1. Redistributions of source code must retain the above copyright
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    11
 *    notice, this list of conditions and the following disclaimer.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    12
 * 2. Redistributions in binary form must reproduce the above copyright
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    13
 *    notice, this list of conditions and the following disclaimer in the
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    14
 *    documentation and/or other materials provided with the distribution.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    15
 * 3. Neither the name of the project nor the names of its contributors
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    16
 *    may be used to endorse or promote products derived from this software
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    17
 *    without specific prior written permission.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    18
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    22
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    26
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    27
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    28
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    29
 * SUCH DAMAGE.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    30
 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    31
/*
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    32
 * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    33
 * based on: http://csrc.nist.gov/fips/fip180-1.txt
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    34
 * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    35
 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    36
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    37
#include <qglobal.h>
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    38
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    39
#ifdef __cplusplus
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    40
extern "C" {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    41
#endif
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    42
typedef unsigned char caddr_t[20];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    43
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    44
struct sha1_ctxt {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    45
	union {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    46
		quint8	b8[20];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    47
		quint32	b32[5];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    48
	} h;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    49
	union {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    50
		quint8	b8[8];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    51
		quint64	b64[1];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    52
	} c;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    53
	union {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    54
		quint8	b8[64];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    55
		quint32	b32[16];
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    56
	} m;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    57
	quint8	count;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    58
};
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    59
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    60
void sha1_init(struct sha1_ctxt *ctxt);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    61
void sha1_pad(struct sha1_ctxt *ctxt);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    62
extern void sha1_loop(struct sha1_ctxt *ctxt, const quint8 *input, size_t len);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    63
extern void sha1_result(struct sha1_ctxt *ctxt, caddr_t digest0);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    64
#ifdef __cplusplus
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    65
}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    66
#endif
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    67
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    68
#define SHA1Init(x)		sha1_init((x))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    69
#define SHA1Update(x, y, z)	sha1_loop((x), (y), (z))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    70
#define SHA1Final(x, y)		sha1_result((y), (x))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    71