xref: /freebsd-src/sys/crypto/sha2/sha512.h (revision c02bc0aa0b22009e4bc209efae99c877167e1161)
17a3f5d11SAllan Jude /*-
27a3f5d11SAllan Jude  * Copyright 2005 Colin Percival
37a3f5d11SAllan Jude  * All rights reserved.
47a3f5d11SAllan Jude  *
57a3f5d11SAllan Jude  * Redistribution and use in source and binary forms, with or without
67a3f5d11SAllan Jude  * modification, are permitted provided that the following conditions
77a3f5d11SAllan Jude  * are met:
87a3f5d11SAllan Jude  * 1. Redistributions of source code must retain the above copyright
97a3f5d11SAllan Jude  *    notice, this list of conditions and the following disclaimer.
107a3f5d11SAllan Jude  * 2. Redistributions in binary form must reproduce the above copyright
117a3f5d11SAllan Jude  *    notice, this list of conditions and the following disclaimer in the
127a3f5d11SAllan Jude  *    documentation and/or other materials provided with the distribution.
137a3f5d11SAllan Jude  *
147a3f5d11SAllan Jude  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
157a3f5d11SAllan Jude  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
167a3f5d11SAllan Jude  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
177a3f5d11SAllan Jude  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
187a3f5d11SAllan Jude  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
197a3f5d11SAllan Jude  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
207a3f5d11SAllan Jude  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
217a3f5d11SAllan Jude  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
227a3f5d11SAllan Jude  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
237a3f5d11SAllan Jude  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
247a3f5d11SAllan Jude  * SUCH DAMAGE.
257a3f5d11SAllan Jude  */
267a3f5d11SAllan Jude 
277a3f5d11SAllan Jude #ifndef _SHA512_H_
287a3f5d11SAllan Jude #define _SHA512_H_
297a3f5d11SAllan Jude 
307a3f5d11SAllan Jude #ifndef _KERNEL
317a3f5d11SAllan Jude #include <sys/types.h>
327a3f5d11SAllan Jude #endif
337a3f5d11SAllan Jude 
347a3f5d11SAllan Jude #define SHA512_BLOCK_LENGTH		128
357a3f5d11SAllan Jude #define SHA512_DIGEST_LENGTH		64
367a3f5d11SAllan Jude #define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
377a3f5d11SAllan Jude 
387a3f5d11SAllan Jude typedef struct SHA512Context {
397a3f5d11SAllan Jude 	uint64_t state[8];
407a3f5d11SAllan Jude 	uint64_t count[2];
417a3f5d11SAllan Jude 	uint8_t buf[SHA512_BLOCK_LENGTH];
427a3f5d11SAllan Jude } SHA512_CTX;
437a3f5d11SAllan Jude 
447a3f5d11SAllan Jude __BEGIN_DECLS
457a3f5d11SAllan Jude 
467a3f5d11SAllan Jude /* Ensure libmd symbols do not clash with libcrypto */
477a3f5d11SAllan Jude #ifndef SHA512_Init
487a3f5d11SAllan Jude #define SHA512_Init		_libmd_SHA512_Init
497a3f5d11SAllan Jude #endif
507a3f5d11SAllan Jude #ifndef SHA512_Update
517a3f5d11SAllan Jude #define SHA512_Update		_libmd_SHA512_Update
527a3f5d11SAllan Jude #endif
537a3f5d11SAllan Jude #ifndef SHA512_Final
547a3f5d11SAllan Jude #define SHA512_Final		_libmd_SHA512_Final
557a3f5d11SAllan Jude #endif
567a3f5d11SAllan Jude #ifndef SHA512_End
577a3f5d11SAllan Jude #define SHA512_End		_libmd_SHA512_End
587a3f5d11SAllan Jude #endif
59de13c242SEd Maste #ifndef SHA512_Fd
60de13c242SEd Maste #define SHA512_Fd		_libmd_SHA512_Fd
61de13c242SEd Maste #endif
62de13c242SEd Maste #ifndef SHA512_FdChunk
63de13c242SEd Maste #define SHA512_FdChunk		_libmd_SHA512_FdChunk
64de13c242SEd Maste #endif
657a3f5d11SAllan Jude #ifndef SHA512_File
667a3f5d11SAllan Jude #define SHA512_File		_libmd_SHA512_File
677a3f5d11SAllan Jude #endif
687a3f5d11SAllan Jude #ifndef SHA512_FileChunk
697a3f5d11SAllan Jude #define SHA512_FileChunk	_libmd_SHA512_FileChunk
707a3f5d11SAllan Jude #endif
717a3f5d11SAllan Jude #ifndef SHA512_Data
727a3f5d11SAllan Jude #define SHA512_Data		_libmd_SHA512_Data
737a3f5d11SAllan Jude #endif
74*c02bc0aaSKyle Evans #ifndef SHA512_Transform
75*c02bc0aaSKyle Evans #define SHA512_Transform		_libmd_SHA512_Transform
76*c02bc0aaSKyle Evans #endif
777a3f5d11SAllan Jude 
787a3f5d11SAllan Jude void	SHA512_Init(SHA512_CTX *);
797a3f5d11SAllan Jude void	SHA512_Update(SHA512_CTX *, const void *, size_t);
808254c3c5SAlan Somers void	SHA512_Final(unsigned char [__min_size(SHA512_DIGEST_LENGTH)],
818254c3c5SAlan Somers     SHA512_CTX *);
827a3f5d11SAllan Jude #ifndef _KERNEL
837a3f5d11SAllan Jude char   *SHA512_End(SHA512_CTX *, char *);
847a3f5d11SAllan Jude char   *SHA512_Data(const void *, unsigned int, char *);
85de13c242SEd Maste char   *SHA512_Fd(int, char *);
86de13c242SEd Maste char   *SHA512_FdChunk(int, char *, off_t, off_t);
877a3f5d11SAllan Jude char   *SHA512_File(const char *, char *);
887a3f5d11SAllan Jude char   *SHA512_FileChunk(const char *, char *, off_t, off_t);
897a3f5d11SAllan Jude #endif
907a3f5d11SAllan Jude 
917a3f5d11SAllan Jude __END_DECLS
927a3f5d11SAllan Jude 
937a3f5d11SAllan Jude #endif /* !_SHA512_H_ */
94