1 /*-
2  * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3  * All rights reserved.
4  *
5  * NBMK Encryption Technologies provides no support of any kind for
6  * this software.  Questions or concerns about it may be addressed to
7  * the members of the relevant open-source community at
8  * <tech-crypto@netbsd.org>.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above
18  *    copyright notice, this list of conditions and the following
19  *    disclaimer in the documentation and/or other materials provided
20  *    with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*****************************************************************************
36  * @(#) n8_pub_hash.h 1.9@(#)
37  *****************************************************************************/
38 
39 /*****************************************************************************/
40 /** @file n8_pub_hash
41  *  @brief Public declarations for hash operations.
42  *
43  * Public header file for hash operations.
44  *
45  *****************************************************************************/
46 
47 /*****************************************************************************
48  * Revision history:
49  * 01/20/04 bac   Fixed __cplusplus beginning directive (Bug 1002).
50  * 04/17/03 brr   Moved hash size constants to this public include file.
51  *                (Bug 866)
52  * 10/24/01 dkm   Moved HMAC defines from hash.h.
53  * 10/15/01 bac   Fixed some signatures to take unsigned ints.
54  * 10/12/01 dkm   Original version.
55  ****************************************************************************/
56 #ifndef N8_PUB_HASH_H
57 #define N8_PUB_HASH_H
58 
59 #ifdef __cplusplus
60 extern "C"
61 {
62 #endif
63 
64 #include "n8_pub_common.h"
65 
66 /*****************************************************************************
67  * #defines
68  *****************************************************************************/
69 
70 #define N8_MAX_HASH_LENGTH (18 * 1024)
71 #define N8_MAX_KEY_LENGTH  (18 * 1024)
72 #define N8_MAX_SSL_KEY_MATERIAL_LENGTH 240
73 #define N8_MAX_TLS_KEY_MATERIAL_LENGTH 224
74 #define N8_MAX_IKE_ITERATIONS 15
75 #define N8_IKE_SKEYID_ITERATIONS 3
76 #define N8_IKE_PRF_ITERATIONS 1
77 #define N8_IKE_ZERO_BYTE_LEN 1
78 
79 #define MD5_HASH_RESULT_LENGTH 16
80 #define SHA1_HASH_RESULT_LENGTH 20
81 #define HMAC_96_HASH_RESULT_LENGTH 12
82 
83 /*****************************************************************************
84  * Structures/type definitions
85  *****************************************************************************/
86 #define N8_HMAC_KEY_LENGTH_ZERO 0
87 #define N8_NO_HMAC_KEY NULL
88 
89 typedef enum
90 {
91    N8_TLS_FINISH = 1,
92    N8_TLS_CERT,
93    N8_SSL_FINISH,
94    N8_SSL_CERT
95 } N8_HashProtocol_t;
96 
97 typedef enum
98 {
99    N8_SERVER   = 1,
100    N8_CLIENT
101 } N8_HashRole_t;
102 
103 typedef struct
104 {
105     uint32_t     keyLength;      /* HMAC key length  */
106     N8_Buffer_t *key_p;          /* ptr to key       */
107     N8_Unit_t    unitID;
108 } N8_HashInfo_t;
109 
110 /*****************************************************************************
111  * Function prototypes
112  *****************************************************************************/
113 N8_Status_t N8_HashInitialize(N8_HashObject_t          *hashObj_p,
114                               const N8_HashAlgorithm_t  alg,
115                               const N8_HashInfo_t      *hashInfo_p,
116                               N8_Event_t               *event_p);
117 
118 
119 N8_Status_t N8_HashPartial(N8_HashObject_t *obj_p,
120                            const N8_Buffer_t *msg_p,
121                            const unsigned int msgLength,
122                            N8_Event_t *event_p);
123 
124 N8_Status_t N8_HashEnd(N8_HashObject_t *obj_p,
125                        N8_Buffer_t *result_p,
126                        N8_Event_t *event_p);
127 
128 N8_Status_t N8_HashClone(const N8_HashObject_t *orig_p,
129                          N8_HashObject_t *clone_p);
130 
131 N8_Status_t N8_HandshakeHashPartial(N8_HashObject_t *md5Obj_p,
132                                     N8_HashObject_t *shaObj_p,
133                                     const N8_Buffer_t *msg_p,
134                                     const unsigned int msgLength,
135                                     N8_Event_t *event_p);
136 
137 N8_Status_t N8_HandshakeHashEnd(N8_HashObject_t *md5Obj_p,
138                                 N8_HashObject_t *sha1Obj_p,
139                                 const N8_HashProtocol_t protocol,
140                                 const N8_Buffer_t *key_p,
141                                 const unsigned int keyLength,
142                                 const N8_HashRole_t role,
143                                 N8_Buffer_t *md5Result_p,
144                                 N8_Buffer_t *sha1Result_p,
145                                 N8_Event_t *event_p);
146 
147 N8_Status_t N8_SSLKeyMaterialHash (N8_HashInfo_t    *obj_p,
148                                   const N8_Buffer_t *random_p,
149                                   const unsigned int outputLength,
150                                   N8_Buffer_t       *keyMaterial_p,
151                                   N8_Event_t        *event_p);
152 
153 N8_Status_t N8_TLSKeyMaterialHash(N8_HashInfo_t     *obj_p,
154                                   const N8_Buffer_t *label_p,
155                                   const unsigned int labelLength,
156                                   const N8_Buffer_t *seed_p,
157                                   const unsigned int seedLength,
158                                   const unsigned int outputLength,
159                                   N8_Buffer_t       *keyMaterial_p,
160                                   N8_Event_t        *event_p);
161 
162 N8_Status_t N8_IKEPrf(const N8_HashAlgorithm_t alg,
163                       const N8_HashInfo_t *hashInfo_p,
164                       const N8_Buffer_t *msg_p,
165                       const uint32_t msgLength,
166                       N8_Buffer_t *result_p,
167                       N8_Event_t *event_p);
168 
169 N8_Status_t N8_IKESKEYIDExpand (const N8_HashAlgorithm_t alg,
170                                 const N8_HashInfo_t *hashInfo_p,
171                                 const N8_Buffer_t *msg_p,
172                                 const uint32_t msgLength,
173                                 N8_Buffer_t *SKEYID_d,
174                                 N8_Buffer_t *SKEYID_a,
175                                 N8_Buffer_t *SKEYID_e,
176                                 N8_Event_t *event_p);
177 
178 N8_Status_t N8_IKEKeyMaterialExpand(const N8_HashAlgorithm_t alg,
179                                     const N8_HashInfo_t *hashInfo_p,
180                                     const N8_Buffer_t *msg_p,
181                                     const uint32_t msgLength,
182                                     N8_Buffer_t *result_p,
183                                     const uint32_t result_len,
184                                     N8_Event_t *event_p);
185 
186 N8_Status_t N8_IKEEncryptKeyExpand(const N8_HashAlgorithm_t alg,
187                                    const N8_HashInfo_t *hashInfo_p,
188                                    N8_Buffer_t *result_p,
189                                    const uint32_t result_len,
190                                    N8_Event_t *event_p);
191 
192 N8_Status_t N8_HashCompleteMessage(N8_HashObject_t   *obj_p,
193                                    const N8_Buffer_t *msg_p,
194                                    const unsigned int msgLength,
195                                    N8_Buffer_t       *result_p,
196                                    N8_Event_t        *event_p);
197 
198 N8_Status_t N8_HashCompleteMessage_uio(N8_HashObject_t *obj_p,
199 			           struct uio          *msg_p,
200                                    const unsigned int   msgLength,
201                                    N8_Buffer_t         *result_p,
202                                    N8_Event_t          *event_p);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif
209 
210 
211