| RSA BSAFE Cert-C Micro Edition |
The power of PKI for the smallest of devices |
00001 /* $Id: r_pkey.h,v 1.76 2002/12/06 02:08:17 jmckee Exp $ */
00002 /*
00003 * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved.
00004 *
00005 * This work contains proprietary information of RSA Security.
00006 * Distribution is limited to authorized licensees of RSA
00007 * Security. Any unauthorized reproduction, distribution or
00008 * modification of this work is strictly prohibited.
00009 *
00010 */
00011
00012 /** @file r_pkey.h
00013 * This file contains structures, defines and function prototypes
00014 * for public and private key operations.
00015 */
00016
00017 #ifndef HEADER_COMMON_CERT_R_PKEY_H
00018 #define HEADER_COMMON_CERT_R_PKEY_H
00019
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023
00024 #include "r_lib.h"
00025 #include "r_types.h"
00026 #include "pk_ids.h"
00027 #include "r_pkey_err.h"
00028 #include "r_format.h"
00029
00030 #ifndef NO_BIO
00031 #include "bio.h"
00032 #endif /* NO_BIO */
00033 /**
00034 * @defgroup KEYS_GROUP Key Operations
00035 * This section outlines the keys used in cryptographic operations and
00036 * certificate processing. There are two main types of keys:<br>
00037 * <li>Asymmetric (public and private).</li>
00038 * <li>Symmetric.</li>
00039 *
00040 * @{
00041 */
00042 /**
00043 * @}
00044 */
00045
00046 /**
00047 * @defgroup PKEY_GROUP Asymmetric Key Operations
00048 * This section provides information on the functions that perform asymmetric
00049 * (public and private) key processing. It details how to retrieve information
00050 * on identifiers and fields, and how to set print and format options.
00051 * @ingroup KEYS_GROUP
00052 *
00053 * @{
00054 */
00055 /**
00056 * @}
00057 */
00058
00059 /*
00060 * Exported macro constants
00061 */
00062
00063 /**
00064 * @defgroup PKEY_TYPE Types
00065 * This section details the public key types that #R_PKEY can handle.
00066 * @ingroup PKEY_GROUP
00067 * @{
00068 */
00069
00070 /*
00071 * There are definitions for a PKEY type used in R_PKEY_from_binary()
00072 * which are deliberately compatible with the defines used for the
00073 * @ref EVP_PKEY types in older implementations .
00074 *
00075 * That is the values are the same as @ref EVP_PKEY_RSA, @ref EVP_PKEY_DSA and
00076 * @ref EVP_PKEY_DH.
00077 *
00078 */
00079 /**
00080 * Indicates the type used to identify an allocated #R_PKEY. An #R_PKEY
00081 * may contain either a public or private key for the nominated type of key
00082 * allocated.
00083 */
00084 typedef int R_PKEY_TYPE;
00085 /**
00086 * Indicates that the <tt>PKEY</tt> type is unknown.
00087 */
00088 #define R_PKEY_TYPE_UNKNOWN -1
00089 /**
00090 * Indicates that the <tt>PKEY</tt> type is RSA.
00091 */
00092 #define R_PKEY_TYPE_RSA 6
00093 /**
00094 * Indicates that the <tt>PKEY</tt> type is Diffie-Hellman.
00095 */
00096 #define R_PKEY_TYPE_DH 28
00097 /**
00098 * Indicates that the <tt>PKEY</tt> type is Digital Signature Algorithm (DSA).
00099 */
00100 #define R_PKEY_TYPE_DSA 116
00101 /**
00102 * Indicates that the <tt>PKEY</tt> type is Elliptic Curve Cryptography (ECC).
00103 */
00104 #define R_PKEY_TYPE_ECC 178
00105
00106 /**
00107 * @}
00108 */
00109
00110 /**
00111 * @defgroup PKEY_FLAGS Flags
00112 * This section outlines the flags associated with a public key structure.
00113 * @ingroup PKEY_GROUP
00114 * @{
00115 */
00116
00117 /*
00118 * Defines for flags used in the _from_binary calls.
00119 *
00120 * NOTE: the flag values for both R_CERT and R_PKEY are the same.
00121 *
00122 */
00123 /**
00124 * Indicates default data referencing.
00125 */
00126 #define R_PKEY_FL_DEFAULT 0x0000
00127 /**
00128 * Indicates to copy data.
00129 */
00130 #define R_PKEY_FL_COPY_DATA 0x0000
00131 /**
00132 * Indicates to use data by reference.
00133 */
00134 #define R_PKEY_FL_BY_REFERENCE 0x0001
00135
00136 /**
00137 * @}
00138 */
00139
00140 /* Indicates that the <tt>PKEY</tt> is binary encoded. */
00141 #define R_PKEY_FORMAT_BINARY R_FORMAT_BINARY
00142
00143 /* Indicates that the <tt>PKEY</tt> is in text format. */
00144 #define R_PKEY_FORMAT_TEXT R_FORMAT_TEXT
00145
00146 /* Indicates that the <tt>PKEY</tt> is Privacy Enhanced Mail (PEM) encoded. */
00147 #define R_PKEY_FORMAT_PEM R_FORMAT_PEM
00148
00149 /* Indicates text output format. */
00150 #define R_PKEY_PRINT_FORMAT_TEXT R_FORMAT_TEXT
00151
00152 /* Indicates C code function format. */
00153 #define R_PKEY_PRINT_FORMAT_CODE_BINARY R_FORMAT_CODE_BINARY
00154
00155 /* Indicates C code fields format. */
00156 #define R_PKEY_PRINT_FORMAT_CODE_FIELDS R_FORMAT_CODE_FIELDS
00157
00158 /* Indicates C code data format. */
00159 #define R_PKEY_PRINT_FORMAT_CODE_HEX R_FORMAT_CODE_HEX
00160
00161 /* Indicates plain hexadecimal Bytes format. */
00162 #define R_PKEY_PRINT_FORMAT_HEX R_FORMAT_HEX
00163
00164 /* Backwards compatibility macro for R_PKEY_FORMAT_from_string */
00165 #define R_PKEY_FORMAT_from_string(str, fmt) \
00166 R_FORMAT_from_string((str), (fmt))
00167
00168 /* Backwards compatibility macro for R_PKEY_FORMAT_to_string */
00169 #define R_PKEY_FORMAT_to_string(fmt, max, str) \
00170 R_FORMAT_to_string((fmt), (max), (str))
00171
00172 #ifndef NO_PEM
00173 /**
00174 * @defgroup PKEY_PEM Privacy Enhanced Mail Cipher Strings
00175 * This section details the strings recognized by #R_PKEY as ciphers to use
00176 * when encrypting a Privacy Enhanced Mail (PEM) file.
00177 * @ingroup PKEY_GROUP
00178 * @{
00179 */
00180
00181 /* supported PEM cipher strings for encrypted keys */
00182 /**
00183 * Indicates a Privacy Enhanced Mail (PEM) cipher in Data Encryption Standard
00184 * Cipher Block Chaining (DES CBC) mode.
00185 */
00186 #define R_PKEY_PEM_CIPHER_DES "DES-CBC"
00187 /**
00188 * Indicates a Privacy Enhanced Mail (PEM) cipher in Triple Data Encryption
00189 * Standard Cipher Block Chaining (DES CBC) mode.
00190 */
00191 #define R_PKEY_PEM_CIPHER_DES_EDE "DES-EDE3-CBC"
00192
00193 /**
00194 * @}
00195 */
00196 #endif /* NO_PEM */
00197
00198 /**
00199 * @defgroup PKEY_FIELD Fields
00200 * This section outlines the fields of a public key recognized by #R_PKEY.
00201 * @ingroup PKEY_GROUP
00202 * @{
00203 */
00204
00205 /* ID values for R_PKEY_get_field - defines come from pk_ids.h */
00206 /**
00207 * Indicates that the data is the modulus (<tt>n</tt>) of the RSA key. The
00208 * modulus is the product of the primes.
00209 */
00210 #define R_PKEY_FIELD_ID_RSA_MOD PK_RSA_N
00211 /**
00212 * Indicates that the data is the public exponent (<tt>e</tt>) of the RSA key.
00213 * The public exponent is often <tt>65537 (0x10001)</tt> which allows fast
00214 * exponentiation calculating.
00215 */
00216 #define R_PKEY_FIELD_ID_RSA_EXP PK_RSA_E
00217 /** Indicates that the data is the private exponent (<tt>d</tt>) of the RSA
00218 * key. The private exponent is the inverse of the public exponent
00219 * (<tt>e.d=1 mod (p-1)(q-1)...</tt>).
00220 */
00221 #define R_PKEY_FIELD_ID_RSA_PRIV_EXP PK_RSA_D
00222 /** Indicates that the data is the <tt>nth</tt> prime of the RSA key. */
00223 #define R_PKEY_FIELD_ID_RSA_PRIME_N(n) PK_RSA_PRIME(n)
00224 /** Indicates that the data is the <tt>nth</tt> exponent calculation of the
00225 * RSA key. The calculation is the private exponent <tt>mod prime - 1</tt>
00226 * and is a pre-calculation used in a Chinese Remainder Theorem
00227 * implementation of the private key operations.
00228 */
00229 #define R_PKEY_FIELD_ID_RSA_EXP_N(n) PK_RSA_EXP(n)
00230 /** Indicates that the data is the <tt>nth</tt> inverse calculation of the
00231 * RSA key. The calculation is the inverse of the previous prime mod this
00232 * prime (<tt>inv(q) mod p</tt>) and is a pre-calculation used in a Chinese
00233 * Remainder Theorem implementation of the private key operations.
00234 */
00235 #define R_PKEY_FIELD_ID_RSA_INV_N(n) PK_RSA_INV(n)
00236 /** Indicates that the data is the first prime (<tt>q</tt>) of the RSA key.
00237 */
00238 #define R_PKEY_FIELD_ID_RSA_Q PK_RSA_Q
00239 /** Indicates that the data is the first exponent calculation of the RSA key.
00240 * The calculation is the private exponent <tt>mod (q-1)</tt> and is a
00241 * pre-calculation used in a Chinese Remainder Theorem implementation
00242 * of the private key operations.
00243 */
00244 #define R_PKEY_FIELD_ID_RSA_DMQ1 PK_RSA_DMQ1
00245 /** Indicates that the data is the second prime (<tt>p</tt>) of the RSA key.
00246 */
00247 #define R_PKEY_FIELD_ID_RSA_P PK_RSA_P
00248 /** Indicates that the data is the second exponent calculation of the RSA key.
00249 * The calculation is the private exponent <tt>mod (p-1)</tt> and is a
00250 * pre-calculation used in a Chinese Remainder Theorem implementation
00251 * of the private key operations.
00252 */
00253 #define R_PKEY_FIELD_ID_RSA_DMP1 PK_RSA_DMP1
00254 /** Indicates that the data is the second inverse calculation of the RSA key.
00255 * The calculation is the inverse of the previous prime <tt>mod</tt> this
00256 * prime (<tt>inv(q) mod p</tt>) and is a pre-calculation used in a
00257 * Chinese Remainder Theorem implementation of the private key operations.
00258 */
00259 #define R_PKEY_FIELD_ID_RSA_IQMP PK_RSA_IQMP
00260 /**
00261 * Indicates that the data is the prime parameter of the Diffie-Hellman key.
00262 * The prime value identifies the Galois field (<tt>p=jq+1</tt>).
00263 */
00264 #define R_PKEY_FIELD_ID_DH_PRIME PK_DH_PRIME
00265 /**
00266 * Indicates that the data is the public key value of the Diffie-Hellman key.
00267 * The public key is calculated by raising the generator to a
00268 * random value <tt>mod p (y=g^x mod p)</tt>.
00269 */
00270 #define R_PKEY_FIELD_ID_DH_GENERATOR PK_DH_GENERATOR
00271 /**
00272 * Indicates that the data is the public key value of the Diffie-Hellman key.
00273 * The public key is calculated by raising the generator to a random value
00274 * <tt>mod p (y=g^x mod p)</tt>.
00275 */
00276 #define R_PKEY_FIELD_ID_DH_PUB_KEY PK_DH_PUB_KEY
00277 /**
00278 * Indicates that the data is the prime modulus parameter of the Digital
00279 * Signature Algorithm (DSA) key. The prime modulus identifier between
00280 * <tt>2^(L-1)</tt> and <tt>2^L</tt> for <tt>L</tt> in the range of
00281 * 512-1024 and is a multiple of 64.
00282 */
00283 #define R_PKEY_FIELD_ID_DSA_PRIME PK_DSA_P
00284 /**
00285 * Indicates that the data is the sub-prime/prime divisor parameter of the
00286 * Digital Signature Algorithm (DSA) key. The sub-prime is a prime divisor
00287 * of the prime minus one between <tt>2^159</tt> and <tt>2^160</tt>.
00288 */
00289 #define R_PKEY_FIELD_ID_DSA_SUBPRIME PK_DSA_Q
00290 /**
00291 * Indicates that the data is the base/generator parameter of the Digital
00292 * Signature Algorithm (DSA) key. The base/generator is used as the
00293 * exponential base for DSA calculations <tt>(g = h^[(p-1)/q])</tt>.
00294 */
00295 #define R_PKEY_FIELD_ID_DSA_BASE PK_DSA_G
00296 /**
00297 * Indicates that the data is the public key value (<tt>y</tt>) of the Digital
00298 * Signature Algorithm (DSA) key. The public key is the base/generator value
00299 * raised to the private key part <tt>mod p (y=g^x mod p)</tt>.
00300 */
00301 #define R_PKEY_FIELD_ID_DSA_PUB_KEY PK_DSA_PUB_KEY
00302 /**
00303 * Indicates that the data is the private key value (<tt>x</tt>) of the Digital
00304 * Signature Algorithm (DSA) key. The private key is the exponent to which the
00305 * base generator is raised to obtain the public key part
00306 * <tt>(y=g^x mod p)</tt>.
00307 */
00308 #define R_PKEY_FIELD_ID_DSA_PRIV_KEY PK_DSA_PRIV_KEY
00309
00310
00311 #define R_PKEY_FIELD_ID_ECC_OID PK_ECC_OID
00312 #define R_PKEY_FIELD_ID_ECC_PARAMS PK_ECC_PARAMS
00313 #define R_PKEY_FIELD_ID_ECC_PUB_KEY PK_ECC_PUB_KEY
00314 /**
00315 * @}
00316 */
00317 /**
00318 * @defgroup PKEY_INFO Information Identifiers
00319 * This section lists the identifiers used to set and/or retrieve information
00320 * from an #R_PKEY.
00321 * The following table details the data types to pass into <i>param</i> when
00322 * calling R_PKEY_get_info().
00323 * @br
00324 * <table><tr>
00325 * <td><b>Identifier</b></td>
00326 * <td><b>Param Data Type</b></td>
00327 * </tr><tr>
00328 * <td>#R_PKEY_INFO_ID_RSA_MOD</td>
00329 * <td>#R_ITEM *</td>
00330 * </tr><tr>
00331 * <td>#R_PKEY_INFO_ID_RSA_EXP</td>
00332 * <td>#R_ITEM *</td>
00333 * </tr><tr>
00334 * <td>#R_PKEY_INFO_ID_RSA_PRIV_EXP</td>
00335 * <td>#R_ITEM *</td>
00336 * </tr><tr>
00337 * <td>#R_PKEY_INFO_ID_RSA_PRIME_N</td>
00338 * <td>#R_ITEM *</td>
00339 * </tr><tr>
00340 * <td>#R_PKEY_INFO_ID_RSA_EXP_N</td>
00341 * <td>#R_ITEM *</td>
00342 * </tr><tr>
00343 * <td>#R_PKEY_INFO_ID_RSA_INV_N</td>
00344 * <td>#R_ITEM *</td>
00345 * </tr><tr>
00346 * <td>#R_PKEY_INFO_ID_RSA_Q</td>
00347 * <td>#R_ITEM *</td>
00348 * </tr><tr>
00349 * <td>#R_PKEY_INFO_ID_RSA_DMQ1</td>
00350 * <td>#R_ITEM *</td>
00351 * </tr><tr>
00352 * <td>#R_PKEY_INFO_ID_RSA_P</td>
00353 * <td>#R_ITEM *</td>
00354 * </tr><tr>
00355 * <td>#R_PKEY_INFO_ID_RSA_DMP1</td>
00356 * <td>#R_ITEM *</td>
00357 * </tr><tr>
00358 * <td>#R_PKEY_INFO_ID_RSA_IQMP</td>
00359 * <td>#R_ITEM *</td>
00360 * </tr><tr>
00361 * <td>#R_PKEY_INFO_ID_DH_PRIME</td>
00362 * <td>#R_ITEM *</td>
00363 * </tr><tr>
00364 * <td>#R_PKEY_INFO_ID_DH_GENERATOR</td>
00365 * <td>#R_ITEM *</td>
00366 * </tr><tr>
00367 * <td>#R_PKEY_INFO_ID_DH_PUB_KEY</td>
00368 * <td>#R_ITEM *</td>
00369 * </tr><tr>
00370 * <td>#R_PKEY_INFO_ID_DSA_PRIME</td>
00371 * <td>#R_ITEM *</td>
00372 * </tr><tr>
00373 * <td>#R_PKEY_INFO_ID_DSA_SUBPRIME</td>
00374 * <td>#R_ITEM *</td>
00375 * </tr><tr>
00376 * <td>#R_PKEY_INFO_ID_DSA_BASE</td>
00377 * <td>#R_ITEM *</td>
00378 * </tr><tr>
00379 * <td>#R_PKEY_INFO_ID_DSA_PUB_KEY</td>
00380 * <td>#R_ITEM *</td>
00381 * </tr><tr>
00382 * <td>#R_PKEY_INFO_ID_DSA_PRIV_KEY</td>
00383 * <td>#R_ITEM *</td>
00384 * </tr><tr>
00385 * <td>#R_PKEY_INFO_ID_R_PKEY_CTX</td>
00386 * <td>#R_PKEY_CTX **</td>
00387 * </tr><tr>
00388 * <td>#R_PKEY_INFO_ID_R_EITEMS</td>
00389 * <td>#R_EITEMS **</td>
00390 * </tr><tr>
00391 * <td>#R_PKEY_INFO_ID_FLAG</td>
00392 * <td><tt>int *</tt></td>
00393 * </tr><tr>
00394 * <td>#R_PKEY_INFO_ID_DATA</td>
00395 * <td><tt>void **</tt></td>
00396 * </tr><tr>
00397 * <td>#R_PKEY_INFO_ID_REFERENCE</td>
00398 * <td><tt>int *</tt></td>
00399 * </tr><tr>
00400 * <td>#R_PKEY_INFO_ID_TYPE</td>
00401 * <td>#R_PKEY_TYPE *</td>
00402 * </tr><tr>
00403 * <td>#R_PKEY_INFO_ID_NUM_BITS</td>
00404 * <td><tt>int *</tt></td>
00405 * </tr><tr>
00406 * <td>#R_PKEY_INFO_ID_NUM_PRIMES</td>
00407 * <td><tt>int *</tt></td>
00408 * </tr><tr>
00409 * </tr></table>
00410 * @br
00411 *
00412 * The following table details the data types to pass into <i>param</i> when
00413 * calling R_PKEY_set_info().
00414 * @br
00415 * <table><tr>
00416 * <td><b>Identifier</b></td>
00417 * <td><b>Param Data Type</b></td>
00418 * </tr><tr>
00419 * <td>#R_PKEY_INFO_ID_RSA_MOD</td>
00420 * <td>#R_ITEM *</td>
00421 * </tr><tr>
00422 * <td>#R_PKEY_INFO_ID_RSA_EXP</td>
00423 * <td>#R_ITEM *</td>
00424 * </tr><tr>
00425 * <td>#R_PKEY_INFO_ID_RSA_PRIV_EXP</td>
00426 * <td>#R_ITEM *</td>
00427 * </tr><tr>
00428 * <td>#R_PKEY_INFO_ID_RSA_PRIME_N</td>
00429 * <td>#R_ITEM *</td>
00430 * </tr><tr>
00431 * <td>#R_PKEY_INFO_ID_RSA_EXP_N</td>
00432 * <td>#R_ITEM *</td>
00433 * </tr><tr>
00434 * <td>#R_PKEY_INFO_ID_RSA_INV_N</td>
00435 * <td>#R_ITEM *</td>
00436 * </tr><tr>
00437 * <td>#R_PKEY_INFO_ID_RSA_Q</td>
00438 * <td>#R_ITEM *</td>
00439 * </tr><tr>
00440 * <td>#R_PKEY_INFO_ID_RSA_DMQ1</td>
00441 * <td>#R_ITEM *</td>
00442 * </tr><tr>
00443 * <td>#R_PKEY_INFO_ID_RSA_P</td>
00444 * <td>#R_ITEM *</td>
00445 * </tr><tr>
00446 * <td>#R_PKEY_INFO_ID_RSA_DMP1</td>
00447 * <td>#R_ITEM *</td>
00448 * </tr><tr>
00449 * <td>#R_PKEY_INFO_ID_RSA_IQMP</td>
00450 * <td>#R_ITEM *</td>
00451 * </tr><tr>
00452 * <td>#R_PKEY_INFO_ID_DH_PRIME</td>
00453 * <td>#R_ITEM *</td>
00454 * </tr><tr>
00455 * <td>#R_PKEY_INFO_ID_DH_GENERATOR</td>
00456 * <td>#R_ITEM *</td>
00457 * </tr><tr>
00458 * <td>#R_PKEY_INFO_ID_DH_PUB_KEY</td>
00459 * <td>#R_ITEM *</td>
00460 * </tr><tr>
00461 * <td>#R_PKEY_INFO_ID_DSA_PRIME</td>
00462 * <td>#R_ITEM *</td>
00463 * </tr><tr>
00464 * <td>#R_PKEY_INFO_ID_DSA_SUBPRIME</td>
00465 * <td>#R_ITEM *</td>
00466 * </tr><tr>
00467 * <td>#R_PKEY_INFO_ID_DSA_BASE</td>
00468 * <td>#R_ITEM *</td>
00469 * </tr><tr>
00470 * <td>#R_PKEY_INFO_ID_DSA_PUB_KEY</td>
00471 * <td>#R_ITEM *</td>
00472 * </tr><tr>
00473 * <td>#R_PKEY_INFO_ID_DSA_PRIV_KEY</td>
00474 * <td>#R_ITEM *</td>
00475 * </tr><tr>
00476 * <td>#R_PKEY_INFO_ID_NUM_PRIMES</td>
00477 * <td><tt>int *</tt></td>
00478 * </tr><tr>
00479 * </tr></table>
00480 * @br
00481 * @ingroup PKEY_GROUP
00482 * @{
00483 */
00484
00485 #define R_PKEY_INFO_ID_BASE 2000
00486 /**
00487 * This identifier is used for the retrieval of the RSA modulus associated
00488 * with the #R_PKEY. To retrieve this value the parameter reference should be
00489 * passed in as cast #R_ITEM *.
00490 *
00491 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_MOD.
00492 */
00493 #define R_PKEY_INFO_ID_RSA_MOD R_PKEY_FIELD_ID_RSA_MOD
00494 /**
00495 * This identifier is used for the retrieval of the RSA exponent associated
00496 * with the #R_PKEY. To retrieve this value the parameter reference should be
00497 * passed in as cast #R_ITEM *.
00498 *
00499 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_EXP.
00500 */
00501 #define R_PKEY_INFO_ID_RSA_EXP R_PKEY_FIELD_ID_RSA_EXP
00502 /**
00503 * This identifier is used for the retrieval of the RSA private exponent
00504 * associated with the #R_PKEY. To retrieve this value the parameter reference
00505 * should be passed in as cast #R_ITEM *.
00506 *
00507 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_PRIV_EXP.
00508 */
00509 #define R_PKEY_INFO_ID_RSA_PRIV_EXP R_PKEY_FIELD_ID_RSA_PRIV_EXP
00510 /**
00511 * This identifier is used for the retrieval of the <tt>nth</tt> RSA prime
00512 * associated with the #R_PKEY. To retrieve this value the parameter
00513 * reference should be passed in as cast #R_ITEM *.
00514 *
00515 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_PRIME_N.
00516 */
00517 #define R_PKEY_INFO_ID_RSA_PRIME_N(n) R_PKEY_FIELD_ID_RSA_PRIME_N(n)
00518 /**
00519 * This identifier is used for the retrieval of the <tt>nth</tt> RSA exponent
00520 * associated with the #R_PKEY. To retrieve this value the parameter
00521 * reference should be passed in as cast #R_ITEM *.
00522 *
00523 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_EXP_N.
00524 */
00525 #define R_PKEY_INFO_ID_RSA_EXP_N(n) R_PKEY_FIELD_ID_RSA_EXP_N(n)
00526 /**
00527 * This identifier is used for the retrieval of the associated RSA inverse
00528 * associated with the #R_PKEY. To retrieve this value the parameter
00529 * reference should be passed in as cast #R_ITEM *.
00530 *
00531 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_INV_N.
00532 */
00533 #define R_PKEY_INFO_ID_RSA_INV_N(n) R_PKEY_FIELD_ID_RSA_INV_N(n)
00534 /**
00535 * This identifier is used for the retrieval of the first RSA prime associated
00536 * with the #R_PKEY. To retrieve this value the parameter reference should
00537 * be passed in as cast #R_ITEM *.
00538 *
00539 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_Q.
00540 */
00541 #define R_PKEY_INFO_ID_RSA_Q R_PKEY_FIELD_ID_RSA_Q
00542 /**
00543 * This identifier is used for the retrieval of the first RSA exponent
00544 * associated with the #R_PKEY. To retrieve this value the parameter reference
00545 * should be passed in as cast #R_ITEM *.
00546 *
00547 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_DMQ1.
00548 */
00549 #define R_PKEY_INFO_ID_RSA_DMQ1 R_PKEY_FIELD_ID_RSA_DMQ1
00550 /**
00551 * This identifier is used for the retrieval of the second RSA prime associated
00552 * with the #R_PKEY. To retrieve this value the parameter reference should
00553 * be passed in as cast #R_ITEM *.
00554 *
00555 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_P.
00556 */
00557 #define R_PKEY_INFO_ID_RSA_P R_PKEY_FIELD_ID_RSA_P
00558 /**
00559 * This identifier is used for the retrieval of the second RSA exponent
00560 * associated with the #R_PKEY. To retrieve this value the parameter reference
00561 * should be passed in as cast #R_ITEM *.
00562 *
00563 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_DMP1.
00564 */
00565 #define R_PKEY_INFO_ID_RSA_DMP1 R_PKEY_FIELD_ID_RSA_DMP1
00566 /**
00567 * This identifier is used for the retrieval of the second RSA inverse
00568 * associated with the #R_PKEY. To retrieve this value the parameter reference
00569 * should be passed in as cast #R_ITEM *.
00570 *
00571 * @see R_PKEY_get_info(), R_PKEY_set_info() and #R_PKEY_FIELD_ID_RSA_IQMP.
00572 */
00573 #define R_PKEY_INFO_ID_RSA_IQMP R_PKEY_FIELD_ID_RSA_IQMP
00574 /**
00575 * This identifier is used for the retrieval of the Diffie-Hellman prime
00576 * value associated with the #R_PKEY. To retrieve this value the parameter
00577 * reference should be passed in as cast #R_ITEM *.
00578 *
00579 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00580 * #R_PKEY_FIELD_ID_DH_PRIME.
00581 */
00582 #define R_PKEY_INFO_ID_DH_PRIME R_PKEY_FIELD_ID_DH_PRIME
00583 /**
00584 * This identifier is used for the retrieval of the Diffie-Hellman parameter
00585 * value associated with the #R_PKEY. To retrieve this value the parameter
00586 * reference should be passed in as cast #R_ITEM *.
00587 *
00588 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00589 * #R_PKEY_FIELD_ID_DH_GENERATOR.
00590 */
00591 #define R_PKEY_INFO_ID_DH_GENERATOR R_PKEY_FIELD_ID_DH_GENERATOR
00592 /**
00593 * This identifier is used for the retrieval of the Diffie-Hellman public
00594 * key associated with the #R_PKEY. To retrieve this value the parameter
00595 * reference should be passed in as cast #R_ITEM *.
00596 *
00597 * @see R_PKEY_get_info(), R_PKEY_set_info()
00598 * and #R_PKEY_FIELD_ID_DH_PUB_KEY.
00599 */
00600 #define R_PKEY_INFO_ID_DH_PUB_KEY R_PKEY_FIELD_ID_DH_PUB_KEY
00601 /**
00602 * This identifier is used for the retrieval of the Digital Signature
00603 * Algorithm (DSA) prime associated with the #R_PKEY. To retrieve this
00604 * value the parameter reference should be passed in as cast #R_ITEM *.
00605 *
00606 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00607 * #R_PKEY_FIELD_ID_DSA_PRIME.
00608 */
00609 #define R_PKEY_INFO_ID_DSA_PRIME R_PKEY_FIELD_ID_DSA_PRIME
00610 /**
00611 * This identifier is used for the retrieval of the Digital Signature
00612 * Algorithm (DSA) sub-prime associated with the #R_PKEY. To retrieve
00613 * this value the parameter reference should be passed in as cast #R_ITEM *.
00614 *
00615 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00616 * #R_PKEY_FIELD_ID_DSA_SUBPRIME.
00617 */
00618 #define R_PKEY_INFO_ID_DSA_SUBPRIME R_PKEY_FIELD_ID_DSA_SUBPRIME
00619 /**
00620 * This identifier is used for the retrieval of the Digital Signature
00621 * Algorithm (DSA) base associated with the #R_PKEY. To retrieve this
00622 * value the parameter reference should be passed in as cast #R_ITEM *.
00623 *
00624 * @see R_PKEY_get_info(), R_PKEY_set_info()
00625 * and #R_PKEY_FIELD_ID_DSA_BASE.
00626 */
00627 #define R_PKEY_INFO_ID_DSA_BASE R_PKEY_FIELD_ID_DSA_BASE
00628 /**
00629 * This identifier is used for the retrieval of the Digital Signature
00630 * Algorithm (DSA) public key associated with the #R_PKEY. To retrieve
00631 * this value the parameter reference should be passed in as cast #R_ITEM *.
00632 *
00633 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00634 * #R_PKEY_FIELD_ID_DSA_PUB_KEY.
00635 */
00636 #define R_PKEY_INFO_ID_DSA_PUB_KEY R_PKEY_FIELD_ID_DSA_PUB_KEY
00637 /**
00638 * This identifier is used for the retrieval of the Digital Signature
00639 * Algorithm (DSA) private key associated with the #R_PKEY. To retrieve
00640 * this value the parameter reference should be passed in as cast #R_ITEM *.
00641 *
00642 * @see R_PKEY_get_info(), R_PKEY_set_info() and
00643 * #R_PKEY_FIELD_ID_DSA_PRIV_KEY.
00644 */
00645 #define R_PKEY_INFO_ID_DSA_PRIV_KEY R_PKEY_FIELD_ID_DSA_PRIV_KEY
00646 /**
00647 * This identifier is used for the retrieval of the #R_PKEY_CTX associated
00648 * with the #R_PKEY. To retrieve this value the parameter reference should be
00649 * passed in as cast #R_PKEY_CTX **.
00650 *
00651 * @see R_PKEY_get_info().
00652 */
00653 #define R_PKEY_INFO_ID_R_PKEY_CTX (R_PKEY_INFO_ID_BASE+1)
00654 /**
00655 * This identifier is used for the retrieval of the #R_EITEMS associated
00656 * with the #R_PKEY. To retrieve this value the parameter reference should be
00657 * passed in as cast #R_EITEMS **.
00658 *
00659 * @see R_PKEY_get_info().
00660 */
00661 #define R_PKEY_INFO_ID_R_EITEMS (R_PKEY_INFO_ID_BASE+2)
00662 /**
00663 * This identifier is used for the retrieval of the flags associated
00664 * with the #R_PKEY. To retrieve this value the parameter reference should be
00665 * passed in as cast <tt>int *</tt>.
00666 *
00667 * @see R_PKEY_get_info().
00668 */
00669 #define R_PKEY_INFO_ID_FLAG (R_PKEY_INFO_ID_BASE+3)
00670 /**
00671 * This identifier is used for the retrieval of the implementation data
00672 * associated with the #R_PKEY. To retrieve this value the parameter reference
00673 * should be passed in as cast <tt>void **</tt>.
00674 *
00675 * @see R_PKEY_get_info().
00676 */
00677 #define R_PKEY_INFO_ID_DATA (R_PKEY_INFO_ID_BASE+4)
00678 /**
00679 * This identifier is used for the retrieval of the reference count associated
00680 * with the #R_PKEY. To retrieve this value the parameter reference should be
00681 * passed in as cast <tt>int *</tt>.
00682 *
00683 * @see R_PKEY_get_info() and R_PKEY_reference_inc().
00684 */
00685 #define R_PKEY_INFO_ID_REFERENCE (R_PKEY_INFO_ID_BASE+5)
00686 /**
00687 * This identifier is used for the retrieval of the #R_PKEY_TYPE
00688 * associated with the #R_PKEY. To retrieve this value the parameter reference
00689 * should be passed in as cast #R_PKEY_TYPE *.
00690 *
00691 * @see R_PKEY_get_info().
00692 */
00693 #define R_PKEY_INFO_ID_TYPE (R_PKEY_INFO_ID_BASE+6)
00694 /**
00695 * This identifier is used for the retrieval of the number of bits associated
00696 * with the #R_PKEY. To retrieve this value the parameter reference should be
00697 * passed in as cast <tt>int *</tt>.
00698 *
00699 * @see R_PKEY_get_info().
00700 */
00701 #define R_PKEY_INFO_ID_NUM_BITS (R_PKEY_INFO_ID_BASE+7)
00702 /**
00703 * This identifier is used for the retrieval of the number of primes
00704 * associated with the #R_PKEY. This is valid for two prime and MultiPrime
00705 * keys. To retrieve this value the parameter reference should be passed in
00706 * as cast <tt>int *</tt>.
00707 *
00708 * @see R_PKEY_get_info() and R_PKEY_set_info().
00709 */
00710 #define R_PKEY_INFO_ID_NUM_PRIMES (R_PKEY_INFO_ID_BASE+8)
00711 /**
00712 * @}
00713 */
00714
00715 /*
00716 * There are opaque data types for those things for which can
00717 * switch the implementation routines - hence they do not really have
00718 * a known type as this is able to be changed at runtime.
00719 *
00720 */
00721 #ifndef HEADER_COMMON_R_PKEY_TYPEDEF_DEF
00722 #define HEADER_COMMON_R_PKEY_TYPEDEF_DEF
00723 /**
00724 * This public key structure can contain both public and/or private key data.
00725 */
00726 typedef struct r_pkey_st R_PKEY;
00727 #endif /* HEADER_COMMON_R_PKEY_TYPEDEF_DEF */
00728
00729 #ifndef HEADER_COMMON_DATA_R_EITEMS_TYPEDEF_DEF
00730 #define HEADER_COMMON_DATA_R_EITEMS_TYPEDEF_DEF
00731 typedef struct r_eitem_st R_EITEM; /* Extended item structure. */
00732 typedef struct r_eitems_st R_EITEMS; /* Extended items structure. */
00733 #endif /* HEADER_COMMON_DATA_R_EITEMS_TYPEDEF_DEF */
00734
00735 /*
00736 * There is a method table (which encapsulates the functions that implement
00737 * the handling of all public key related functions for a particular type).
00738 */
00739 /**
00740 * The table of methods for public keys.
00741 */
00742 typedef struct r_pkey_method_st R_PKEY_METHOD;
00743
00744
00745 /*
00746 * There is a context which holds a method and other information needed
00747 * for the runtime glue between routines.
00748 */
00749 #ifndef HEADER_COMMON_R_PKEY_CTX_TYPEDEF_DEF
00750 #define HEADER_COMMON_R_PKEY_CTX_TYPEDEF_DEF
00751 /**
00752 * The public key context structure.
00753 */
00754 typedef struct r_pkey_ctx_st R_PKEY_CTX;
00755 #endif /* HEADER_COMMON_R_PKEY_CTX_TYPEDEF_DEF */
00756
00757 #include "r_pkey_m.h"
00758
00759 /*
00760 * Exported functions
00761 */
00762
00763 /**
00764 * @defgroup PKEY_CTX_INFO Context Information Identifiers
00765 * This section lists the identifiers used to set and/or retrieve information
00766 * from an #R_PKEY_CTX object.
00767 * The following table details the data types to pass into <i>param</i> when
00768 * calling R_PKEY_CTX_get_info().
00769 * @br
00770 * <table><tr>
00771 * <td><b>Identifier</b></td>
00772 * <td><b>Param Data Type</b></td>
00773 * </tr><tr>
00774 * <td>#R_PKEY_CTX_INFO_ID_LIB_CTX</td>
00775 * <td>#R_LIB_CTX **</td>
00776 * </tr><tr>
00777 * <td>#R_PKEY_CTX_INFO_ID_R_PKEY_METHOD</td>
00778 * <td>#R_PKEY_METHOD **</td>
00779 * </tr><tr>
00780 * <td>#R_PKEY_CTX_INFO_ID_CRYPTO_CTX</td>
00781 * <td><tt>void **</tt></td>
00782 * </tr><tr>
00783 * <td>#R_PKEY_CTX_INFO_ID_FLAG</td>
00784 * <td><tt>int *</tt></td>
00785 * </tr><tr>
00786 * <td>#R_PKEY_CTX_INFO_ID_DATA</td>
00787 * <td><tt>void **</tt></td>
00788 * </tr><tr>
00789 * </tr></table>
00790 * @br
00791 *
00792 * The following table details the data types to pass into <i>param</i> when
00793 * calling R_PKEY_CTX_set_info().
00794 * @br
00795 * <table><tr>
00796 * <td><b>Identifier</b></td>
00797 * <td><b>Param Data Type</b></td>
00798 * </tr><tr>
00799 * <td>#R_PKEY_CTX_INFO_ID_FLAG</td>
00800 * <td><tt>int *</tt></td>
00801 * </tr><tr>
00802 * <td>#R_PKEY_CTX_INFO_ID_DATA</td>
00803 * <td><tt>void **</tt></td>
00804 * </tr><tr>
00805 * </tr></table>
00806 * @br
00807 * @ingroup PKEY_GROUP
00808 *
00809 * @{
00810 */
00811 /**
00812 * This identifier is used for the retrieval of the #R_LIB_CTX associated
00813 * with the #R_PKEY_CTX. To retrieve this value the parameter reference should
00814 * be passed in as cast #R_LIB_CTX **.
00815 *
00816 * @see R_PKEY_CTX_get_info().
00817 */
00818 #define R_PKEY_CTX_INFO_ID_LIB_CTX 1
00819 /**
00820 * This identifier is used for the retrieval of the #R_PKEY_METHOD associated
00821 * with the #R_PKEY_CTX. To retrieve this value the parameter reference should
00822 * be passed in as cast #R_PKEY_METHOD **.
00823 *
00824 * @see R_PKEY_CTX_get_info().
00825 */
00826 #define R_PKEY_CTX_INFO_ID_R_PKEY_METHOD 2
00827 /**
00828 * This identifier is used for the retrieval of the cryptographic context
00829 * associated with the #R_PKEY_CTX. To retrieve this value the parameter
00830 * reference should be passed in as cast <tt>void **</tt>.
00831 *
00832 * @see R_PKEY_CTX_get_info().
00833 */
00834 #define R_PKEY_CTX_INFO_ID_CRYPTO_CTX 3
00835 /**
00836 * This identifier is used for the setting or retrieval of the flags
00837 * associated with the #R_PKEY_CTX. To retrieve this value the parameter
00838 * reference should be passed in as cast <tt>int *</tt>.
00839 *
00840 * @see R_PKEY_CTX_get_info() and R_PKEY_CTX_set_info().
00841 */
00842 #define R_PKEY_CTX_INFO_ID_FLAG 4
00843 /**
00844 * This identifier is used for the setting or retrieval of the extra
00845 * implementation data associated with the #R_PKEY_CTX. To retrieve this value
00846 * the parameter reference should be passed in as cast <tt>void **</tt>.
00847 *
00848 * @see R_PKEY_CTX_get_info() and R_PKEY_CTX_set_info().
00849 */
00850 #define R_PKEY_CTX_INFO_ID_DATA 5
00851
00852 /**
00853 * @}
00854 */
00855
00856 /**
00857 * @defgroup PKEY_CB_FUNC Public Key Callback Functions
00858 * This section documents the function provided for the utilization of
00859 * user-defined callback routines.
00860 * @ingroup PKEY_GROUP
00861 * @{
00862 */
00863 /**
00864 * The callback function to use with R_PKEY_iterate_fields().
00865 * This function will be called and passed with each field of the key, one
00866 * key at a time.
00867 *
00868 * @param arg [In] The user-defined argument.
00869 * @param type [In] The type of the data.
00870 * @param item [In] An item of data.
00871 * @return #R_ERROR_NONE indicates success.<br>
00872 * See @ref R_ERROR_IDS for valid values.
00873 *
00874 * @see R_PKEY_iterate_fields().
00875 */
00876 typedef int R_PKEY_CB_T(void *arg, int type, R_ITEM *item);
00877
00878 /**
00879 * @}
00880 */
00881
00882 /**
00883 * @defgroup PKEY_ALL_FUNCS Asymmetric Key Functions
00884 * This section provides information on the functions which perform asymmetric
00885 * key processing.
00886 * @ingroup PKEY_GROUP
00887 * @{
00888 */
00889 /**
00890 * @}
00891 */
00892
00893 /**
00894 * @defgroup PKEY_CTX Context Functions
00895 * This section lists the functions that facilitate public key contexts.
00896 * @ingroup PKEY_ALL_FUNCS
00897 * @{
00898 */
00899
00900 #ifndef NO_R_PKEY_METH_TABLE
00901 int R_PKEY_CTX_new(R_LIB_CTX *lib_ctx, R_RES_FLAG flag, R_PKEY_TYPE pkeytype,
00902 R_PKEY_CTX **pkey_ctx);
00903 int R_PKEY_CTX_free(R_PKEY_CTX *ctx);
00904
00905 int R_PKEY_CTX_get_info(R_PKEY_CTX *pkey_ctx, int id, void *param);
00906 int R_PKEY_CTX_set_info(R_PKEY_CTX *pkey_ctx, int id, void *param);
00907
00908 R_LIB_CTX *R_PKEY_CTX_get_LIB_CTX(R_PKEY_CTX *ctx);
00909 #endif /* !defined(NO_R_PKEY_METH_TABLE) */
00910
00911 R_PKEY_METHOD *R_PKEY_pk_method(void *imp_data);
00912
00913 /**
00914 * @}
00915 */
00916
00917 /**
00918 * @defgroup R_PKEY_PUB_FN Operation Functions
00919 * This section contains all the functions that manage public keys.
00920 * @ingroup PKEY_ALL_FUNCS
00921 * @{
00922 */
00923
00924 #ifndef NO_R_PKEY_METH_TABLE
00925 R_PKEY_CTX *R_PKEY_get_PKEY_CTX(R_PKEY *pkey);
00926
00927 /* Return the "type" of a pkey - R_PKEY_TYPE_* */
00928 int R_PKEY_get_type(R_PKEY *pkey);
00929
00930 /* Public/Private key functions */
00931 int R_PKEY_new(R_PKEY_CTX *ctx, R_PKEY_TYPE pkeytype, R_PKEY **pkey);
00932 int R_PKEY_free(R_PKEY *pkey);
00933 int R_PKEY_copy(R_PKEY *new_pkey, R_PKEY *pkey, int flag);
00934
00935 int R_PKEY_from_binary(R_PKEY_CTX *pkey_ctx, int flag, R_PKEY_TYPE type,
00936 size_t max_buf_len, const unsigned char *buf, size_t *consumed_len,
00937 R_PKEY **pkey);
00938 int R_PKEY_to_binary(R_PKEY *pkey, size_t max_buf_len, unsigned char *buf,
00939 size_t *consumed_len);
00940 int R_PKEY_from_public_key_binary(R_PKEY_CTX *pkey_ctx, int flag,
00941 R_PKEY_TYPE type, size_t max_buf_len, const unsigned char *buf,
00942 size_t *consumed_len, R_PKEY **pkey);
00943 int R_PKEY_to_public_key_binary(R_PKEY *pkey, size_t max_buf_len,
00944 unsigned char *buf, size_t *out_len);
00945
00946 int R_PKEY_reference_inc(R_PKEY *pkey);
00947 int R_PKEY_cmp(R_PKEY *key1, R_PKEY *key2);
00948 int R_PKEY_public_cmp(R_PKEY *key1, R_PKEY *key2);
00949
00950 int R_PKEY_get_info(R_PKEY *pkey, int id, void *param);
00951 int R_PKEY_set_info(R_PKEY *pkey, int type, void *param);
00952
00953 int R_PKEY_iterate_fields(R_PKEY *pkey, R_PKEY_CB_T *func, void *arg);
00954
00955 /* Crypto-related functions */
00956 int R_PKEY_get_num_bits(R_PKEY *pkey);
00957 int R_PKEY_get_num_primes(R_PKEY *pkey);
00958 int R_PKEY_signhash(R_PKEY *pkey, unsigned char *data, unsigned int dlen,
00959 unsigned char *out, unsigned int *olen);
00960 int R_PKEY_verifyhash(R_PKEY *pkey, unsigned char *data, unsigned int dlen,
00961 unsigned char *hash, unsigned int hlen);
00962 #endif /* !defined(NO_R_PKEY_METH_TABLE) */
00963
00964 int R_PKEY_generate_simple(R_PKEY_CTX *pkey_ctx, R_PKEY **rpkey, int type,
00965 int num_bits, int modifier, int flags, R_SURRENDER *surrender);
00966
00967 /* wrapper functions - common non-format specific functions that simply
00968 * encapsulate often used steps
00969 */
00970
00971 int R_PKEY_from_file(R_PKEY_CTX *pkey_ctx, R_PKEY **pkey, char *filename,
00972 int type, R_FORMAT format);
00973
00974 int R_PKEY_TYPE_to_string(R_PKEY_TYPE type, size_t max_str_len, char *str);
00975 int R_PKEY_TYPE_from_string(R_PKEY_TYPE *type, char *str);
00976 int R_PKEY_TYPE_to_PEM_header(R_PKEY_TYPE type, size_t max_str_len, char *str);
00977
00978 #ifndef NO_BIO
00979 int R_PKEY_to_bio(BIO *bio, R_PKEY *pkey, R_FORMAT format, char *cipher);
00980
00981 #ifndef NO_R_PKEY_METH_TABLE
00982 int R_PKEY_print(BIO *bio, R_PKEY *pkey, R_FORMAT format, char *format_arg);
00983 #endif /* !defined(NO_R_PKEY_METH_TABLE) */
00984
00985 int R_PKEY_from_bio(BIO *bio, R_PKEY_CTX *pkey_ctx, R_PKEY **pkey, int type,
00986 R_FORMAT format);
00987 #endif /* NO_BIO */
00988
00989 /**
00990 * @}
00991 */
00992
00993 #ifdef __cplusplus
00994 }
00995 #endif
00996 #endif /* HEADER_COMMON_CERT_R_PKEY_H */