xref: /freebsd/sys/crypto/skein/skein_freebsd.h (revision f39bffc62c1395bde25d152c7f68fdf7cbaab414)
1 /*-
2  * Copyright 2016 Allan Jude
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _SKEIN_FREEBSD_H_
30 #define _SKEIN_FREEBSD_H_
31 
32 #define  SKEIN_256_BLOCK_BYTES ( 8*SKEIN_256_STATE_WORDS)
33 #define  SKEIN_512_BLOCK_BYTES ( 8*SKEIN_512_STATE_WORDS)
34 #define  SKEIN1024_BLOCK_BYTES ( 8*SKEIN1024_STATE_WORDS)
35 
36 #define SKEIN256_BLOCK_LENGTH		SKEIN_256_BLOCK_BYTES
37 #define SKEIN256_DIGEST_LENGTH		32
38 #define SKEIN256_DIGEST_STRING_LENGTH	(SKEIN256_DIGEST_LENGTH * 2 + 1)
39 #define SKEIN512_BLOCK_LENGTH		SKEIN_512_BLOCK_BYTES
40 #define SKEIN512_DIGEST_LENGTH		64
41 #define SKEIN512_DIGEST_STRING_LENGTH	(SKEIN512_DIGEST_LENGTH * 2 + 1)
42 #define SKEIN1024_BLOCK_LENGTH		SKEIN1024_BLOCK_BYTES
43 #define SKEIN1024_DIGEST_LENGTH		128
44 #define SKEIN1024_DIGEST_STRING_LENGTH	(SKEIN1024_DIGEST_LENGTH * 2 + 1)
45 
46 /* Make the context types look like the other hashes on FreeBSD */
47 typedef Skein_256_Ctxt_t    SKEIN256_CTX;
48 typedef Skein_512_Ctxt_t    SKEIN512_CTX;
49 typedef Skein1024_Ctxt_t    SKEIN1024_CTX;
50 
51 /* Make the prototypes look like the other hashes */
52 void SKEIN256_Init  (SKEIN256_CTX *ctx);
53 void SKEIN512_Init  (SKEIN512_CTX *ctx);
54 void SKEIN1024_Init  (SKEIN1024_CTX *ctx);
55 
56 void SKEIN256_Update(SKEIN256_CTX *ctx, const void *in, size_t len);
57 void SKEIN512_Update(SKEIN512_CTX *ctx, const void *in, size_t len);
58 void SKEIN1024_Update(SKEIN1024_CTX *ctx, const void *in, size_t len);
59 
60 void SKEIN256_Final(unsigned char digest[__min_size(SKEIN256_DIGEST_LENGTH)],
61     SKEIN256_CTX *ctx);
62 void SKEIN512_Final(unsigned char digest[__min_size(SKEIN512_DIGEST_LENGTH)],
63     SKEIN512_CTX *ctx);
64 void SKEIN1024_Final(unsigned char digest[__min_size(SKEIN1024_DIGEST_LENGTH)],
65     SKEIN1024_CTX *ctx);
66 
67 #ifndef _KERNEL
68 char   *SKEIN256_End(SKEIN256_CTX *, char *);
69 char   *SKEIN512_End(SKEIN512_CTX *, char *);
70 char   *SKEIN1024_End(SKEIN1024_CTX *, char *);
71 char   *SKEIN256_Data(const void *, unsigned int, char *);
72 char   *SKEIN512_Data(const void *, unsigned int, char *);
73 char   *SKEIN1024_Data(const void *, unsigned int, char *);
74 char   *SKEIN256_Fd(int, char *);
75 char   *SKEIN512_Fd(int, char *);
76 char   *SKEIN1024_Fd(int, char *);
77 char   *SKEIN256_FdChunk(int, char *, off_t, off_t);
78 char   *SKEIN512_FdChunk(int, char *, off_t, off_t);
79 char   *SKEIN1024_FdChunk(int, char *, off_t, off_t);
80 char   *SKEIN256_File(const char *, char *);
81 char   *SKEIN512_File(const char *, char *);
82 char   *SKEIN1024_File(const char *, char *);
83 char   *SKEIN256_FileChunk(const char *, char *, off_t, off_t);
84 char   *SKEIN512_FileChunk(const char *, char *, off_t, off_t);
85 char   *SKEIN1024_FileChunk(const char *, char *, off_t, off_t);
86 #endif
87 
88 #endif	/* ifndef _SKEIN_FREEBSD_H_ */
89