Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / n8 / include_private / n8_common.h
blob591deff5c6fa3cda7f5dd0c48a7b1ee48e84dd97
1 /*-
2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3 * All rights reserved.
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:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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.
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.
35 /*****************************************************************************
36 * @(#) n8_common.h 1.50@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file n8_common.h
41 * @brief Common definitions for NSP2000 Interface
43 * Common header file for root definitions for NSP2000 project
45 *****************************************************************************/
47 /*****************************************************************************
48 * Revision history:
49 * 06/06/03 brr Move N8_Hardware_t to n8_pub_common.
50 * 05/15/03 brr Eliminate obsolete typedef's.
51 * 11/24/01 bac Added conditional support for MemTrace.
52 * 11/06/01 hml Added #defines for structure verification and removed
53 * unneeded FPGA define.
54 * 10/30/01 hml Changed NSP_2000 to NSP_2000_HW in N8_Hardware_t.
55 * 10/23/01 dkm Moved N8_ANY_UNIT to n8_pub_common.h.
56 * 10/12/01 dkm Moved public portion to n8_pub_common.h.
57 * 10/01/01 hml Removed RSA and DSA material structs.
58 * 09/21/01 hml Added N8_ANY_UNIT.
59 * 09/14/01 msz Moved some values from n8_packet.h to remove a circular
60 * include dependency.
61 * 09/10/01 bac Changed lengths in material structs to be unsigned ints.
62 * 09/06/01 bac Change enums to start with a value of 1.
63 * 09/04/01 hml Added FPGA_NUM_EA_CONTEXTS.
64 * 08/07/01 hml Added N8 semaphore types.
65 * 07/31/01 bac Removed COPY_IN and COPY_OUT macros as they are defined
66 * elsewhere.
67 * 07/30/01 bac New macros and definitions for dynamic word size selection for
68 * FPGA.
69 * 07/20/01 bac Added definition for enum N8_Hardware_t.
70 * 07/10/01 mel Added modulusLength to N8_DSAKeyMaterial_t;
71 * Deleted privateKeyLength and publicKeyLength.
72 * 07/06/01 mel Added Diffie-Hellman Key Material structure
73 * 06/22/01 bac Changed to N8_DSAKeyMaterial_t from N8_DSA_KeyMaterial_t.
74 * 06/18/01 dws Conditionally #include sys/types.h to get N8_Boolean_t on
75 * Solaris platforms. Conditionally #include limits.h to get
76 * INT_MAX on Solaris platforms.
77 * 06/15/01 hml No longer use copyin and copyout.
78 * 06/13/01 hml Changed N8_MAX to N8_NUM_COMPONENTS in N8_Component_t.
79 * 05/24/01 dws Modified the uint32 conversion macros to deal with less
80 * than ideal arguments. The character pointers are now cast
81 * to unsigned char *.
82 * 05/14/01 dws Added swap_uint32 macro.
83 * 05/08/01 dws Defined uint32_t for BSDi systems and conditionally
84 * #include inttypes.h. Extended the conditional handling of
85 * MIN, MAX and N8_Boolean_t to BDSi.
86 * 05/07/01 dws Made the definition of MIN and MAX conditional.
87 * 05/04/01 bac Corrected N8_Boolean_t conditional compilation.
88 * 05/03/01 bac Added definition for N8_Boolean_t since linux doesn't
89 * define it.
90 * 05/02/01 dws Removed BE2uint32 and uint322BE macros. Added LE_to_uint32
91 * and uint32_to_LE macros to force little endian loads and
92 * stores.
93 * 04/26/01 bac Changed MALLOC and FREE macros to test/set null
94 * pointers. Needs some review and revision.
95 * 04/11/01 bac More standardization.
96 * 04/09/01 bac Added _t to typedefs.
97 * 04/05/01 bac Fixed the comment for key lengths in N8_KeyMaterial.
98 * 04/05/01 bac Turned off debugging. Minor formatting changes.
99 * 04/03/01 bac Removed the CRT value 'u' from key material. As we
100 * have to sort p and q, and u is dependent upon their
101 * ordering, u must be computed at initialization.
102 * 03/29/01 dws Removed RNG-specific definitions.
103 * Removed uint32 - use uint32_t from inttypes.h.
104 ****************************************************************************/
106 #ifndef N8_COMMON_H
107 #define N8_COMMON_H
109 #include "n8_pub_common.h"
110 #include "n8_pub_types.h"
111 #include "n8_OS_intf.h"
113 #ifdef MEMTRACE
114 #include "memtrace.h"
115 #define calloc MemTrace_Calloc
116 #define malloc MemTrace_Malloc
117 #define free MemTrace_Free
118 #endif
120 #if !defined(TRUE) || ((TRUE) != 1)
121 #define TRUE 1
122 #endif
124 #if !defined(FALSE) || ((FALSE) != 0)
125 #define FALSE 0
126 #endif
128 #define N8_SINGLE_CHIP 0
130 #define SIMON_BITS_PER_DIGIT 128
131 #define BM_BITS_PER_DIGIT 128
132 #define FPGA_BITS_PER_DIGIT 64
134 #define SIMON_MULTIPLIER 1
135 #define BM_MULTIPLIER 1
136 #define FPGA_MULTIPLIER 2
138 #define CONTEXT_ENTRY_SIZE 512
140 #define N8_MS_BYTE 0
141 #define N8_LS_BYTE 4
143 /* enums used for structure type checking. These values are intended to
144 be used in the upper half of an id word */
145 typedef enum
147 N8_RSA_STRUCT = 1,
148 N8_DSA_STRUCT = 2,
149 N8_DH_STRUCT = 3,
150 N8_CONTEXT_STRUCT = 4,
151 N8_ENCRYPT_STRUCT = 5,
152 N8_HASH_STRUCT = 6,
153 N8_PACKET_STRUCT = 7
154 } N8_Struct_Types_t;
156 /* version numbers for structure type checking. These values are intended to
157 be used in the lower half of an id word */
158 #define N8_RSA_STRUCT_VER 1
159 #define N8_DSA_STRUCT_VER 1
160 #define N8_DH_STRUCT_VER 1
161 #define N8_CONTEXT_STRUCT_VER 1
162 #define N8_ENCRYPT_STRUCT_VER 1
163 #define N8_HASH_STRUCT_VER 1
164 #define N8_PACKET_STRUCT_VER 1
166 /* id numbers for structure type checking. These values are composed of the
167 structure type in the upper half and the version in the lower half of th
168 word */
169 #define N8_RSA_STRUCT_ID ((N8_RSA_STRUCT << 16) | N8_RSA_STRUCT_VER)
170 #define N8_DSA_STRUCT_ID ((N8_DSA_STRUCT << 16) | N8_DSA_STRUCT_VER)
171 #define N8_DH_STRUCT_ID ((N8_DH_STRUCT << 16) | N8_DH_STRUCT_VER)
172 #define N8_CONTEXT_STRUCT_ID ((N8_CONTEXT_STRUCT << 16) | N8_CONTEXT_STRUCT_VER)
173 #define N8_ENCRYPT_STRUCT_ID ((N8_ENCRYPT_STRUCT << 16) | N8_ENCRYPT_STRUCT_VER)
174 #define N8_HASH_STRUCT_ID ((N8_HASH_STRUCT << 16) | N8_HASH_STRUCT_VER)
175 #define N8_PACKET_STRUCT_ID ((N8_PACKET_STRUCT << 16) | N8_PACKET_STRUCT_VER)
177 /* Macro to force a big endian load of a 32-bit integer in
178 either big or little endian machines */
179 #define BE_to_uint32(c) ((const uint32_t)(*(((const unsigned char *)(c))+3) | \
180 (const uint32_t)*(((const unsigned char *)(c))+2) << 8 | \
181 (const uint32_t)*(((const unsigned char *)(c))+1) << 16 | \
182 (const uint32_t)*(((const unsigned char *)(c)) ) << 24))
184 /* Macro to force a big endian store from a 32-bit integer in
185 either big or little endian machines */
186 #define uint32_to_BE(l,c) \
187 do { \
188 unsigned char *_c = (unsigned char *)(c); \
189 uint32_t _l = (l); \
190 *((_c)+3) = ((_l) ) & 0xff; \
191 *((_c)+2) = ((_l) >> 8) & 0xff; \
192 *((_c)+1) = ((_l) >> 16) & 0xff; \
193 *((_c) ) = ((_l) >> 24) & 0xff; } while (0)
195 /* Macro to force a little endian load of a 32-bit integer in
196 either big or little endian machines */
197 #define LE_to_uint32(c) ((const uint32_t)*(((const unsigned char *)(c)) ) | \
198 (const uint32_t)*(((const unsigned char *)(c))+1) << 8 | \
199 (const uint32_t)*(((const unsigned char *)(c))+2) << 16 | \
200 (const uint32_t)*(((const unsigned char *)(c))+3) << 24)
202 /* Macro to force a little endian store from a 32-bit integer in
203 either big or little endian machines */
204 #define uint32_to_LE(l,c) \
205 do { \
206 unsigned char *_c = (unsigned char *)(c); \
207 uint32_t _l = (l); \
208 *((_c) ) = ((_l) ) & 0xff; \
209 *((_c)+1) = ((_l) >> 8) & 0xff; \
210 *((_c)+2) = ((_l) >> 16) & 0xff; \
211 *((_c)+3) = ((_l) >> 24) & 0xff; } while (0)
213 /* Macro to force a 32-bit byte swap. */
214 #define swap_uint32(l) \
215 ((((l) & 0x000000ff) << 24) | \
216 (((l) & 0x0000ff00) << 8) | \
217 (((l) & 0x00ff0000) >> 8) | \
218 (((l) & 0xff000000) >> 24))
220 /*****************************************************************************
221 * typedef N8_SystemSem_t
222 *****************************************************************************/
223 /** @ingroup n8_semaphore
224 * @typedef N8_SystemSem_t
225 * @brief OS independent handle for system level semaphores.
227 *****************************************************************************/
228 typedef void *N8_SystemSem_t;
230 /*****************************************************************************
231 * typedef N8_SemKey_t
232 *****************************************************************************/
233 /** @ingroup n8_semaphore
234 * @typedef N8_SemKey_t
235 * @brief OS independent key type for finding semaphores (not to be confused
236 * with the handle).
238 *****************************************************************************/
239 typedef void *N8_SemKey_t;
240 #endif /* N8_COMMON_H */