No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / pci / n8 / include_public / n8_pub_pk.h
blob441f501c9377b7be163044484deb94ef48d8f55f
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_pub_pk.h 1.18@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file n8_pub_pk
41 * @brief Public declarations for public key operations.
43 * Public header file for public key operations.
45 *****************************************************************************/
47 /*****************************************************************************
48 * Revision history:
49 * 12/17/03 bac Added prototype for N8_RSAPublicDecrypt.
50 * 05/16/03 brr Moved DH modulus size constants to this public include file.
51 * Fix Bug 902 by allocating a kernel buffer to hold key,
52 * modulus etc. to avoid copies in N8_DHCompute.
53 * 08/01/02 bac Documented 'modulusSize' for N8_DSAKeyObject_t is in bytes.
54 * 05/15/02 mww Moved over prototypes from n8_pk_ops.h to this header
55 * 11/24/01 bac Changed the signature of N8_DSAVerify to add 'const' where
56 * appropriate.
57 * 11/06/01 hml Added structureID field to RSA, DSA and DH key objects.
58 * 10/12/01 dkm Original version.
59 ****************************************************************************/
60 #ifndef N8_PUB_PK_H
61 #define N8_PUB_PK_H
63 #ifdef __cplusplus
64 extern "C"
66 #endif
68 #include "n8_pub_common.h"
70 /* Max size for PKE base operation operands in bytes */
71 #define N8_PK_MAX_SIZE 512
73 /* Modulus size limits for Diffie-Helmann */
74 #define N8_DH_MIN_MODULUS_SIZE 1 /* bytes */
75 #define N8_DH_MAX_MODULUS_SIZE 512 /* bytes */
77 /*****************************************************************************
78 * Structures/type definitions
79 *****************************************************************************/
81 * An RSA key object contains all of the state necessary to perform RSA
82 * operations. It is initialized by calling N8_RSAInitializeKey. The user
83 * should never use or access this structure directly.
85 typedef struct
87 uint32_t p; /* secret prime number. used for
88 * private operations. */
89 uint32_t q; /* secret prime number. used for
90 * private operations. */
91 /* d is the private key */
92 uint32_t dp; /* d mod ((p-1) mod p) */
93 uint32_t dq; /* d mod ((q-1) mod q) */
94 uint32_t R_mod_p; /* R mod p. (private) */
95 uint32_t R_mod_q; /* R mod q. (private) */
96 uint32_t R_mod_n; /* R mod n. (public) */
97 uint32_t n; /* modulus: n=pq */
98 uint32_t u; /* used for Chinese Remainder
99 * Theorem:
100 * u = p^-1 mod q. private
101 * operations only. */
102 uint32_t cp; /* additive inverse of the
103 * multiplicative inverse of the
104 * least significant digit of p, mod
105 * 2^128. used for private
106 * operations. */
107 uint32_t cq; /* same as cp but for q. used for
108 * private operations. */
109 uint32_t cn; /* same as cp but for n. used for
110 * public operations. */
111 uint32_t key; /* this is either e, the public key or
112 * d, the private key, depending upon
113 * the context this object is being
114 * used. */
115 uint32_t paramBlock; /* parameter block in PK format,
116 * suitable for loading directly into
117 * the Big Number Cache (BNC). */
118 N8_KeyType_t keyType;
119 unsigned int publicKeyLength; /* length in bytes of the public key. */
120 unsigned int privateKeyLength; /* length in bytes of the private
121 * key. */
122 unsigned int publicKeyDigits; /* length in digits of the public
123 * key */
124 unsigned int privateKeyDigits; /* length in digits of the private
125 * key */
126 unsigned int pLength; /* length of p in bytes */
127 unsigned int qLength; /* length of q in bytes */
128 unsigned int pDigits; /* length of p in digits */
129 unsigned int qDigits; /* length of q in digits */
130 unsigned int pPad; /* length of p pad for the parameter
131 * block */
132 unsigned int qPad; /* length of q pad for the parameter
133 * block */
134 N8_MemoryHandle_t *kmem_p; /* kernel memory structure for the
135 * allocated space */
136 N8_Unit_t unitID; /* Unit id on which to execute this
137 request */
138 N8_SKSKeyHandle_t SKSKeyHandle; /* contains SKS info */
139 unsigned int structureID; /* Id field for structure */
140 } N8_RSAKeyObject_t;
142 /* DSA */
144 typedef struct
146 N8_Buffer_t *q; /* prime divisor. */
147 N8_Buffer_t *cp; /* additive inverse of the
148 multiplicative inverse of the least
149 significant digit of p, mod 2^128.
150 used for private operations. */
151 N8_Buffer_t *gR_mod_p; /* g*R mod q. (private) */
152 N8_Buffer_t *p; /* prime modulus. */
153 N8_Buffer_t *privateKey; /* private key x */
154 N8_Buffer_t *publicKey; /* public key y */
155 N8_Buffer_t *g; /* generator = h^(p-1)/q mod p, where h
156 * is less than p - 1 and g > 1. */
157 N8_Buffer_t *paramBlock; /* parameter block in PK format,
158 suitable for loading directly into
159 the Big Num Cache (BNC) */
160 N8_KeyType_t keyType;
161 unsigned int modulusLength; /* in bytes */
162 N8_MemoryHandle_t *kmem_p; /* kernel memory structure for the
163 allocated space */
164 N8_Unit_t unitID; /* Unit id on which to execute this
165 request */
166 N8_SKSKeyHandle_t SKSKeyHandle; /* contains SKS info */
167 unsigned int structureID; /* Id field for structure */
168 } N8_DSAKeyObject_t;
170 /* Diffie-Helmann */
172 typedef struct
174 N8_Buffer_t *g; /* group generator. */
175 N8_Buffer_t *p; /* modulus p. */
176 unsigned int modulusLength; /* length in bytes of p and g */
177 N8_Buffer_t *R_mod_p; /* intermediate result necessary for
178 * exponentiation computations. */
179 N8_Buffer_t *gR_mod_p; /* intermediate value of g*R mod p.
180 * only to be used when using the value
181 * for g in this object. */
182 N8_Buffer_t *cp; /* intermediate result necessary for
183 * exponentiation. useful for
184 * operations using this value
185 * of p. */
186 N8_Unit_t unitID; /* Execution unit for request */
187 unsigned int structureID; /* Id field for structure */
188 uint32_t g_a; /* group generator. */
189 uint32_t p_a; /* modulus_p. */
190 uint32_t RmodP_a;
191 uint32_t gRmodP_a;
192 uint32_t cp_a;
193 N8_MemoryHandle_t *kmem_p; /* kernel memory structure for the
194 allocated space */
196 } N8_DH_KeyObject_t;
198 /*****************************************************************************
199 * Function prototypes
200 *****************************************************************************/
201 N8_Status_t N8_RSAInitializeKey(N8_RSAKeyObject_t*,
202 N8_KeyType_t,
203 N8_RSAKeyMaterial_t*,
204 N8_Event_t*);
206 N8_Status_t N8_RSAEncrypt(N8_RSAKeyObject_t *,
207 N8_Buffer_t *,
208 uint32_t,
209 N8_Buffer_t *,
210 N8_Event_t *);
212 N8_Status_t N8_RSADecrypt(N8_RSAKeyObject_t *,
213 N8_Buffer_t *,
214 uint32_t,
215 N8_Buffer_t *,
216 N8_Event_t *);
218 N8_Status_t N8_RSAPublicDecrypt(N8_RSAKeyObject_t *key_p,
219 const N8_RSAKeyMaterial_t *material_p,
220 const N8_Buffer_t *msgIn,
221 uint32_t msgLength,
222 N8_Buffer_t *msgOut,
223 N8_Event_t *event_p);
225 N8_Status_t N8_RSAFreeKey (N8_RSAKeyObject_t *RSAKeyObject_p);
228 /**********************************************************************
229 * DSA function prototypes
230 **********************************************************************/
232 N8_Status_t N8_DSAInitializeKey(N8_DSAKeyObject_t *DSAKeyObject_p,
233 N8_KeyType_t type,
234 N8_DSAKeyMaterial_t *material,
235 N8_Event_t *event_p);
237 N8_Status_t N8_DSASign(N8_DSAKeyObject_t *DSAKeyObject_p,
238 N8_Buffer_t *msgHash_p,
239 N8_Buffer_t *rValue_p,
240 N8_Buffer_t *sValue_p,
241 N8_Event_t *event_p);
243 N8_Status_t N8_DSAVerify(const N8_DSAKeyObject_t *DSAKeyObject_p,
244 const N8_Buffer_t *msgHash_p,
245 const N8_Buffer_t *rValue_p,
246 const N8_Buffer_t *sValue_p,
247 N8_Boolean_t *verify,
248 N8_Event_t *event_p);
250 N8_Status_t N8_DSAFreeKey (N8_DSAKeyObject_t *DSAKeyObject_p);
252 /**********************************************************************
253 * DH function prototypes
254 **********************************************************************/
255 N8_Status_t N8_DHCompute(N8_DH_KeyObject_t *DHKeyObject_p,
256 N8_Buffer_t *GValue,
257 N8_Buffer_t *XValue,
258 N8_Buffer_t *GXValue,
259 N8_Event_t *event_p);
261 N8_Status_t N8_DHInitializeKey(N8_DH_KeyObject_t *DHKeyObject_p,
262 N8_DH_KeyMaterial_t *material,
263 N8_Event_t *event_p);
265 N8_Status_t N8_DHFreeKey(N8_DH_KeyObject_t *key_p);
267 /**********************************************************************
268 * PKE Base Operation function prototypes
269 **********************************************************************/
270 N8_Status_t N8_ModAdd(const N8_SizedBuffer_t *a_p,
271 const N8_SizedBuffer_t *b_p,
272 const N8_SizedBuffer_t *modulus_p,
273 N8_SizedBuffer_t *result_p,
274 const N8_Unit_t unitID,
275 N8_Event_t *event_p);
277 N8_Status_t N8_ModSubtract(const N8_SizedBuffer_t *a_p,
278 const N8_SizedBuffer_t *b_p,
279 const N8_SizedBuffer_t *modulus_p,
280 N8_SizedBuffer_t *result_p,
281 const N8_Unit_t unitID,
282 N8_Event_t *event_p);
284 N8_Status_t N8_ModMultiply(const N8_SizedBuffer_t *a_p,
285 const N8_SizedBuffer_t *b_p,
286 const N8_SizedBuffer_t *modulus_p,
287 N8_SizedBuffer_t *result_p,
288 const N8_Unit_t unitID,
289 N8_Event_t *event_p);
291 N8_Status_t N8_Modulus(const N8_SizedBuffer_t *a_p,
292 const N8_SizedBuffer_t *modulus_p,
293 N8_SizedBuffer_t *result_p,
294 const N8_Unit_t unitID,
295 N8_Event_t *event_p);
297 N8_Status_t N8_ModAdditiveInverse(const N8_SizedBuffer_t *a_p,
298 const N8_SizedBuffer_t *modulus_p,
299 N8_SizedBuffer_t *result_p,
300 const N8_Unit_t unitID,
301 N8_Event_t *event_p);
303 N8_Status_t N8_ModMultiplicativeInverse(const N8_SizedBuffer_t *a_p,
304 const N8_SizedBuffer_t *modulus_p,
305 N8_SizedBuffer_t *result_p,
306 const N8_Unit_t unitID,
307 N8_Event_t *event_p);
309 N8_Status_t N8_ModR(const N8_SizedBuffer_t *modulus_p,
310 N8_SizedBuffer_t *result_p,
311 const N8_Unit_t unitID,
312 N8_Event_t *event_p);
314 N8_Status_t N8_ModExponentiate(const N8_SizedBuffer_t *a_p,
315 const N8_SizedBuffer_t *b_p,
316 const N8_SizedBuffer_t *modulus_p,
317 N8_SizedBuffer_t *result_p,
318 const N8_Unit_t unitID,
319 N8_Event_t *event_p);
320 #ifdef __cplusplus
322 #endif
324 #endif