| RSA BSAFE Cert-C Micro Edition |
The power of PKI for the smallest of devices |
00001 /* $Id: cryp_meth.h,v 1.19 2002/08/04 23:35:43 cmueller 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 /**
00013 * @file cryp_meth.h
00014 * This file contains the cryptographic method table structures and
00015 * method defines.
00016 */
00017
00018 #ifndef HEADER_COMMON_CRYP_METH_H
00019 #define HEADER_COMMON_CRYP_METH_H
00020
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024
00025 #include "cryp_mod.h"
00026
00027 /**
00028 * This structure contains the set of function pointers which are used
00029 * as a method table to map calls to the cryptographic Application
00030 * Programming Interface (API) functions through to their implementations.
00031 *
00032 * The functions provide support for <tt>init</tt>, <tt>update</tt>,
00033 * <tt>final</tt> and single update/final operations which are required by
00034 * PKCS #11. With this, individual functions can be mapped through to
00035 * hardware devices that provide a PKCS #11 interface.
00036 *
00037 */
00038 struct r_cr_method_st
00039 {
00040 /** @see R_CR_CTX_new(). */
00041 int (*ctx_new)(R_LIB_CTX *lib_ctx, R_RES_FLAG flag, R_CR_CTX **ctx);
00042
00043 /** @see R_CR_CTX_free(). */
00044 int (*ctx_free)(R_CR_CTX *ctx);
00045
00046 /** @see R_CR_new(). */
00047 int (*crypto_new)(R_CR_CTX *crypto_ctx, int alg_type, int alg_id,
00048 int alg_sub, R_CR **crypto);
00049
00050 /** @see R_CR_dup(). */
00051 int (*crypto_dup)(R_CR *crypto, R_CR **new_crypto);
00052
00053 /** @see R_CR_free(). */
00054 int (*crypto_free)(R_CR *crypto);
00055
00056 /**
00057 * @see R_CR_get_error(), R_CR_get_reason(), R_CR_get_detail(),
00058 * R_CR_get_function(), R_CR_get_line(), R_CR_get_file(),
00059 * R_CR_get_error_string(), R_CR_get_reason_string(),
00060 * R_CR_get_detail_string() and R_CR_get_function_string().
00061 */
00062 int (*crypto_get_errinfo)(R_CR *crypto, int what, void **data);
00063
00064 /** @see R_CR_set_info(). */
00065 int (*crypto_getinfo)(R_CR *crypto, int id, void **param);
00066
00067 /** @see R_CR_get_info(). */
00068 int (*crypto_setinfo)(R_CR *crypto, int id, void *param);
00069
00070 /** @see R_CR_encrypt_init(). */
00071 int (*encrypt_init)(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
00072
00073 /** @see R_CR_encrypt(). */
00074 int (*encrypt)(R_CR *crypto, unsigned char *data,
00075 unsigned int data_len, unsigned char *out,
00076 unsigned int *out_len);
00077
00078 /** @see R_CR_encrypt_update(). */
00079 int (*encrypt_update)(R_CR *crypto, unsigned char *data,
00080 unsigned int dlen, unsigned char *out, unsigned int *olen);
00081
00082 /** @see R_CR_encrypt_final(). */
00083 int (*encrypt_final)(R_CR *crypto, unsigned char *out,
00084 unsigned int *olen);
00085
00086 /** @see R_CR_decrypt_init(). */
00087 int (*decrypt_init)(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
00088
00089 /** @see R_CR_decrypt(). */
00090 int (*decrypt)(R_CR *crypto, unsigned char *data,
00091 unsigned int data_len, unsigned char *out,
00092 unsigned int *out_len);
00093
00094 /** @see R_CR_decrypt_update(). */
00095 int (*decrypt_update)(R_CR *crypto, unsigned char *data,
00096 unsigned int dlen, unsigned char *out, unsigned int *olen);
00097
00098 /** @see R_CR_decrypt_final(). */
00099 int (*decrypt_final)(R_CR *crypto, unsigned char *out,
00100 unsigned int *olen);
00101
00102 /** @see R_CR_sign_init(). */
00103 int (*sign_init)(R_CR *crypto, R_PKEY *key);
00104
00105 /** @see R_CR_sign(). */
00106 int (*sign)(R_CR *crypto, unsigned char *data,
00107 unsigned int dlen, unsigned char *out, unsigned int *olen);
00108
00109 /** @see R_CR_sign_update(). */
00110 int (*sign_update)(R_CR *crypto, unsigned char *data,
00111 unsigned int data_len);
00112
00113 /** @see R_CR_sign_final(). */
00114 int (*sign_final)(R_CR *crypto,unsigned char *out,
00115 unsigned int *out_len);
00116
00117 /** @see R_CR_verify_init(). */
00118 int (*verify_init)(R_CR *crypto, R_PKEY *key);
00119
00120 /** @see R_CR_verify(). */
00121 int (*verify)(R_CR *crypto, unsigned char *data,
00122 unsigned int dlen, unsigned char *signature,
00123 unsigned int slen, int *result);
00124
00125 /** @see R_CR_verify_update(). */
00126 int (*verify_update)(R_CR *crypto, unsigned char *data,
00127 unsigned int data_len);
00128
00129 /** @see R_CR_verify_final(). */
00130 int (*verify_final)(R_CR *crypto, unsigned char *signature,
00131 unsigned int sig_len, int *result);
00132
00133 /** @see R_CR_asym_encrypt_init(). */
00134 int (*asym_encrypt_init)(R_CR *crypto, R_PKEY *key);
00135
00136 /** @see R_CR_asym_encrypt(). */
00137 int (*asym_encrypt)(R_CR *crypto, unsigned char *data,
00138 unsigned int data_len, unsigned char *out,
00139 unsigned int *out_len);
00140
00141 /** @see R_CR_asym_decrypt_init(). */
00142 int (*asym_decrypt_init)(R_CR *crypto, R_PKEY *key);
00143
00144 /** @see R_CR_asym_decrypt(). */
00145 int (*asym_decrypt)(R_CR *crypto, unsigned char *data,
00146 unsigned int data_len, unsigned char *out,
00147 unsigned int *out_len);
00148
00149 /** @see R_CR_digest_init(). */
00150 int (*digest_init)(R_CR *crypto);
00151
00152 /** @see R_CR_digest(). */
00153 int (*digest)(R_CR *crypto, unsigned char *data,
00154 unsigned int data_len, unsigned char *out,
00155 unsigned int *out_len);
00156
00157 /** @see R_CR_digest_update(). */
00158 int (*digest_update)(R_CR *crypto, unsigned char *data,
00159 unsigned int data_len);
00160
00161 /** @see R_CR_digest_final(). */
00162 int (*digest_final)(R_CR *crypto, unsigned char *out,
00163 unsigned int *olen);
00164
00165 /** @see R_CR_mac_init(). */
00166 int (*mac_init)(R_CR *crypto, R_SKEY *key);
00167
00168 /** @see R_CR_mac(). */
00169 int (*mac)(R_CR *crypto, unsigned char *data,
00170 unsigned int data_len, unsigned char *out,
00171 unsigned int *olen);
00172
00173 /** @see R_CR_mac_update(). */
00174 int (*mac_update)(R_CR *crypto, unsigned char *data,
00175 unsigned int data_len);
00176
00177 /** @see R_CR_mac_final(). */
00178 int (*mac_final)(R_CR *crypto, unsigned char *out,
00179 unsigned int *olen);
00180
00181 /** @see R_CR_verify_mac_init(). */
00182 int (*verify_mac_init)(R_CR *crypto, R_SKEY *key);
00183
00184 /** @see R_CR_verify_mac(). */
00185 int (*verify_mac)(R_CR *crypto, unsigned char *data,
00186 unsigned int data_len, unsigned char *mac,
00187 unsigned int mac_len, int *result);
00188
00189 /** @see R_CR_verify_mac_update(). */
00190 int (*verify_mac_update)(R_CR *crypto, unsigned char *data,
00191 unsigned int data_len);
00192
00193 /** @see R_CR_verify_mac_final(). */
00194 int (*verify_mac_final)(R_CR *crypto, unsigned char *mac,
00195 unsigned int mac_len, int *result);
00196
00197 /** @see R_CR_key_exchange_init(). */
00198 int (*key_exchange_init)(R_CR *crypto, R_PKEY *key);
00199
00200 /** @see R_CR_key_exchange_phase_1(). */
00201 int (*key_exchange_phase_1)(R_CR *crypto, unsigned char *out,
00202 unsigned int *olen);
00203
00204 /** @see R_CR_key_exchange_phase_2(). */
00205 int (*key_exchange_phase_2)(R_CR *crypto, unsigned char *data,
00206 unsigned int dlen, unsigned char *out, unsigned int * olen);
00207
00208 /** @see R_CR_generate_key_init(). */
00209 int (*generate_key_init)(R_CR *crypto);
00210
00211 /** @see R_CR_generate_key(). */
00212 int (*generate_key)(R_CR *crypto, R_PKEY **key);
00213
00214 /** @see R_CR_generate_parameter_init(). */
00215 int (*generate_params_init)(R_CR *crypto);
00216
00217 /** @see R_CR_generate_parameter(). */
00218 int (*generate_params)(R_CR *crypto, R_PKEY **params);
00219
00220 /** @see R_CR_random_seed(). */
00221 int (*random_seed)(R_CR *crypto, unsigned char *bytes,
00222 unsigned int len);
00223
00224 /** @see R_CR_random_bytes(). */
00225 int (*gen_rand)(R_CR *crypto, unsigned int len,
00226 unsigned char *out, unsigned int *olen);
00227 };
00228
00229
00230 /**
00231 * These functions are the intermediate function level that should
00232 * correspond to the method table on an almost 1:1 basis. As a result,
00233 * <tt>r_crm r - RSA - cr -CRYPTO - m</tt> method prefix.
00234 */
00235 int r_crm_not_implemented(void);
00236
00237 int r_crm_ctx_new(R_LIB_CTX *lib_ctx, R_RES_FLAG flag, R_CR_CTX **crypto_ctx);
00238 int r_crm_ctx_free(R_CR_CTX *crypto_ctx);
00239
00240 int r_crm_new(R_CR_CTX *crypto_ctx, R_CR_ALG_TYPE alg_type, R_CR_ALG_ID alg_id,
00241 R_CR_ALG_SUB alg_sub, R_CR **crypto);
00242 int r_crm_dup(R_CR *crypto, R_CR **new_crypto);
00243 int r_crm_free(R_CR *crypto);
00244
00245 int r_crm_digest_init(R_CR *crypto);
00246 int r_crm_digest(R_CR *crypto, unsigned char *data,
00247 unsigned int data_len, unsigned char *out,
00248 unsigned int *out_len);
00249 int r_crm_digest_update(R_CR *crypto, unsigned char *data,
00250 unsigned int data_len);
00251 int r_crm_digest_final(R_CR *crypto, unsigned char *out,
00252 unsigned int *olen);
00253
00254 int r_crm_mac_init(R_CR *crypto, R_SKEY *key);
00255 int r_crm_mac(R_CR *crypto, unsigned char *data,
00256 unsigned int data_len, unsigned char *out,
00257 unsigned int *olen);
00258 int r_crm_mac_update(R_CR *crypto, unsigned char *data,
00259 unsigned int data_len);
00260 int r_crm_mac_final(R_CR *crypto, unsigned char *out,
00261 unsigned int *olen);
00262
00263 int r_crm_verify_mac(R_CR *crypto, unsigned char *data,
00264 unsigned int data_len, unsigned char *mac, unsigned int mac_len,
00265 int *result);
00266 int r_crm_verify_mac_update(R_CR *crypto, unsigned char *data,
00267 unsigned int data_len);
00268 int r_crm_verify_mac_final(R_CR *crypto, unsigned char *mac,
00269 unsigned int mac_len, int *result);
00270
00271 int r_crm_encrypt_init(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
00272 int r_crm_decrypt_init(R_CR *crypto, R_SKEY *key, R_ITEM *iv);
00273 int r_crm_cipher(R_CR *crypto, unsigned char *data,
00274 unsigned int data_len, unsigned char *out, unsigned int *out_len);
00275 int r_crm_cipher_update(R_CR *crypto, unsigned char *data,
00276 unsigned int dlen, unsigned char *out, unsigned int *olen);
00277 int r_crm_cipher_final(R_CR *crypto, unsigned char *out,unsigned int *olen);
00278
00279 int r_crm_asym_init(R_CR *crypto, R_PKEY *key);
00280 int r_crm_asym_enc(R_CR *crypto, unsigned char *data,
00281 unsigned int data_len, unsigned char *out,
00282 unsigned int *out_len);
00283 int r_crm_asym_dec(R_CR *crypto, unsigned char *data,
00284 unsigned int data_len, unsigned char *out, unsigned int *out_len);
00285
00286 int r_crm_ke_init(R_CR *crypto, R_PKEY *key);
00287 int r_crm_ke_phase_1(R_CR *crypto, unsigned char *out,
00288 unsigned int *olen);
00289 int r_crm_ke_phase_2(R_CR *crypto, unsigned char *data,
00290 unsigned int dlen, unsigned char *out, unsigned int * olen);
00291
00292 int r_crm_kgen_init(R_CR *crypto);
00293 int r_crm_generate_key(R_CR *crypto, R_PKEY **key);
00294
00295 int r_crm_pgen_init(R_CR *crypto);
00296 int r_crm_generate_params(R_CR *crypto, R_PKEY **params);
00297
00298 int r_crm_sign_vfy_init(R_CR *crypto, R_PKEY *key);
00299 int r_crm_sign(R_CR *crypto, unsigned char *data, unsigned int dlen,
00300 unsigned char *out, unsigned int *olen);
00301 int r_crm_sign_update(R_CR *crypto, unsigned char *data, unsigned int data_len);
00302 int r_crm_sign_final(R_CR *crypto,unsigned char *out, unsigned int *out_len);
00303 int r_crm_verify(R_CR *crypto, unsigned char *data, unsigned int dlen,
00304 unsigned char *signature, unsigned int slen, int *result);
00305 int r_crm_verify_update(R_CR *crypto, unsigned char *data,
00306 unsigned int data_len);
00307 int r_crm_verify_final(R_CR *crypto, unsigned char *signature,
00308 unsigned int sig_len, int *result);
00309
00310 int r_crm_random_seed(R_CR *crypto, unsigned char *seed, unsigned int len);
00311 int r_crm_gen_rand(R_CR *crypto, unsigned int len,
00312 unsigned char *out, unsigned int *olen);
00313
00314 int r_crm_get_errinfo(R_CR *crypto, int what, void **data);
00315
00316 int r_crm_get_info(R_CR *crypto, int id, void **param);
00317 int r_crm_set_info(R_CR *crypto, int id, void *param);
00318
00319 int r_crm_function_lookup(R_CR *crypto, R_CR_IMP_METHOD *table,
00320 R_CR_IMP_METHOD **imp_meth);
00321
00322
00323 #ifdef __cplusplus
00324 }
00325 #endif
00326
00327 #endif /* HEADER_COMMON_CRYP_METH_H */