xref: /freebsd/sys/crypto/sha1.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1686cdd19SJun-ichiro itojun Hagino /*	$KAME: sha1.h,v 1.5 2000/03/27 04:36:23 sumikawa Exp $	*/
2686cdd19SJun-ichiro itojun Hagino 
351369649SPedro F. Giffuni /*-
451369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
551369649SPedro F. Giffuni  *
66a800098SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
76a800098SYoshinobu Inoue  * All rights reserved.
86a800098SYoshinobu Inoue  *
96a800098SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
106a800098SYoshinobu Inoue  * modification, are permitted provided that the following conditions
116a800098SYoshinobu Inoue  * are met:
126a800098SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
136a800098SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
146a800098SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
156a800098SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
166a800098SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
176a800098SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
186a800098SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
196a800098SYoshinobu Inoue  *    without specific prior written permission.
206a800098SYoshinobu Inoue  *
216a800098SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
226a800098SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236a800098SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
246a800098SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
256a800098SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
266a800098SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
276a800098SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286a800098SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
296a800098SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306a800098SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
316a800098SYoshinobu Inoue  * SUCH DAMAGE.
326a800098SYoshinobu Inoue  */
336a800098SYoshinobu Inoue /*
346a800098SYoshinobu Inoue  * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
356a800098SYoshinobu Inoue  * based on: http://csrc.nist.gov/fips/fip180-1.txt
366a800098SYoshinobu Inoue  * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
376a800098SYoshinobu Inoue  */
386a800098SYoshinobu Inoue 
39571ebf76SConrad Meyer #ifndef _CRYPTO_SHA1_H_
40571ebf76SConrad Meyer #define _CRYPTO_SHA1_H_
416a800098SYoshinobu Inoue 
426a800098SYoshinobu Inoue struct sha1_ctxt {
436a800098SYoshinobu Inoue 	union {
44*d3d79e96SJohn Baldwin 		uint8_t		b8[20];
45*d3d79e96SJohn Baldwin 		uint32_t	b32[5];
466a800098SYoshinobu Inoue 	} h;
476a800098SYoshinobu Inoue 	union {
48*d3d79e96SJohn Baldwin 		uint8_t		b8[8];
49*d3d79e96SJohn Baldwin 		uint64_t	b64[1];
506a800098SYoshinobu Inoue 	} c;
516a800098SYoshinobu Inoue 	union {
52*d3d79e96SJohn Baldwin 		uint8_t		b8[64];
53*d3d79e96SJohn Baldwin 		uint32_t	b32[16];
546a800098SYoshinobu Inoue 	} m;
55*d3d79e96SJohn Baldwin 	uint8_t	count;
566a800098SYoshinobu Inoue };
572155bb23SAllan Jude typedef struct sha1_ctxt SHA1_CTX;
586a800098SYoshinobu Inoue 
59571ebf76SConrad Meyer #define	SHA1_RESULTLEN	(160/8)
60571ebf76SConrad Meyer 
61c4473420SPeter Wemm #ifdef _KERNEL
6214e10f99SAlfred Perlstein extern void sha1_init(struct sha1_ctxt *);
6314e10f99SAlfred Perlstein extern void sha1_pad(struct sha1_ctxt *);
64*d3d79e96SJohn Baldwin extern void sha1_loop(struct sha1_ctxt *, const uint8_t *, size_t);
658254c3c5SAlan Somers extern void sha1_result(struct sha1_ctxt *, char[__min_size(SHA1_RESULTLEN)]);
666a800098SYoshinobu Inoue 
676a800098SYoshinobu Inoue /* compatibilty with other SHA1 source codes */
686a800098SYoshinobu Inoue #define SHA1Init(x)		sha1_init((x))
696a800098SYoshinobu Inoue #define SHA1Update(x, y, z)	sha1_loop((x), (y), (z))
706a800098SYoshinobu Inoue #define SHA1Final(x, y)		sha1_result((y), (x))
718576ccb7SArchie Cobbs #endif /* _KERNEL */
726a800098SYoshinobu Inoue 
73571ebf76SConrad Meyer #endif /*_CRYPTO_SHA1_H_*/
74