e_xcbc_d.c revision 55714
1238104Sdes/* crypto/evp/e_xcbc_d.c */ 2238104Sdes/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3238104Sdes * All rights reserved. 4238104Sdes * 5238104Sdes * This package is an SSL implementation written 6238104Sdes * by Eric Young (eay@cryptsoft.com). 7238104Sdes * The implementation was written so as to conform with Netscapes SSL. 8238104Sdes * 9238104Sdes * This library is free for commercial and non-commercial use as long as 10238104Sdes * the following conditions are aheared to. The following conditions 11238104Sdes * apply to all code found in this distribution, be it the RC4, RSA, 12238104Sdes * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13238104Sdes * included with this distribution is covered by the same copyright terms 14238104Sdes * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15238104Sdes * 16238104Sdes * Copyright remains Eric Young's, and as such any Copyright notices in 17238104Sdes * the code are not to be removed. 18238104Sdes * If this package is used in a product, Eric Young should be given attribution 19238104Sdes * as the author of the parts of the library used. 20238104Sdes * This can be in the form of a textual message at program startup or 21238104Sdes * in documentation (online or textual) provided with the package. 22238104Sdes * 23238104Sdes * Redistribution and use in source and binary forms, with or without 24238104Sdes * modification, are permitted provided that the following conditions 25238104Sdes * are met: 26238104Sdes * 1. Redistributions of source code must retain the copyright 27238104Sdes * notice, this list of conditions and the following disclaimer. 28238104Sdes * 2. Redistributions in binary form must reproduce the above copyright 29238104Sdes * notice, this list of conditions and the following disclaimer in the 30238104Sdes * documentation and/or other materials provided with the distribution. 31238104Sdes * 3. All advertising materials mentioning features or use of this software 32238104Sdes * must display the following acknowledgement: 33238104Sdes * "This product includes cryptographic software written by 34238104Sdes * Eric Young (eay@cryptsoft.com)" 35238104Sdes * The word 'cryptographic' can be left out if the rouines from the library 36238104Sdes * being used are not cryptographic related :-). 37238104Sdes * 4. If you include any Windows specific code (or a derivative thereof) from 38238104Sdes * the apps directory (application code) you must include an acknowledgement: 39238104Sdes * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40238104Sdes * 41238104Sdes * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42238104Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43238104Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44238104Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45238104Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46238104Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47238104Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48238104Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49238104Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50238104Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51238104Sdes * SUCH DAMAGE. 52238104Sdes * 53238104Sdes * The licence and distribution terms for any publically available version or 54238104Sdes * derivative of this code cannot be changed. i.e. this code cannot simply be 55238104Sdes * copied and put under another distribution licence 56238104Sdes * [including the GNU Public Licence.] 57238104Sdes */ 58238104Sdes 59238104Sdes#ifndef NO_DES 60238104Sdes#include <stdio.h> 61238104Sdes#include "cryptlib.h" 62238104Sdes#include <openssl/evp.h> 63238104Sdes#include <openssl/objects.h> 64238104Sdes 65238104Sdesstatic void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66238104Sdes unsigned char *iv,int enc); 67238104Sdesstatic void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68238104Sdes unsigned char *in, unsigned int inl); 69238104Sdesstatic EVP_CIPHER d_xcbc_cipher= 70238104Sdes { 71238104Sdes NID_desx_cbc, 72238104Sdes 8,24,8, 73238104Sdes desx_cbc_init_key, 74238104Sdes desx_cbc_cipher, 75238104Sdes NULL, 76238104Sdes sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 77238104Sdes sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)), 78238104Sdes EVP_CIPHER_set_asn1_iv, 79238104Sdes EVP_CIPHER_get_asn1_iv, 80238104Sdes }; 81238104Sdes 82238104SdesEVP_CIPHER *EVP_desx_cbc(void) 83238104Sdes { 84238104Sdes return(&d_xcbc_cipher); 85238104Sdes } 86238104Sdes 87238104Sdesstatic void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 88238104Sdes unsigned char *iv, int enc) 89238104Sdes { 90238104Sdes des_cblock *deskey = (des_cblock *)key; 91238104Sdes 92238104Sdes if (iv != NULL) 93238104Sdes memcpy(&(ctx->oiv[0]),iv,8); 94238104Sdes memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 95238104Sdes if (deskey != NULL) 96238104Sdes { 97238104Sdes des_set_key(deskey,ctx->c.desx_cbc.ks); 98238104Sdes memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); 99238104Sdes memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); 100238104Sdes } 101238104Sdes } 102238104Sdes 103238104Sdesstatic void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 104238104Sdes unsigned char *in, unsigned int inl) 105238104Sdes { 106238104Sdes des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks, 107238104Sdes (des_cblock *)&(ctx->iv[0]), 108238104Sdes &ctx->c.desx_cbc.inw, 109238104Sdes &ctx->c.desx_cbc.outw, 110238104Sdes ctx->encrypt); 111238104Sdes } 112238104Sdes#endif 113238104Sdes