c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* $FreeBSD: src/sys/crypto/sha1.h,v 1.8 2002/03/20 05:13:50 alfred Exp $ */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* $KAME: sha1.h,v 1.5 2000/03/27 04:36:23 sumikawa Exp $ */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/*
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * All rights reserved.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen *
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * Redistribution and use in source and binary forms, with or without
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * modification, are permitted provided that the following conditions
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * are met:
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 1. Redistributions of source code must retain the above copyright
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * notice, this list of conditions and the following disclaimer.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 2. Redistributions in binary form must reproduce the above copyright
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * notice, this list of conditions and the following disclaimer in the
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * documentation and/or other materials provided with the distribution.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 3. Neither the name of the project nor the names of its contributors
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * may be used to endorse or promote products derived from this software
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * without specific prior written permission.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen *
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * SUCH DAMAGE.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/*
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * based on: http://csrc.nist.gov/fips/fip180-1.txt
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef SHA1_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define SHA1_H
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen#include "hash-method.h"
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen
09caccbfa7a47fbcd428b0618dfdf46d1679390aTimo Sirainen/* libmysqlclient really should try to keep its internal stuff internal so
09caccbfa7a47fbcd428b0618dfdf46d1679390aTimo Sirainen they won't conflict with the actual programs that are trying to use it.
09caccbfa7a47fbcd428b0618dfdf46d1679390aTimo Sirainen This particular instance has been fixed in 4.1.18 and 5.0.19, but there
09caccbfa7a47fbcd428b0618dfdf46d1679390aTimo Sirainen are others. */
7b8ec0341c3b3b1bfcfd20694b0a6ed590ea2c1cTimo Sirainen#define sha1_result sha1_result_libmysqlclient_craps_all_over
09caccbfa7a47fbcd428b0618dfdf46d1679390aTimo Sirainen
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstruct sha1_ctxt {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen union {
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint8_t b8[20];
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint32_t b32[5];
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen } h;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen union {
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint8_t b8[8];
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint64_t b64[1];
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen } c;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen union {
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint8_t b8[64];
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen uint32_t b32[16];
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen } m;
e6837a4f1118565d2ac460dce140705d56f779b3Timo Sirainen uint8_t count;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen};
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenextern void sha1_init(struct sha1_ctxt *);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenextern void sha1_pad(struct sha1_ctxt *);
77a8c99da71844aaf0fa3036960473024d19f471Timo Sirainenextern void sha1_loop(struct sha1_ctxt *, const void *, size_t);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenextern void sha1_result(struct sha1_ctxt *, void *);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
211c638d81d382517d196ad47565e0d85012c927klemens/* compatibility with other SHA1 source codes */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainentypedef struct sha1_ctxt SHA1_CTX;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define SHA1Init(x) sha1_init((x))
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define SHA1Final(x, y) sha1_result((y), (x))
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define SHA1_RESULTLEN (160/8)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
5140f38cb347593aa60a44ab4b0fe60a0b17f808Timo Sirainenextern void sha1_get_digest(const void *data, size_t size,
5140f38cb347593aa60a44ab4b0fe60a0b17f808Timo Sirainen unsigned char result[STATIC_ARRAY SHA1_RESULTLEN]);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainenextern const struct hash_method hash_method_sha1;
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#endif