RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

cryp_mod.h

Go to the documentation of this file.
00001 /* $Id: cryp_mod.h,v 1.170.2.1 2005/10/11 03:37:15 hpriddle Exp $ */
00002 /*
00003  * Copyright (C) 1998-2003 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 
00023 #ifndef HEADER_COMMON_CRYP_MOD_H
00024 #define HEADER_COMMON_CRYP_MOD_H
00025 
00026 #ifdef  __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 #include "r_lib.h"
00031 #include "r_com.h"
00032 #include "r_nid.h"
00033 #include "r_pkey.h"
00034 #include "r_skey.h"
00035 
00036 #include "c_impmth.h"
00037 
00038 #if !defined(NO_NAT_METH) && !defined(NO_SOFTWARE_CRYPTO)
00039 #include "nat_meth.h"
00040 #endif
00041 
00042 #ifndef HEADER_COMMON_MODULE_CRYP_MOD_TYPEDEF_DEF
00043 #define HEADER_COMMON_MODULE_CRYP_MOD_TYPEDEF_DEF
00044 
00055 typedef int R_CR_ALG_ID;
00060 typedef int R_CR_ALG_TYPE;
00065 typedef int R_CR_ALG_SUB;
00066 #endif /* HEADER_COMMON_MODULE_CRYP_MOD_TYPEDEF_DEF */
00067 
00108 #define R_CR_DIGEST_MD2_LEN                 16
00109 
00112 #define R_CR_DIGEST_MD5_LEN                 16
00113 
00116 #define R_CR_DIGEST_SHA1_LEN                20
00117 
00120 #define R_CR_DIGEST_SHA256_LEN              32
00121 
00124 #define R_CR_DIGEST_SHA384_LEN              48
00125 
00128 #define R_CR_DIGEST_SHA512_LEN              64
00129 #ifndef NO_SHA512
00130 
00133 #define R_CR_DIGEST_MAX_LEN                 R_CR_DIGEST_SHA512_LEN
00134 #elif !defined(NO_SHA384)
00135 #define R_CR_DIGEST_MAX_LEN                 R_CR_DIGEST_SHA384_LEN
00136 #elif !defined(NO_SHA256)
00137 #define R_CR_DIGEST_MAX_LEN                 R_CR_DIGEST_SHA256_LEN
00138 #elif !defined(NO_SHA1)
00139 #define R_CR_DIGEST_MAX_LEN                 R_CR_DIGEST_SHA1_LEN
00140 #elif !defined(NO_MD5)
00141 #define R_CR_DIGEST_MAX_LEN                 R_CR_DIGEST_MD5_LEN
00142 #else
00143 #define R_CR_DIGEST_MAX_LEN                 16
00144 #endif
00145 
00158 #define R_CR_CIPHER_KEY_MAX_LEN             32 /* AES is the biggest */
00159 
00162 #define R_CR_CIPHER_IV_MAX_LEN              32 /* AES is the biggest */
00163 
00178 #define R_CR_NOT_SUPPORTED                  0
00179 
00182 #define R_CR_NOT_AVAIL                      1
00183 
00186 #define R_CR_SUPPORTED                      2
00187 
00308 #define R_CR_TYPE_NONE                      0
00309 
00327 #define R_CR_TYPE_ASYM                      1
00328 
00346 #define R_CR_TYPE_CIPHER                    2
00347 
00365 #define R_CR_TYPE_DIGEST                    3
00366 
00384 #define R_CR_TYPE_RANDOM                    4
00385 
00403 #define R_CR_TYPE_KEY_EXCHANGE              5
00404 
00422 #define R_CR_TYPE_SIGNATURE                 6
00423 
00441 #define R_CR_TYPE_MAC                       7
00442 
00460 #define R_CR_TYPE_KEYGEN                    8
00461 
00479 #define R_CR_TYPE_PARAMGEN                  9
00480 
00498 #define R_CR_TYPE_MAX                       9
00499 
00504 /* There are two sorts of sub-ids -- Those with a single bit set that can be
00505    combined by bit-wise or in a method table for methods that can handle more
00506    than one sub-id. For algorithms for which combinable sub-ids are not
00507    sensible, a range for scalar sub-id allocation is also reserved.
00508 
00509    Assuming a 32-bit integer, up to 30 single-bit sub-ids and 2^^31 - 2
00510    scalar sub-ids may be defined.
00511 
00512    The macros below have the effect of defining scalar sub-ids as odd numbers
00513    and single-bit sub-ids as even numbers. Using the low-order bit to
00514    distinguish scalar and bit ids ensures independence from integer size.
00515 */
00516 #define R_CR_SUB_BIT(n)                 (1<<((n)+1))
00517 #define R_CR_SUB_SCALAR(n)              (((n)<<1)|1)
00518 #define R_CR_IS_SUB_SCALAR(sub)         ((((sub)&1)==1)||(sub==R_CR_SUB_NONE))
00519 #define R_CR_IS_SUB_BIT(sub)            (!R_CR_IS_SUB_SCALAR(sub))
00520 
00521 /* the max sub bit currently used - must be updated when new SUB_IDs are added
00522  * as the hardware module uses this to make sure SUB_IDs it requires do
00523  * no clash with those used here.
00524  */
00525 #define R_CR_SUB_BIT_MAX                8
00526 
00627 #define R_CR_SUB_NONE                   0
00628 
00650 #define R_CR_SUB_SIGN                   R_CR_SUB_BIT(0)
00651 
00673 #define R_CR_SUB_VERIFY                 R_CR_SUB_BIT(1)
00674 
00696 #define R_CR_SUB_ENCRYPT                R_CR_SUB_BIT(2)
00697 
00719 #define R_CR_SUB_DECRYPT                R_CR_SUB_BIT(3)
00720 
00742 #define R_CR_SUB_PUBLIC                 R_CR_SUB_BIT(4)
00743 
00765 #define R_CR_SUB_PRIVATE                R_CR_SUB_BIT(5)
00766 
00789 #define R_CR_SUB_MAC                    R_CR_SUB_BIT(6)
00790 
00812 #define R_CR_SUB_SOFTWARE_ONLY          R_CR_SUB_BIT(7)
00813 
00836 #define R_CR_SUB_HARDWARE_ONLY          R_CR_SUB_BIT(8)
00837 
00859 #define R_CR_SUB_PUB_ENC                (R_CR_SUB_PUBLIC|R_CR_SUB_ENCRYPT)
00860 
00882 #define R_CR_SUB_PUB_DEC                (R_CR_SUB_PUBLIC|R_CR_SUB_DECRYPT)
00883 
00903 #define R_CR_SUB_PRIV_ENC               (R_CR_SUB_PRIVATE|R_CR_SUB_ENCRYPT)
00904 
00926 #define R_CR_SUB_PRIV_DEC               (R_CR_SUB_PRIVATE|R_CR_SUB_DECRYPT)
00927 
00964 /*
00965  * Use this macro to define IDs that are meaningful only to the R_CR_xxx
00966  * functions and not to lower layers (e.g., the nat_meth layer. These IDs
00967  * MUST NOT be passed to lower layers that expect some type of NID_xxx. The
00968  * local IDs begin at 4096 to give wide berth to the NIDs defined in
00969  * object.h.
00970  */
00971 #define R_CR_ID_LOCAL(local_id)             (4096 + (local_id))
00972 
00973 /* the max id currently used - must be updated when new IDs are added
00974  * as the hardware module uses this to make sure IDs it requires do
00975  * no clash with those used here.
00976  */
00977 #define R_CR_ID_MAX                         R_CR_ID_LOCAL(10)
00978 
00979 /* Define algorithm IDs and map them to NIDs where possible.
00980    In general, two names are defined for each ID -- one that includes the
00981    algorithm type and one that does not.
00982  */
01002 #define R_CR_ID_UNKNOWN                     (-1)
01003 
01146 #define R_CR_ID_RSA                         NID_rsa
01147 
01167 #define R_CR_ID_RSA_PKCS1                   NID_rsaEncryption
01168 
01188 #define R_CR_ID_RSA_PKCS1_OAEP              NID_rsaes_oaep
01189 
01209 #define R_CR_ID_RSA_PKCS1_SSL               R_CR_ID_LOCAL(7)
01210 
01230 #define R_CR_ID_RSA_PKCS1_RAW               R_CR_ID_LOCAL(9)
01231 
01252 #define R_CR_ID_RSA_X931                    R_CR_ID_LOCAL(14)
01253 
01275 #define R_CR_ID_ECAES                       R_CR_ID_LOCAL(23)
01276 
01730 #define R_CR_ID_AES_128_CBC                 NID_aes128_cbc
01731 
01750 #define R_CR_ID_AES_128_ECB                 NID_aes128_ecb
01751 
01770 #define R_CR_ID_AES_128_CFB                 NID_aes128_cfb
01771 
01790 #define R_CR_ID_AES_128_OFB                 NID_aes128_ofb
01791 
01811 #define R_CR_ID_AES_192_CBC                 NID_aes192_cbc
01812 
01831 #define R_CR_ID_AES_192_ECB                 NID_aes192_ecb
01832 
01851 #define R_CR_ID_AES_192_CFB                 NID_aes192_cfb
01852 
01871 #define R_CR_ID_AES_192_OFB                 NID_aes192_ofb
01872 
01892 #define R_CR_ID_AES_256_CBC                 NID_aes256_cbc
01893 
01912 #define R_CR_ID_AES_256_ECB                 NID_aes256_ecb
01913 
01932 #define R_CR_ID_AES_256_CFB                 NID_aes256_cfb
01933 
01952 #define R_CR_ID_AES_256_OFB                 NID_aes256_ofb
01953 
01973 #define R_CR_ID_DES_CBC                     NID_des_cbc
01974 
01994 #define R_CR_ID_DES_EDE                     NID_des_ede
01995 
02014 #define R_CR_ID_DES_ECB                     NID_des_ecb
02015 
02034 #define R_CR_ID_DES_CFB64                   NID_des_cfb64
02035 
02054 #define R_CR_ID_DES_EDE3                    NID_des_ede3
02055 
02074 #define R_CR_ID_DES_EDE_CBC                 NID_des_ede_cbc
02075 
02094 #define R_CR_ID_DES_EDE3_CBC                NID_des_ede3_cbc
02095 
02114 #define R_CR_ID_DES_EDE_CFB64               NID_des_ede_cfb64
02115 
02135 #define R_CR_ID_DES_EDE3_CFB64              NID_des_ede3_cfb64
02136 
02155 #define R_CR_ID_DES_EDE_OFB64               NID_des_ede_ofb64
02156 
02175 #define R_CR_ID_DES_EDE3_OFB64              NID_des_ede3_ofb64
02176 
02196 #define R_CR_ID_DES_40_CBC                  NID_des_40_cbc
02197 
02217 #define R_CR_ID_DES_40_CFB                  NID_des_40_cfb
02218 
02237 #define R_CR_ID_DES_OFB                     NID_des_ofb64
02238 
02258 #define R_CR_ID_RC2_CBC                     NID_rc2_cbc
02259 
02278 #define R_CR_ID_RC2_ECB                     NID_rc2_ecb
02279 
02298 #define R_CR_ID_RC2_CFB                     NID_rc2_cfb64
02299 
02318 #define R_CR_ID_RC2_OFB                     NID_rc2_ofb64
02319 
02339 #define R_CR_ID_RC2_40_CBC                  NID_rc2_40_cbc
02340 
02360 #define R_CR_ID_RC4                         NID_rc4
02361 
02380 #define R_CR_ID_RC4_40                      NID_rc4_40
02381 
02403 #define R_CR_ID_RC5_CBC                     NID_rc5_cbc
02404 
02405 /*
02406  * Equivalent RC5-CBC identifier for compatibility with OpenSSL
02407  */
02408 #define R_CR_ID_RC5_CBC_NO_PAD              NID_rc5_cbc_no_pad
02409 
02431 #define R_CR_ID_RC5_ECB                     NID_rc5_ecb
02432 
02453 #define R_CR_ID_RC5_CFB                     NID_rc5_cfb64
02454 
02475 #define R_CR_ID_RC5_OFB                     NID_rc5_ofb64
02476 
02477 /*
02478  * A cryptographic identifier which indicates an RC6 CBC symmetric cipher.
02479  * The following table details the usage of the identifier
02480  * in @ref R_CR_CTX_FN.
02481  *
02482  * <table><tr>
02483  * <td><b>Function</b></td>
02484  * <td><b>String</b></td>
02485  * <td><b>Description</b></td>
02486  * </tr><tr>
02487  * <td>R_CR_ID_from_string()</td>
02488  * <td><tt>"RC6_CBC"</tt></td>
02489  * <td>This string is interpreted as the <tt>RC6_CBC</tt> type.</td>
02490  * </tr><tr>
02491  * <td>R_CR_ID_to_string()</td>
02492  * <td><tt>"RC6_CBC"</tt></td>
02493  * <td>The string that represents an <tt>RC6_CBC</tt> type.</td>
02494  * </tr></table>
02495  */
02496 #define R_CR_ID_RC6_CBC                     NID_rc6_cbc
02497 /*
02498  * A cryptographic identifier which indicates an RC6 ECB symmetric cipher.
02499  * The following table details the usage of the identifier
02500  * in @ref R_CR_CTX_FN.
02501  *
02502  * <table><tr>
02503  * <td><b>Function</b></td>
02504  * <td><b>String</b></td>
02505  * <td><b>Description</b></td>
02506  * </tr><tr>
02507  * <td>R_CR_ID_from_string()</td>
02508  * <td><tt>"RC6_ECB"</tt></td>
02509  * <td>This string is interpreted as the <tt>RC6_ECB</tt> type.</td>
02510  * </tr><tr>
02511  * <td>R_CR_ID_to_string()</td>
02512  * <td><tt>"RC6_ECB"</tt></td>
02513  * <td>The string that represents an <tt>RC6_ECB</tt> type.</td>
02514  * </tr></table>
02515  */
02516 #define R_CR_ID_RC6_ECB                     NID_rc6_ecb
02517 /*
02518  * A cryptographic identifier which indicates an RC6 CFB symmetric cipher.
02519  * The following table details the usage of the identifier
02520  * in @ref R_CR_CTX_FN.
02521  *
02522  * <table><tr>
02523  * <td><b>Function</b></td>
02524  * <td><b>String</b></td>
02525  * <td><b>Description</b></td>
02526  * </tr><tr>
02527  * <td>R_CR_ID_from_string()</td>
02528  * <td><tt>"RC6_CFB"</tt></td>
02529  * <td>This string is interpreted as the <tt>RC6_CFB</tt> type.</td>
02530  * </tr><tr>
02531  * <td>R_CR_ID_to_string()</td>
02532  * <td><tt>"RC6_CFB"</tt></td>
02533  * <td>The string that represents an <tt>RC6_CFB</tt> type.</td>
02534  * </tr></table>
02535  */
02536 #define R_CR_ID_RC6_CFB                     NID_rc6_cfb128
02537 /*
02538  * A cryptographic identifier which indicates an RC6 OFB symmetric cipher.
02539  * The following table details the usage of the identifier
02540  * in @ref R_CR_CTX_FN.
02541  *
02542  * <table><tr>
02543  * <td><b>Function</b></td>
02544  * <td><b>String</b></td>
02545  * <td><b>Description</b></td>
02546  * </tr><tr>
02547  * <td>R_CR_ID_from_string()</td>
02548  * <td><tt>"RC6_OFB"</tt></td>
02549  * <td>This string is interpreted as the <tt>RC6_OFB</tt> type.</td>
02550  * </tr><tr>
02551  * <td>R_CR_ID_to_string()</td>
02552  * <td><tt>"RC6_OFB"</tt></td>
02553  * <td>The string that represents an <tt>RC6_OFB</tt> type.</td>
02554  * </tr></table>
02555  */
02556 #define R_CR_ID_RC6_OFB                     NID_rc6_ofb128
02557 
02577 #define R_CR_ID_NULL                        0
02578 
02716 #define R_CR_ID_SHA1                        NID_sha1
02717 
02738 #define R_CR_ID_SHA256                      NID_sha256
02739 
02760 #define R_CR_ID_SHA384                      NID_sha384
02761 
02782 #define R_CR_ID_SHA512                      NID_sha512
02783 
02803 #define R_CR_ID_MD2                         NID_md2
02804 
02823 #define R_CR_ID_MD5                         NID_md5
02824 
02844 #define R_CR_ID_DIGEST_NULL                 R_CR_ID_NULL
02845 
02956 #define R_CR_ID_RANDOM                      R_CR_ID_LOCAL(0)
02957 
02978 #define R_CR_ID_RANDOM_ENTROPY              R_CR_ID_LOCAL(11)
02979 
02980 /*
02981  * Indicates a random cryptographic identifier that uses
02982  * the global FIPS 186-2 CN1 random object.
02983  */
02984 #define R_CR_ID_RANDOM_GLOBAL               R_CR_ID_LOCAL(12)
02985 
03006 #define R_CR_ID_RANDOM_MODULUS              R_CR_ID_LOCAL(13)
03007 
03028 #define R_CR_ID_RANDOM_SYS                  R_CR_ID_LOCAL(8)
03029 
03030 /*
03031  * Indicates the identifier for the deterministic random implementation.
03032  * This "random" implementation allows Byte blocks to be set by the
03033  * application that are returned without modification from
03034  * R_CR_random_bytes(). This option is meant to be used for testing
03035  * purposes only, where deterministic random output is an advantage.
03036  *
03037  * The following table details the usage of the identifier
03038  * in @ref R_CR_CTX_FN.
03039  *
03040  * <table><tr>
03041  * <td><b>Function</b></td>
03042  * <td><b>String</b></td>
03043  * <td><b>Description</b></td>
03044  * </tr><tr>
03045  * <td>R_CR_ID_from_string()</td>
03046  * <td><tt>"RANDOM_OTP"</tt></td>
03047  * <td>This string is interpreted as the <tt>RANDOM_OTP</tt> type.</td>
03048  * </tr><tr>
03049  * <td>R_CR_ID_to_string()</td>
03050  * <td><tt>"RANDOM_OTP"</tt></td>
03051  * <td>The string that represents a <tt>RANDOM_OTP</tt> type.</td>
03052  * </tr></table>
03053  */
03054 #define R_CR_ID_RANDOM_OTP                  R_CR_ID_LOCAL(17)
03055 
03060 #ifndef NO_DH
03061 
03105 #endif /* NO_DH */
03106 
03128 #define R_CR_ID_KE_DH                       NID_dhKeyAgreement
03129 
03375 #define R_CR_ID_DSA                         NID_dsa
03376 
03377 /* Defines for signing and verify */
03398 #define R_CR_ID_SHA1_DSA                    NID_dsaWithSHA1
03399 
03420 #define R_CR_ID_SHA1_RSA                    NID_sha1WithRSAEncryption
03421 
03441 #define R_CR_ID_SHA1_RSA_RAW                R_CR_ID_LOCAL(10)
03442 
03463 #define R_CR_ID_SHA1_RSA_X931               R_CR_ID_LOCAL(15)
03464 
03484 #define R_CR_ID_MD2_RSA                     NID_md2WithRSAEncryption
03485 
03504 #define R_CR_ID_MD5_RSA                     NID_md5WithRSAEncryption
03505 
03527 #define R_CR_ID_SIGNATURE_TYPE_NONE         R_CR_ID_NULL
03528 
03550 #define R_CR_ID_SIGNATURE_TYPE_DER          1
03551 
03672 #define R_CR_ID_HMAC_MD5                    R_CR_ID_LOCAL(1)
03673 
03693 #define R_CR_ID_HMAC_SHA1                   R_CR_ID_LOCAL(2)
03694 
03798 #define R_CR_ID_RSA_KEY_GENERATION          R_CR_ID_LOCAL(3)
03799 
03818 #define R_CR_ID_RSA_KEY_GENERATION_X931     R_CR_ID_LOCAL(18)
03819 
03838 #define R_CR_ID_DSA_KEY_GENERATION          R_CR_ID_LOCAL(4)
03839 
03860 #define R_CR_ID_RSA_KEY_GENERATION_VENDOR    R_CR_ID_LOCAL(16)
03861 
03950 #define R_CR_ID_DSA_PARAMETER_GENERATION    R_CR_ID_LOCAL(5)
03951 
03975 #define R_CR_ID_DH_PARAMETER_GENERATION     R_CR_ID_LOCAL(6)
03976 
03981 #define R_CR_ID_ECDSA_SHA1                  NID_ECDSAwithSHA1
03982 
04272 /*
04273  * A cryptographic identifier which indicates that the algorithm is supported.
04274  */
04275 #define R_CR_INFO_ID_SUPPORTED              0
04276 
04279 #define R_CR_INFO_ID_KEY_LEN                1
04280 /*
04281  * A cryptographic identifier which indicates the export strength cipher.
04282  */
04283 #define R_CR_INFO_ID_IS_EXPORT              2
04284 /*
04285  * A cryptographic identifier which indicates key agreement authentication.
04286  */
04287 #define R_CR_INFO_ID_KE_AUTHENTICATE        3
04288 /*
04289  * A cryptographic identifier which indicates the key agreement type.
04290  */
04291 #define R_CR_INFO_ID_KE_TYPE                4
04292 /*
04293  * A cryptographic identifier which indicates the export strength key length.
04294  */
04295 #define R_CR_INFO_ID_CIPHER_EXP_KEY_LEN     5
04296 
04300 #define R_CR_INFO_ID_CIPHER_IV_LEN          6
04301 /*
04302  * A cryptographic identifier which indicates the symmetric cipher parameter.
04303  */
04304 #define R_CR_INFO_ID_CIPHER_PARAM           7
04305 
04309 #define R_CR_INFO_ID_CIPHER_ROUNDS          8
04310 /*
04311  * A cryptographic identifier which indicates the symmetric cipher type.
04312  */
04313 #define R_CR_INFO_ID_CIPHER_TYPE            9
04314 
04318 #define R_CR_INFO_ID_CIPHER_BLOCK_SIZE      10
04319 
04323 #define R_CR_INFO_ID_DIGEST_MAC_LEN         11
04324 
04328 #define R_CR_INFO_ID_DIGEST_BLOCK_SIZE      13
04329 
04333 #define R_CR_INFO_ID_CIPHER_BITS            14
04334 
04338 #define R_CR_INFO_ID_OAEP_PARAM             15
04339 
04342 #define R_CR_INFO_ID_SURRENDER              16
04343 
04347 #define R_CR_INFO_ID_CRYPTO_TYPE            17
04348 
04351 #define R_CR_INFO_ID_CRYPTO_ID              18
04352 
04355 #define R_CR_INFO_ID_CRYPTO_SUB             19
04356 
04361 #define R_CR_INFO_ID_BLOCK_PADDING          20
04362 
04366 #define R_CR_INFO_ID_FLAGS                  21
04367 
04371 #define R_CR_INFO_ID_NUM_BITS               22  
04376 #define R_CR_INFO_ID_NUM_PRIMES             23  
04380 #define R_CR_INFO_ID_PUBLIC_KEY             24
04381 
04384 #define R_CR_INFO_ID_PRIVATE_KEY            25
04385 
04389 #define R_CR_INFO_ID_DSA_P                  26
04390 
04394 #define R_CR_INFO_ID_DSA_Q                  27
04395 
04399 #define R_CR_INFO_ID_DSA_G                  28
04400 
04404 #define R_CR_INFO_ID_DH_PRIME_LENGTH        29  
04409 #define R_CR_INFO_ID_DH_GENERATOR_ORDER     30
04410 
04414 #define R_CR_INFO_ID_RSA_E                  31  
04419 #define R_CR_INFO_ID_DSA_PARAMETERS         32
04420 
04423 #define R_CR_INFO_ID_SIGNATURE              33
04424 
04428 #define R_CR_INFO_DH_PRIV_KEY               34
04429 
04432 #define R_CR_INFO_ID_RAND_FILE_NAME         48
04433 
04436 #define R_CR_INFO_ID_RAND_WRITE_FILE        49
04437 
04441 #define R_CR_INFO_ID_RAND_ADD_ENTROPY       50
04442 
04446 #define R_CR_INFO_ID_RAND_LOAD_FILE         51
04447 
04451 #define R_CR_INFO_ID_RAND_ENTROPY_FUNC      52
04452 
04456 #define R_CR_INFO_ID_RANDOM                 53
04457 
04464 #define R_CR_INFO_ID_RAND_BLOCK_SIZE        54
04465 
04471 #define R_CR_INFO_ID_RAND_AUTO_SEED         56
04472 
04478 #define R_CR_INFO_ID_RAND_KEY_SEED_COMPARE  57
04479 
04484 #define R_CR_INFO_ID_RAND_RUN_TIME_TESTS    58
04485 
04491 #define R_CR_INFO_ID_RAND_SEED_RESET        59
04492 
04496 #define R_CR_INFO_ID_RAND_MODULUS           60
04497 /*
04498  * A cryptographic identifier which sets the random object into a
04499  * deterministic mode of operation for testing purposes. Only available
04500  * when using #R_CR_ID_RANDOM_OTP. The deterministic mode of operation is
04501  * enabled by default.
04502  */
04503 #define R_CR_INFO_ID_RAND_PREDICTABLE_MODE  62
04504 /*
04505  * A cryptographic identifier which sets against a random object a random
04506  * object with which to get random data from. Only available when using
04507  * #R_CR_ID_RANDOM_OTP.
04508  */
04509 #define R_CR_INFO_ID_RAND_REAL_RANDOM       63
04510 
04514 #define R_CR_INFO_ID_DSA_SEED               64
04515 
04516 /* next available value for R_CR_INFO_ID is: 65 */
04517 
04522 #define R_CR_INFO_ID_LABEL                  PK_SHARED_ID_LABEL
04523 
04527 #define R_CR_INFO_ID_KEY_ID                 PK_SHARED_ID_HW_ID
04528 
04545 #define R_CR_FLAG_CIPHER_NO_BLOCK_PADDING   0x0001
04546 
04549 #define R_CR_FLAG_CIPHER_KEY_SET            0x0002
04550 
04554 #define R_CR_FLAG_DER_SIGNATURE             0x0004
04555 
04560 #define R_CR_FLAG_ITEMS_ALLOCED             0x0008
04561 
04566 #define R_CR_FLAG_RANDOM_AVAIL              0x0010
04567 
04572 #define R_CR_FLAG_RANDOM_R_CR               0x0020
04573 
04574 
04592 #define R_CR_RANDOM_ENTROPY_TYPE_SMALL      1
04593 
04598 #define R_CR_RANDOM_ENTROPY_TYPE_LARGE      2
04599 
04613 #define R_CR_RANDOM_RNG_KEY_SEED_COMPARE_OFF           0
04614 
04618 #define R_CR_RANDOM_RNG_KEY_SEED_COMPARE_ON            1
04619 
04623 #define R_CR_RANDOM_RNG_KEY_SEED_COMPARE_FAILED        2
04624 
04639 #define R_CR_RANDOM_RNG_TESTS_OFF           0
04640 
04644 #define R_CR_RANDOM_RNG_TESTS_ON            1
04645 
04649 #define R_CR_RANDOM_RNG_TESTS_FAILED        2
04650 
04708 #define R_CR_CTX_INFO_ID_RANDOM             0
04709 
04712 #define R_CR_CTX_INFO_ID_SURRENDER          1
04713 
04714 #ifndef NO_HDW
04715 
04718 #endif
04719 #define R_CR_CTX_INFO_ID_HW_CTX             3
04720 
04721 
04726 /* Structure types */
04730 typedef struct r_cr_method_st               R_CR_METHOD;
04734 typedef struct r_cr_imp_method_st           R_CR_IMP_METHOD;
04738 typedef struct r_cr_ctx_st                  R_CR_CTX;
04739 #ifndef HEADER_COMMON_R_CR_TYPEDEF_DEF
04740 #define HEADER_COMMON_R_CR_TYPEDEF_DEF
04741 
04744 typedef struct r_cr_st                      R_CR;
04745 #endif /* HEADER_COMMON_R_CR_TYPEDEF_DEF */
04746 
04749 typedef struct r_sign_vfy_map_obj_st        R_CR_SIGN_VFY_MAP;
04750 
04755 struct r_sign_vfy_map_obj_st
04756     {
04761     int sig_id;
04766     int dig_id;
04771     int pk_id;
04772     };
04773 
04789 #define R_CR_RES_LIBRARY_SMALL \
04790         { R_RES_MOD_ID_LIBRARY, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04791           R_RES_FLAG_DEF, NULL, NULL, \
04792           (void *(*)(void *))R_LIB_CTX_get_small_method, NULL }
04793 
04795 #define R_CR_RES_LIBRARY \
04796         { R_RES_MOD_ID_LIBRARY, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04797           R_RES_FLAG_DEF, NULL, NULL, \
04798           (void *(*)(void *))R_LIB_CTX_get_default_method, NULL }
04799 
04809 #ifdef FIPS140_ONLY
04810 #define R_CR_RES_CRYPTO_DEFAULT R_CR_RES_NIST
04811 #else
04812 #define R_CR_RES_CRYPTO_DEFAULT \
04813     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04814       R_RES_FLAG_DEF, NULL, NULL, \
04815       (void *(*)(void *))R_CR_get_default_method, \
04816       (void *(*)(void *))R_CR_get_default_imp_method }
04817 #endif
04818 
04825 #define R_CR_RES_CRYPTO_CUSTOM \
04826     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04827       R_RES_FLAG_DEF, NULL, NULL, \
04828       (void *(*)(void *))R_CR_get_default_method, \
04829       (void *(*)(void *))(R_CR_HAVE_CIPHER_LIST *(*)(void *))r_crm_custom_list_retriever }
04830 
04838 #define R_CR_RES_SIGNATURE_MAP \
04839     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_MAP,\
04840           R_RES_FLAG_DEF, NULL, NULL, NULL,\
04841       (void *(*)(void *))R_CR_get_default_signature_map }
04842 
04850 #define R_CR_RES_LOCK \
04851     { R_RES_MOD_ID_LOCK, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04852       R_RES_FLAG_DEF, NULL, R_LOCK_lib_finish, \
04853       (void *(*)(void *))R_LOCK_get_default_method, NULL }
04854 
04859 #define R_CR_RES_PKEY_PRINT \
04860     { R_RES_MOD_ID_PKEY, R_RES_IMPL_ID_PRINT_FUNC, \
04861       R_RES_SUB_ID_DEF, R_RES_FLAG_DEF, NULL, NULL, NULL, \
04862       (void *(*)(void *))R_PKEY_get_print_func }
04863 
04870 #define R_CR_RES_PKEY_RSA \
04871     { R_RES_MOD_ID_PKEY, R_RES_IMPL_ID_DEF, R_PKEY_TYPE_RSA, \
04872       R_RES_FLAG_DEF, NULL, NULL, (void *(*)(void *))R_PKEY_pk_method, \
04873       NULL }
04874 
04882 #define R_CR_RES_PKEY_DSA \
04883     { R_RES_MOD_ID_PKEY, R_RES_IMPL_ID_DEF, R_PKEY_TYPE_DSA, \
04884       R_RES_FLAG_DEF, NULL, NULL, (void *(*)(void *))R_PKEY_pk_method, \
04885       NULL }
04886 
04894 #define R_CR_RES_PKEY_DH \
04895     { R_RES_MOD_ID_PKEY, R_RES_IMPL_ID_DEF, R_PKEY_TYPE_DH, \
04896       R_RES_FLAG_DEF, NULL, NULL, (void *(*)(void *))R_PKEY_pk_method, \
04897       NULL }
04898 
04905 #define R_CR_RES_RAND \
04906     { R_RES_MOD_ID_RAND, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04907       R_RES_FLAG_DEF, NULL, \
04908       (int (*)(R_RES_LIST *, R_RES_ITEM *, void **))R_rand_lib_cleanup, \
04909       (void *(*)(void *))R_rand_get_default, NULL }
04910 
04917 #define R_CR_RES_TIME \
04918     { R_RES_MOD_ID_TIME, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04919       R_RES_FLAG_DEF, NULL, NULL, \
04920       (void *(*)(void *))R_TIME_get_time_mi_method, NULL }
04921 
04927 #define R_CR_RES_COMMON_ERROR_STRINGS \
04928     { R_RES_MOD_ID_LIBRARY, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_ERROR_STRINGS, \
04929       R_RES_FLAG_DEF, NULL, NULL, NULL, \
04930       (void *(*)(void *))R_LIB_CTX_com_err_str_table }
04931 
04939 #define R_CR_RES_CRYPTO_REASON_STRINGS \
04940     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_REASON_STRINGS, \
04941           R_RES_FLAG_DEF, NULL, NULL, NULL, \
04942       (void *(*)(void *))R_CR_get_reason_string_table }
04943 
04951 #define R_CR_RES_CRYPTO_FUNCTION_NAMES \
04952     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_FUNCTION_STRINGS,\
04953           R_RES_FLAG_DEF, NULL, NULL, NULL,\
04954       (void *(*)(void *))R_CR_get_function_string_table }
04955 
04963 #define R_CR_RES_CRYPTO_DETAIL_STRINGS \
04964     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DETAIL_STRINGS, \
04965           R_RES_FLAG_DEF, NULL, NULL, NULL, \
04966       (void *(*)(void *))R_CR_get_detail_string_table }
04967 
04971 #define R_CR_RES_END_OF_LIST \
04972     { R_RES_MOD_ID_RES_LIST, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
04973       R_RES_LIST_FLAG_STATIC, NULL, R_RES_LIST_lib_finish, NULL, NULL }
04974 
04975 
04976 #ifndef NO_BIO
04977 
04978 extern BIO_METHOD * R_CDECL r_cr_digest_get_bio_method();
04979 extern BIO_METHOD * R_CDECL r_cr_encrypt_get_bio_method();
04980 extern BIO_METHOD * R_CDECL r_cr_decrypt_get_bio_method();
04981 extern BIO_METHOD * R_CDECL r_cr_cipher_get_bio_method();
04982 
04986 #define R_CR_RES_BIO_DIGEST                                    \
04987     { R_RES_MOD_ID_BIO, BIO_TYPE_CR, R_CR_TYPE_DIGEST,         \
04988       R_RES_FLAG_DEF, NULL, NULL,                              \
04989       (void *(*)(void *))r_cr_digest_get_bio_method, NULL }
04990 
04994 #define R_CR_RES_BIO_ENCRYPT                                   \
04995     { R_RES_MOD_ID_BIO, BIO_TYPE_CIPHER, R_CR_SUB_ENCRYPT,     \
04996       R_RES_FLAG_DEF, NULL, NULL,                              \
04997       (void *(*)(void *))r_cr_encrypt_get_bio_method, NULL }
04998 
05002 #define R_CR_RES_BIO_DECRYPT                                   \
05003     { R_RES_MOD_ID_BIO, BIO_TYPE_CIPHER, R_CR_SUB_DECRYPT,     \
05004       R_RES_FLAG_DEF, NULL, NULL,                              \
05005       (void *(*)(void *))r_cr_decrypt_get_bio_method, NULL }
05006 
05011 #define R_CR_RES_BIO_CIPHER                                    \
05012     { R_RES_MOD_ID_BIO, BIO_TYPE_CIPHER,                       \
05013       R_CR_SUB_ENCRYPT | R_CR_SUB_DECRYPT, R_RES_FLAG_DEF,     \
05014       NULL, NULL,                                              \
05015       (void *(*)(void *))r_cr_cipher_get_bio_method, NULL }
05016 
05017 #endif /* !NO_BIO */
05018 
05023 #include "cryp_macros.h"
05024 
05040 #if !defined(NO_R_CR_METH_TABLE)
05041 int R_CDECL R_CR_CTX_new(R_LIB_CTX *lib_ctx, R_RES_FLAG flag,
05042                          R_CR_CTX **crypto_ctx);
05043 #endif /* !defined(NO_R_CR_METH_TABLE) */
05044 
05045 #if !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE)
05046 int R_CDECL R_CR_CTX_free(R_CR_CTX *ctx);
05047 
05048 int R_CDECL R_CR_new(R_CR_CTX *ctx, R_CR_ALG_TYPE alg_type,
05049             R_CR_ALG_ID alg_id, R_CR_ALG_SUB alg_sub, R_CR **crypto);
05050 int R_CDECL R_CR_dup(R_CR *crypto, R_CR **new_crypto);
05051 int R_CDECL R_CR_free(R_CR *crypto);
05062 int R_CDECL R_CR_encrypt_init(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
05063 int R_CDECL R_CR_encrypt(R_CR *crypto, unsigned char *data,
05064     unsigned int dlen, unsigned char *out, unsigned int *olen);
05065 int R_CDECL R_CR_encrypt_update(R_CR *crypto, unsigned char *data,
05066     unsigned int dlen, unsigned char *out, unsigned int *olen);
05067 int R_CDECL R_CR_encrypt_final(R_CR *crypto,unsigned char *out, unsigned int *olen);
05068 
05069 int R_CDECL R_CR_decrypt_init(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
05070 int R_CDECL R_CR_decrypt(R_CR *crypto, unsigned char *data,
05071     unsigned int dlen, unsigned char *out, unsigned int *olen);
05072 int R_CDECL R_CR_decrypt_update(R_CR *crypto, unsigned char *data,
05073     unsigned int dlen, unsigned char *out, unsigned int *olen);
05074 int R_CDECL R_CR_decrypt_final(R_CR *crypto,unsigned char *out, unsigned int *olen);
05085 int R_CDECL R_CR_sign_init(R_CR *crypto, R_PKEY *key);
05086 int R_CDECL R_CR_sign(R_CR *crypto, unsigned char *data, unsigned int dlen,
05087     unsigned char *out, unsigned int *olen);
05088 int R_CDECL R_CR_sign_update(R_CR *crypto, unsigned char *data, unsigned int dlen);
05089 int R_CDECL R_CR_sign_final(R_CR *crypto,unsigned char *out, unsigned int *olen);
05090 
05091 int R_CDECL R_CR_verify_init(R_CR *crypto, R_PKEY *key);
05092 int R_CDECL R_CR_verify(R_CR *crypto, unsigned char *data,
05093     unsigned int dlen, unsigned char *signature, unsigned int slen,
05094     int *result);
05095 int R_CDECL R_CR_verify_update(R_CR *crypto, unsigned char *data,
05096         unsigned int dlen);
05097 int R_CDECL R_CR_verify_final(R_CR *crypto, unsigned char *signature,
05098         unsigned int sig_len, int *result);
05110 int R_CDECL R_CR_asym_encrypt_init(R_CR *crypto, R_PKEY *key);
05111 int R_CDECL R_CR_asym_encrypt(R_CR *crypto, unsigned char *data,
05112         unsigned int dlen, unsigned char *out,
05113                 unsigned int *olen);
05114 int R_CDECL R_CR_asym_decrypt_init(R_CR *crypto, R_PKEY *key);
05115 int R_CDECL R_CR_asym_decrypt(R_CR *crypto, unsigned char *data,
05116     unsigned int dlen, unsigned char *out, unsigned int *olen);
05129 int R_CDECL R_CR_digest_init(R_CR *crypto);
05130 int R_CDECL R_CR_digest(R_CR *crypto, unsigned char *data,
05131     unsigned int dlen, unsigned char *out,
05132     unsigned int *out_len);
05133 int R_CDECL R_CR_digest_update(R_CR *crypto, unsigned char *data,
05134     unsigned int dlen);
05135 int R_CDECL R_CR_digest_final(R_CR *crypto, unsigned char *out,
05136     unsigned int *olen);
05137 
05138 int R_CDECL R_CR_mac_init(R_CR *crypto, R_SKEY *key);
05139 int R_CDECL R_CR_mac(R_CR *crypto, unsigned char *data,
05140     unsigned int dlen, unsigned char *out,
05141     unsigned int *olen);
05142 int R_CDECL R_CR_mac_update(R_CR *crypto, unsigned char *data,
05143     unsigned int dlen);
05144 int R_CDECL R_CR_mac_final(R_CR *crypto, unsigned char *out,
05145     unsigned int *olen);
05146 
05147 int R_CDECL R_CR_verify_mac_init(R_CR *crypto, R_SKEY *key);
05148 int R_CDECL R_CR_verify_mac(R_CR *crypto, unsigned char *data,
05149     unsigned int dlen, unsigned char *mac, unsigned int mac_len,
05150     int *result);
05151 int R_CDECL R_CR_verify_mac_update(R_CR *crypto, unsigned char *data,
05152         unsigned int dlen);
05153 int R_CDECL R_CR_verify_mac_final(R_CR *crypto, unsigned char *mac,
05154         unsigned int mac_len, int *result);
05167 int R_CDECL R_CR_key_exchange_init(R_CR *crypto, R_PKEY *params);
05168 int R_CDECL R_CR_key_exchange_phase_1(R_CR *crypto, unsigned char *out,
05169     unsigned int *olen);
05170 int R_CDECL R_CR_key_exchange_phase_2(R_CR *crypto, unsigned char *data,
05171     unsigned int dlen, unsigned char *out, unsigned int * olen);
05185 int R_CDECL R_CR_generate_key_init(R_CR *crypto);
05186 int R_CDECL R_CR_generate_key(R_CR *crypto, R_PKEY **key);
05187 
05188 int R_CDECL R_CR_generate_parameter_init(R_CR *crypto);
05189 int R_CDECL R_CR_generate_parameter(R_CR *crypto, R_PKEY **key);
05190 
05204 int R_CDECL R_CR_random_seed(R_CR *crypto, unsigned char *bytes, unsigned int len);
05205 int R_CDECL R_CR_random_bytes(R_CR *crypto, unsigned int  dlen,
05206     unsigned char *obuf, unsigned int *olen);
05210 #endif /* !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE) */
05211 
05217 int R_CDECL R_CR_get_info(R_CR *crypto, int id, void *param);
05218 int R_CDECL R_CR_set_info(R_CR *crypto, int id, void *param);
05219 
05220 int R_CDECL R_CR_CTX_get_info(R_CR_CTX *ctx, int id, void *param);
05221 int R_CDECL R_CR_CTX_set_info(R_CR_CTX *ctx, int id, void *param);
05222 
05223 int R_CDECL R_CR_CTX_alg_supported(R_CR_CTX *ctx, int alg_type, int alg_id,
05224     int alg_sub, int *is_supported);
05225 
05226 const R_CR_SIGN_VFY_MAP * R_CDECL R_CR_get_default_signature_map(void *imp_data);
05227 
05228 int R_CDECL R_CR_CTX_ids_to_sig_id(R_CR_CTX *ctx, int dig_id, int pkey_id, int *sig_id);
05229 int R_CDECL R_CR_CTX_ids_from_sig_id(R_CR_CTX *ctx, int sig_id, int *dig_id,
05230     int *pkey_id);
05243 #if !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE)
05244 int R_CDECL R_CR_get_error(R_CR *crypto, int *data);
05245 int R_CDECL R_CR_get_reason(R_CR *crypto, int *data);
05246 int R_CDECL R_CR_get_detail(R_CR *crypto, int *data);
05247 int R_CDECL R_CR_get_function(R_CR *crypto, int *data);
05248 int R_CDECL R_CR_get_line(R_CR *crypto, int *data);
05249 
05250 int R_CDECL R_CR_get_file(R_CR *crypto, char **data);
05251 int R_CDECL R_CR_get_error_string(R_CR *crypto, char **data);
05252 int R_CDECL R_CR_get_reason_string(R_CR *crypto, char **data);
05253 int R_CDECL R_CR_get_detail_string(R_CR *crypto, char **data);
05254 int R_CDECL R_CR_get_function_string(R_CR *crypto, char **data);
05255 #endif /* !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE) */
05256 
05257 
05258 #if !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE)
05259 /* error related strings */
05260 R_STRTBL * R_CDECL R_CR_get_reason_string_table(void *imp_data);
05261 R_STRTBL * R_CDECL R_CR_get_detail_string_table(void *imp_data);
05262 R_STRTBL * R_CDECL R_CR_get_function_string_table(void *imp_data);
05263 #endif /* !defined(NO_R_CR_FUNC) && !defined(NO_R_CR_METH_TABLE) */
05264 
05265 #ifndef NO_BIO
05266 BIO * R_CDECL BIO_new_CR_MD(R_LIB_CTX *ctx, int flag, int id);
05267 #endif /* NO_BIO */
05268 
05277 int R_CDECL R_CR_ID_from_string(char *str, R_CR_ALG_ID *type);
05278 int R_CDECL R_CR_ID_to_string(R_CR_ALG_ID type, unsigned int max_str_len, char *str);
05279 int R_CDECL R_CR_ID_sign_to_string(R_CR_ALG_ID sign_type, unsigned int max_str_len,
05280      char *str);
05281 int R_CDECL R_CR_TYPE_from_string(char *str, R_CR_ALG_TYPE *type);
05282 int R_CDECL R_CR_TYPE_to_string(R_CR_ALG_TYPE type, unsigned int max_str_len, char *str);
05283 int R_CDECL R_CR_SUB_from_string(char *str, R_CR_ALG_SUB *type);
05284 int R_CDECL R_CR_SUB_to_string(R_CR_ALG_SUB type, unsigned int max_str_len, char *str);
05288 /* Default method */
05293 R_CR_METHOD * R_CDECL R_CR_get_default_method(void *imp_data);
05294 R_CR_IMP_METHOD * R_CDECL R_CR_get_default_imp_method(void *imp_data);
05317 #define R_CR_RES_CRYPTO_CUSTOM_METHOD(meth_fn, alg_fn) \
05318     { R_RES_MOD_ID_CRYPTO, R_RES_IMPL_ID_DEF, R_RES_SUB_ID_DEF, \
05319       R_RES_FLAG_DEF, NULL, NULL, \
05320       (void *(*)(void *))meth_fn, \
05321       (void *(*)(void *))alg_fn }
05322 
05337 #define R_CR_DEFINE_CUSTOM_CIPHER_LIST(list, fn) \
05338     static R_CR_IMP_METHOD *fn(void)\
05339         { return((R_CR_IMP_METHOD *)list); } typedef int _dummy_int ## fn
05340 
05355 #define R_CR_DEFINE_CUSTOM_METHOD_TABLE(list, fn) \
05356     static R_CR_METHOD *fn(void *imp_data)\
05357     { return((R_CR_METHOD *)&list); }  typedef int _dummy_int ## fn
05358 
05366 #ifdef FIPS140_ONLY
05367 #include "r_cr_nist.h"
05368 #endif
05369 
05370 #ifdef  __cplusplus
05371 }
05372 #endif
05373 #endif /* HEADER_COMMON_CRYP_MOD_H */
05374 
05375 

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1