2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
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>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
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_sks.h 1.23@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file SKS_Management_Interface
41 * @brief Header file for the SKS Management Interface library.
43 * This file contains all of the needed SKS Management Interface definitions
46 *****************************************************************************/
48 /*****************************************************************************
50 * 07/03/02 brr Define SKS directory for VxWorks since Windows based
51 * compiler cannot pass the string in correctly.
52 * 05/23/02 brr Moved definition of SKS directory to Makefile.defaults.
53 * 05/02/02 brr Removed all references to the queue structure.
54 * 03/15/02 bac Removed all references to SUPPORTING_BM
55 * 01/30/02 bac Rewrote macros that depend on SUPPORTING_BM to not reference
56 * the behavioral model routines at all.
57 * 01/13/02 brr Revamp to build in 2.1 environment.
58 * 11/13/01 mel Fixed bug #297: register access macros in n8_sks.c will
59 * only work on the behavioral model
60 * - added SKS_READ/WRITE definitions
61 * 11/02/01 bac Moved location of SKS_KEY_NODE_PATH.
62 * 10/12/01 dkm Moved public portion to n8_pub_common.h.
63 * 10/10/01 jdj Fixed bug where SKS busy bits were not being polled
65 * 10/01/01 hml jdj's code review changes, plus some fixes.
66 * 06/14/01 jdj Changed API to reflect new Allocate/Free calls.
67 * 06/04/01 jdj Original version.
68 ****************************************************************************/
73 #include "n8_pub_errors.h"
74 #include "n8_common.h"
77 /* This is defined here for VxWorks since the Windows based compiler */
78 /* will not accept the defintion on the command line in the Makefile */
79 #undef SKS_KEY_NODE_PATH
80 #define SKS_KEY_NODE_PATH "/opt/NetOctave/sks/"
83 #define SKS_PROM_MAX_OFFSET (4096)
84 #define SKS_PROM_MIN_OFFSET (0)
85 #define SKS_WORDS_PER_ALLOC_UNIT (8)
86 #define SKS_ALLOC_UNITS_PER_PROM ( SKS_PROM_MAX_OFFSET / SKS_WORDS_PER_ALLOC_UNIT )
88 #define SKS_INUSE (0x1)
89 #define SKS_FREE (0x0)
91 /* Length for SKS_*_DATA_LENGTH is in SKS words (32 bits each). */
92 #define SKS_RSA_DATA_LENGTH(kl) (( (kl) * 18 ) + 8 )
93 #define SKS_DSA_DATA_LENGTH(kl) (( (kl) * 8 ) + 20 )
95 #define SKS_RSA_P_OFFSET(kl) ( 0 )
96 #define SKS_RSA_Q_OFFSET(kl) ( 2 * (kl))
97 #define SKS_RSA_DP_OFFSET(kl) ( 4 * (kl))
98 #define SKS_RSA_DQ_OFFSET(kl) ( 6 * (kl))
99 #define SKS_RSA_RMODP_OFFSET(kl) ( 8 * (kl))
100 #define SKS_RSA_RMODQ_OFFSET(kl) ( 10 * (kl))
101 #define SKS_RSA_N_OFFSET(kl) ( 12 * (kl))
102 #define SKS_RSA_PINV_OFFSET(kl) ( 16 * (kl))
103 #define SKS_RSA_CP_OFFSET(kl) ( 18 * (kl))
104 #define SKS_RSA_CQ_OFFSET(kl) (( 18 * (kl)) + 4)
106 #define SKS_RSA_P_LENGTH(kl) (( (kl)/2 ) * 4)
107 #define SKS_RSA_Q_LENGTH(kl) (( (kl)/2 ) * 4)
108 #define SKS_RSA_DP_LENGTH(kl) (( (kl)/2 ) * 4)
109 #define SKS_RSA_DQ_LENGTH(kl) (( (kl)/2 ) * 4)
110 #define SKS_RSA_RMODP_LENGTH(kl) (( (kl)/2 ) * 4)
111 #define SKS_RSA_RMODQ_LENGTH(kl) (( (kl)/2 ) * 4)
112 #define SKS_RSA_N_LENGTH(kl) (( kl ) * 4)
113 #define SKS_RSA_PINV_LENGTH(kl) (( (kl)/2 ) * 4)
114 #define SKS_RSA_CP_LENGTH(kl) (( 1 ) * 4)
115 #define SKS_RSA_CQ_LENGTH(kl) (( 1 ) * 4)
118 #define SKS_DSA_P_OFFSET(kl) ( 0 )
119 #define SKS_DSA_GRMODP_OFFSET(kl) ( 4 * (kl))
120 #define SKS_DSA_Q_OFFSET(kl) ( 8 * (kl))
121 #define SKS_DSA_X_OFFSET(kl) (( 8 * (kl)) + 8)
122 #define SKS_DSA_CP_OFFSET(kl) (( 8 * (kl)) + 16)
124 #define SKS_DSA_P_LENGTH(kl) (( kl ) * 4)
125 #define SKS_DSA_GRMODP_LENGTH(kl) (( kl ) * 4)
126 #define SKS_DSA_Q_LENGTH(kl) (( 2 ) * 4)
127 #define SKS_DSA_X_LENGTH(kl) (( 2 ) * 4)
128 #define SKS_DSA_CP_LENGTH(kl) (( 1 ) * 4)
130 #define SKS_MULTIPLE_OF_16_BYTES 16
132 /**********************************************************************
134 **********************************************************************/
135 /** @brief Read control register
137 * @param _NSPinstance_p RO: Pointer to the NSP Structure for this chip.
139 *********************************************************************/
140 #define SKS_READ_CONTROL(_NSPinstance_p) \
141 ( ((NSP2000REGS_t *)(_NSPinstance_p)->NSPregs_p)->pkh_secure_key_storage_control )
143 /**********************************************************************
145 **********************************************************************/
146 /** @brief Read control register
148 * @param _NSPinstance_p RO: Pointer to the NSP Structure for this chip.
150 *********************************************************************/
151 /*#define pk_write_sks_control(A) pksim_write_sks_control(A)*/
152 #define SKS_WRITE_CONTROL(_NSPinstance_p, A) \
153 (((NSP2000REGS_t *)(_NSPinstance_p)->NSPregs_p)->pkh_secure_key_storage_control = (A));
155 /**********************************************************************
157 **********************************************************************/
158 /** @brief Read control register
160 * @param _NSPinstance_p RO: Pointer to the NSP Structure for this chip.
162 *********************************************************************/
163 #define SKS_READ_DATA(_NSPinstance_p) \
164 (((NSP2000REGS_t *)(_NSPinstance_p)->NSPregs_p)->pkh_secure_key_storage_data )
166 /**********************************************************************
168 **********************************************************************/
169 /** @brief Read control register
171 * @param _NSPinstance_p RO: Pointer to the NSP Structure for this chip.
173 *********************************************************************/
174 #define SKS_WRITE_DATA(_NSPinstance_p, A) \
175 (((NSP2000REGS_t *)(_NSPinstance_p)->NSPregs_p)->pkh_secure_key_storage_data = (A));
179 /****************************
180 * Function Prototypes *
181 ****************************/
182 /* These have been moved to n8_sks_proto.h in order to prevent a circular
183 dependency with n8_rsa.h */