yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame] | 1 | /* crypto/evp/evp.h */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. |
| 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: |
| 26 | * 1. Redistributions of source code must retain the copyright |
| 27 | * notice, this list of conditions and the following disclaimer. |
| 28 | * 2. Redistributions in binary form must reproduce the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer in the |
| 30 | * documentation and/or other materials provided with the distribution. |
| 31 | * 3. All advertising materials mentioning features or use of this software |
| 32 | * must display the following acknowledgement: |
| 33 | * "This product includes cryptographic software written by |
| 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. |
| 52 | * |
| 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] |
| 57 | */ |
| 58 | |
| 59 | #ifndef HEADER_ENVELOPE_H |
| 60 | #define HEADER_ENVELOPE_H |
| 61 | |
| 62 | #include "ossl_typ.h" |
| 63 | #include "kal_public_defs.h" |
| 64 | |
| 65 | #ifdef __cplusplus |
| 66 | extern "C" { |
| 67 | #endif |
| 68 | |
| 69 | #define ASN1_PKEY_ALIAS 0x1 |
| 70 | |
| 71 | #define EVP_PKEY_EC 408 |
| 72 | #define EVP_PKEY_NONE 0 |
| 73 | #define EVP_PKEY_ALG_CTRL 0x1000 |
| 74 | |
| 75 | #define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ |
| 76 | |
| 77 | |
| 78 | struct env_md_st |
| 79 | { |
| 80 | //int type; |
| 81 | //int pkey_type; |
| 82 | int md_size; |
| 83 | //unsigned long flags; |
| 84 | int (*init)(EVP_MD_CTX *ctx); |
| 85 | int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count); |
| 86 | int (*final)(EVP_MD_CTX *ctx,unsigned char *md); |
| 87 | //int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from); |
| 88 | //int (*cleanup)(EVP_MD_CTX *ctx); |
| 89 | |
| 90 | /* FIXME: prototype these some day */ |
| 91 | //int (*sign)(int type, const unsigned char *m, unsigned int m_length, |
| 92 | // unsigned char *sigret, unsigned int *siglen, void *key); |
| 93 | //int (*verify)(int type, const unsigned char *m, unsigned int m_length, |
| 94 | // const unsigned char *sigbuf, unsigned int siglen, |
| 95 | // void *key); |
| 96 | //int required_pkey_type[5]; /*EVP_PKEY_xxx */ |
| 97 | int block_size; |
| 98 | int ctx_size; /* how big does the ctx->md_data need to be */ |
| 99 | /* control function */ |
| 100 | //int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); |
| 101 | } /* EVP_MD */; |
| 102 | |
| 103 | |
| 104 | struct env_md_ctx_st |
| 105 | { |
| 106 | const EVP_MD *digest; |
| 107 | //ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */ |
| 108 | unsigned long flags; |
| 109 | void *md_data; |
| 110 | /* Public key context for sign/verify */ |
| 111 | //EVP_PKEY_CTX *pctx; |
| 112 | /* Update function: usually copied from EVP_MD */ |
| 113 | int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count); |
| 114 | } /* EVP_MD_CTX */; |
| 115 | |
| 116 | /* values for EVP_MD_CTX flags */ |
| 117 | |
| 118 | #define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called |
| 119 | * once only */ |
| 120 | //#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been |
| 121 | // * cleaned */ |
| 122 | #define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data |
| 123 | * in EVP_MD_CTX_cleanup */ |
| 124 | |
| 125 | //#define EVP_MD_CTX_FLAG_NO_INIT 0x0100 /* Don't initialize md_data */ |
| 126 | |
| 127 | |
| 128 | int EVP_MD_size(const EVP_MD *md); |
| 129 | int EVP_MD_block_size(const EVP_MD *md); |
| 130 | EVP_MD_CTX *EVP_MD_CTX_new(void); |
| 131 | int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); |
| 132 | void EVP_MD_CTX_free(EVP_MD_CTX *ctx); |
| 133 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx); |
| 134 | int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); |
| 135 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); |
| 136 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in); |
| 137 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx,int flags); |
| 138 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type);//, ENGINE *impl); |
| 139 | int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, |
| 140 | size_t cnt); |
| 141 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); |
| 142 | int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); |
| 143 | int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in); |
| 144 | int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
| 145 | int EVP_Digest(const void *data, kal_uint32 data_len, |
| 146 | unsigned char *digest, unsigned int *digest_len, const EVP_MD *md); |
| 147 | int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); |
| 148 | |
| 149 | |
| 150 | const EVP_MD *EVP_sha256(void); |
| 151 | const EVP_MD *EVP_sha1(void); |
| 152 | const EVP_MD *EVP_SHA384(void); |
| 153 | |
| 154 | /* values for EVP_MD_CTX flags */ |
| 155 | |
| 156 | EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id); |
| 157 | EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey); |
| 158 | int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); |
| 159 | int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); |
| 160 | int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); |
| 161 | int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); |
| 162 | int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, |
| 163 | int cmd, int p1, void *p2); |
| 164 | int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); |
| 165 | int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); |
| 166 | int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); |
| 167 | int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); |
| 168 | int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); |
| 169 | int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); |
| 170 | int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); |
| 171 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(int type); //ENGINE **pe, int type); |
| 172 | |
| 173 | |
| 174 | EVP_PKEY *EVP_PKEY_new(void); |
| 175 | int EVP_PKEY_up_ref(EVP_PKEY *pkey); |
| 176 | void EVP_PKEY_free(EVP_PKEY *pkey); |
| 177 | void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); |
| 178 | int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); |
| 179 | |
| 180 | |
| 181 | #define EVP_PKEY_CTRL_PEER_KEY 2 |
| 182 | |
| 183 | #define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC, (char *)(eckey)) |
| 184 | |
| 185 | /* Operation codes. */ |
| 186 | |
| 187 | #define EVP_PKEY_OP_UNDEFINED 0 |
| 188 | #define EVP_PKEY_OP_PARAMGEN (1<<1) |
| 189 | #define EVP_PKEY_OP_KEYGEN (1<<2) |
| 190 | #define EVP_PKEY_OP_SIGN (1<<3) |
| 191 | #define EVP_PKEY_OP_VERIFY (1<<4) |
| 192 | #define EVP_PKEY_OP_VERIFYRECOVER (1<<5) |
| 193 | #define EVP_PKEY_OP_SIGNCTX (1<<6) |
| 194 | #define EVP_PKEY_OP_VERIFYCTX (1<<7) |
| 195 | #define EVP_PKEY_OP_ENCRYPT (1<<8) |
| 196 | #define EVP_PKEY_OP_DECRYPT (1<<9) |
| 197 | #define EVP_PKEY_OP_DERIVE (1<<10) |
| 198 | |
| 199 | |
| 200 | /* Error codes for the EVP functions. */ |
| 201 | |
| 202 | /* Function codes. */ |
| 203 | #define EVP_F_EVP_DIGESTINIT_EX 128 |
| 204 | #define EVP_F_EVP_MD_CTX_COPY_EX 110 |
| 205 | #define EVP_F_EVP_MD_SIZE 162 |
| 206 | #define EVP_F_INT_CTX_NEW 157 |
| 207 | #define EVP_F_EVP_PKEY_KEYGEN 146 |
| 208 | #define EVP_F_EVP_PKEY_KEYGEN_INIT 147 |
| 209 | #define EVP_F_EVP_PKEY_PARAMGEN 148 |
| 210 | #define EVP_F_EVP_PKEY_PARAMGEN_INIT 149 |
| 211 | #define EVP_F_EVP_PKEY_CTX_CTRL 137 |
| 212 | #define EVP_F_EVP_PKEY_DERIVE 153 |
| 213 | #define EVP_F_EVP_PKEY_DERIVE_INIT 154 |
| 214 | #define EVP_F_EVP_PKEY_DERIVE_SET_PEER 155 |
| 215 | #define EVP_F_EVP_PKEY_NEW 106 |
| 216 | #define EVP_F_PKEY_SET_TYPE 158 |
| 217 | #define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 |
| 218 | |
| 219 | |
| 220 | /* Reason codes. */ |
| 221 | #define EVP_R_INPUT_NOT_INITIALIZED 111 |
| 222 | #define EVP_R_MESSAGE_DIGEST_IS_NULL 159 |
| 223 | #define EVP_R_UNSUPPORTED_ALGORITHM 156 |
| 224 | #define EVP_R_COMMAND_NOT_SUPPORTED 147 |
| 225 | #define EVP_R_INVALID_OPERATION 148 |
| 226 | #define EVP_R_NO_OPERATION_SET 149 |
| 227 | #define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150 |
| 228 | #define EVP_R_OPERATON_NOT_INITIALIZED 151 |
| 229 | #define EVP_R_DIFFERENT_PARAMETERS 153 |
| 230 | #define EVP_R_NO_KEY_SET 154 |
| 231 | #define EVP_R_DIFFERENT_KEY_TYPES 101 |
| 232 | #define EVP_R_MISSING_PARAMETERS 103 |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | #ifdef __cplusplus |
| 240 | } |
| 241 | #endif |
| 242 | #endif |