Eneboo - Documentación para desarrolladores
src/libdigidoc/openssl/crypto/evp/evp_locl.h
Ir a la documentación de este archivo.
00001 /* evp_locl.h */
00002 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
00003  * project 2000.
00004  */
00005 /* ====================================================================
00006  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. All advertising materials mentioning features or use of this
00021  *    software must display the following acknowledgment:
00022  *    "This product includes software developed by the OpenSSL Project
00023  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
00024  *
00025  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00026  *    endorse or promote products derived from this software without
00027  *    prior written permission. For written permission, please contact
00028  *    licensing@OpenSSL.org.
00029  *
00030  * 5. Products derived from this software may not be called "OpenSSL"
00031  *    nor may "OpenSSL" appear in their names without prior written
00032  *    permission of the OpenSSL Project.
00033  *
00034  * 6. Redistributions of any form whatsoever must retain the following
00035  *    acknowledgment:
00036  *    "This product includes software developed by the OpenSSL Project
00037  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00040  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00041  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00042  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00043  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00044  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00045  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00046  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00048  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00049  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00050  * OF THE POSSIBILITY OF SUCH DAMAGE.
00051  * ====================================================================
00052  *
00053  * This product includes cryptographic software written by Eric Young
00054  * (eay@cryptsoft.com).  This product includes software written by Tim
00055  * Hudson (tjh@cryptsoft.com).
00056  *
00057  */
00058 
00059 /* Macros to code block cipher wrappers */
00060 
00061 /* Wrapper functions for each cipher mode */
00062 
00063 #define BLOCK_CIPHER_ecb_loop() \
00064         unsigned int i, bl; \
00065         bl = ctx->cipher->block_size;\
00066         if(inl < bl) return 1;\
00067         inl -= bl; \
00068         for(i=0; i <= inl; i+=bl) 
00069 
00070 #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
00071 static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
00072 {\
00073         BLOCK_CIPHER_ecb_loop() \
00074                 cprefix##_ecb_encrypt(in + i, out + i, &((kstruct *)ctx->cipher_data)->ksched, ctx->encrypt);\
00075         return 1;\
00076 }
00077 
00078 #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
00079 static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
00080 {\
00081         cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
00082         return 1;\
00083 }
00084 
00085 #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
00086 static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
00087 {\
00088         cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
00089         return 1;\
00090 }
00091 
00092 #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
00093 static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
00094 {\
00095         cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits==1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
00096         return 1;\
00097 }
00098 
00099 #define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
00100         BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
00101         BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
00102         BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
00103         BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
00104 
00105 #define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
00106                           key_len, iv_len, flags, init_key, cleanup, \
00107                           set_asn1, get_asn1, ctrl) \
00108 static const EVP_CIPHER cname##_##mode = { \
00109         nid##_##nmode, block_size, key_len, iv_len, \
00110         flags | EVP_CIPH_##MODE##_MODE, \
00111         init_key, \
00112         cname##_##mode##_cipher, \
00113         cleanup, \
00114         sizeof(kstruct), \
00115         set_asn1, get_asn1,\
00116         ctrl, \
00117         NULL \
00118 }; \
00119 const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
00120 
00121 #define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
00122                              iv_len, flags, init_key, cleanup, set_asn1, \
00123                              get_asn1, ctrl) \
00124 BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
00125                   iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
00126 
00127 #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
00128                              iv_len, cbits, flags, init_key, cleanup, \
00129                              set_asn1, get_asn1, ctrl) \
00130 BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
00131                   key_len, iv_len, flags, init_key, cleanup, set_asn1, \
00132                   get_asn1, ctrl)
00133 
00134 #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
00135                              iv_len, cbits, flags, init_key, cleanup, \
00136                              set_asn1, get_asn1, ctrl) \
00137 BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
00138                   key_len, iv_len, flags, init_key, cleanup, set_asn1, \
00139                   get_asn1, ctrl)
00140 
00141 #define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
00142                              flags, init_key, cleanup, set_asn1, \
00143                              get_asn1, ctrl) \
00144 BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
00145                   0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
00146 
00147 #define BLOCK_CIPHER_defs(cname, kstruct, \
00148                           nid, block_size, key_len, iv_len, cbits, flags, \
00149                           init_key, cleanup, set_asn1, get_asn1, ctrl) \
00150 BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
00151                      init_key, cleanup, set_asn1, get_asn1, ctrl) \
00152 BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
00153                      flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
00154 BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
00155                      flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
00156 BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \
00157                      init_key, cleanup, set_asn1, get_asn1, ctrl)
00158 
00159 
00160 /*
00161 #define BLOCK_CIPHER_defs(cname, kstruct, \
00162                                 nid, block_size, key_len, iv_len, flags,\
00163                                  init_key, cleanup, set_asn1, get_asn1, ctrl)\
00164 static const EVP_CIPHER cname##_cbc = {\
00165         nid##_cbc, block_size, key_len, iv_len, \
00166         flags | EVP_CIPH_CBC_MODE,\
00167         init_key,\
00168         cname##_cbc_cipher,\
00169         cleanup,\
00170         sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
00171                 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
00172         set_asn1, get_asn1,\
00173         ctrl, \
00174         NULL \
00175 };\
00176 const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
00177 static const EVP_CIPHER cname##_cfb = {\
00178         nid##_cfb64, 1, key_len, iv_len, \
00179         flags | EVP_CIPH_CFB_MODE,\
00180         init_key,\
00181         cname##_cfb_cipher,\
00182         cleanup,\
00183         sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
00184                 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
00185         set_asn1, get_asn1,\
00186         ctrl,\
00187         NULL \
00188 };\
00189 const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
00190 static const EVP_CIPHER cname##_ofb = {\
00191         nid##_ofb64, 1, key_len, iv_len, \
00192         flags | EVP_CIPH_OFB_MODE,\
00193         init_key,\
00194         cname##_ofb_cipher,\
00195         cleanup,\
00196         sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
00197                 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
00198         set_asn1, get_asn1,\
00199         ctrl,\
00200         NULL \
00201 };\
00202 const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
00203 static const EVP_CIPHER cname##_ecb = {\
00204         nid##_ecb, block_size, key_len, iv_len, \
00205         flags | EVP_CIPH_ECB_MODE,\
00206         init_key,\
00207         cname##_ecb_cipher,\
00208         cleanup,\
00209         sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
00210                 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
00211         set_asn1, get_asn1,\
00212         ctrl,\
00213         NULL \
00214 };\
00215 const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
00216 */
00217 
00218 #define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
00219                                block_size, key_len, iv_len, cbits, \
00220                                flags, init_key, \
00221                                cleanup, set_asn1, get_asn1, ctrl) \
00222         BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
00223         BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
00224                           cbits, flags, init_key, cleanup, set_asn1, \
00225                           get_asn1, ctrl)
00226 
00227 #define EVP_C_DATA(kstruct, ctx)        ((kstruct *)(ctx)->cipher_data)
00228 
00229 #define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
00230         BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
00231         BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
00232                              NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
00233                              (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
00234                              cipher##_init_key, NULL, NULL, NULL, NULL)
00235 
00236 #ifdef OPENSSL_FIPS
00237 #define RC2_set_key     private_RC2_set_key
00238 #define RC4_set_key     private_RC4_set_key
00239 #define CAST_set_key    private_CAST_set_key
00240 #define RC5_32_set_key  private_RC5_32_set_key
00241 #define BF_set_key      private_BF_set_key
00242 #define Camellia_set_key private_Camellia_set_key
00243 #define idea_set_encrypt_key private_idea_set_encrypt_key
00244 
00245 #define MD5_Init        private_MD5_Init
00246 #define MD4_Init        private_MD4_Init
00247 #define MD2_Init        private_MD2_Init
00248 #define MDC2_Init       private_MDC2_Init
00249 #define SHA_Init        private_SHA_Init
00250 
00251 #endif
00252 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'