| 1 | /*	$NetBSD: sha3.h,v 1.1 2017/11/30 05:47:24 riastradh Exp $	*/ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c) 2015 Taylor R. Campbell |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef	_SHA3_H |
| 30 | #define	_SHA3_H |
| 31 | |
| 32 | #include <sys/types.h> |
| 33 | #include <sys/cdefs.h> |
| 34 | |
| 35 | struct sha3 { |
| 36 | 	uint64_t A[25]; |
| 37 | 	unsigned nb;		/* number of bytes remaining to fill buffer */ |
| 38 | }; |
| 39 | |
| 40 | typedef struct { struct sha3 C224; } SHA3_224_CTX; |
| 41 | typedef struct { struct sha3 C256; } SHA3_256_CTX; |
| 42 | typedef struct { struct sha3 C384; } SHA3_384_CTX; |
| 43 | typedef struct { struct sha3 C512; } SHA3_512_CTX; |
| 44 | typedef struct { struct sha3 C128; } SHAKE128_CTX; |
| 45 | typedef struct { struct sha3 C256; } SHAKE256_CTX; |
| 46 | |
| 47 | #define	SHA3_224_DIGEST_LENGTH	28 |
| 48 | #define	SHA3_256_DIGEST_LENGTH	32 |
| 49 | #define	SHA3_384_DIGEST_LENGTH	48 |
| 50 | #define	SHA3_512_DIGEST_LENGTH	64 |
| 51 | |
| 52 | __BEGIN_DECLS |
| 53 | void	SHA3_224_Init(SHA3_224_CTX *); |
| 54 | void	SHA3_224_Update(SHA3_224_CTX *, const uint8_t *, size_t); |
| 55 | void	SHA3_224_Final(uint8_t[SHA3_224_DIGEST_LENGTH], SHA3_224_CTX *); |
| 56 | |
| 57 | void	SHA3_256_Init(SHA3_256_CTX *); |
| 58 | void	SHA3_256_Update(SHA3_256_CTX *, const uint8_t *, size_t); |
| 59 | void	SHA3_256_Final(uint8_t[SHA3_256_DIGEST_LENGTH], SHA3_256_CTX *); |
| 60 | |
| 61 | void	SHA3_384_Init(SHA3_384_CTX *); |
| 62 | void	SHA3_384_Update(SHA3_384_CTX *, const uint8_t *, size_t); |
| 63 | void	SHA3_384_Final(uint8_t[SHA3_384_DIGEST_LENGTH], SHA3_384_CTX *); |
| 64 | |
| 65 | void	SHA3_512_Init(SHA3_512_CTX *); |
| 66 | void	SHA3_512_Update(SHA3_512_CTX *, const uint8_t *, size_t); |
| 67 | void	SHA3_512_Final(uint8_t[SHA3_512_DIGEST_LENGTH], SHA3_512_CTX *); |
| 68 | |
| 69 | void	SHAKE128_Init(SHAKE128_CTX *); |
| 70 | void	SHAKE128_Update(SHAKE128_CTX *, const uint8_t *, size_t); |
| 71 | void	SHAKE128_Final(uint8_t *, size_t, SHAKE128_CTX *); |
| 72 | |
| 73 | void	SHAKE256_Init(SHAKE256_CTX *); |
| 74 | void	SHAKE256_Update(SHAKE256_CTX *, const uint8_t *, size_t); |
| 75 | void	SHAKE256_Final(uint8_t *, size_t, SHAKE256_CTX *); |
| 76 | |
| 77 | int	SHA3_Selftest(void); |
| 78 | __END_DECLS |
| 79 | |
| 80 | #endif	/* _SHA3_H */ |