~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/evp/e_des3.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 * [including the GNU Public Licence.]
57
57
 */
58
58
 
59
 
#ifndef OPENSSL_NO_DES
60
59
#include <stdio.h>
61
60
#include "cryptlib.h"
 
61
#ifndef OPENSSL_NO_DES
62
62
#include <openssl/evp.h>
63
63
#include <openssl/objects.h>
64
64
#include "evp_locl.h"
85
85
                              const unsigned char *in, unsigned int inl)
86
86
{
87
87
        BLOCK_CIPHER_ecb_loop()
88
 
                DES_ecb3_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), 
 
88
                DES_ecb3_encrypt(in + i,out + i, 
89
89
                                 &data(ctx)->ks1, &data(ctx)->ks2,
90
90
                                 &data(ctx)->ks3,
91
91
                                 ctx->encrypt);
121
121
        return 1;
122
122
}
123
123
 
124
 
static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
124
static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
125
125
                              const unsigned char *in, unsigned int inl)
126
126
{
127
127
        DES_ede3_cfb64_encrypt(in, out, (long)inl, 
130
130
        return 1;
131
131
}
132
132
 
 
133
/* Although we have a CFB-r implementation for 3-DES, it doesn't pack the right
 
134
   way, so wrap it here */
 
135
static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
136
                                const unsigned char *in, unsigned int inl)
 
137
    {
 
138
    unsigned int n;
 
139
    unsigned char c[1],d[1];
 
140
 
 
141
    for(n=0 ; n < inl ; ++n)
 
142
        {
 
143
        c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
 
144
        DES_ede3_cfb_encrypt(c,d,1,1,
 
145
                             &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
 
146
                             (DES_cblock *)ctx->iv,ctx->encrypt);
 
147
        out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
 
148
        }
 
149
 
 
150
    return 1;
 
151
    }
 
152
 
 
153
static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
154
                                const unsigned char *in, unsigned int inl)
 
155
    {
 
156
    DES_ede3_cfb_encrypt(in,out,8,inl,
 
157
                         &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
 
158
                         (DES_cblock *)ctx->iv,ctx->encrypt);
 
159
    return 1;
 
160
    }
 
161
 
133
162
BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
134
163
                        0, des_ede_init_key, NULL, 
135
164
                        EVP_CIPHER_set_asn1_iv,
136
165
                        EVP_CIPHER_get_asn1_iv,
137
166
                        NULL)
138
167
 
139
 
#define des_ede3_cfb_cipher des_ede_cfb_cipher
 
168
#define des_ede3_cfb64_cipher des_ede_cfb64_cipher
140
169
#define des_ede3_ofb_cipher des_ede_ofb_cipher
141
170
#define des_ede3_cbc_cipher des_ede_cbc_cipher
142
171
#define des_ede3_ecb_cipher des_ede_ecb_cipher
147
176
                        EVP_CIPHER_get_asn1_iv,
148
177
                        NULL)
149
178
 
 
179
BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,0,
 
180
                     des_ede3_init_key,NULL,
 
181
                     EVP_CIPHER_set_asn1_iv,
 
182
                     EVP_CIPHER_get_asn1_iv,NULL)
 
183
 
 
184
BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,0,
 
185
                     des_ede3_init_key,NULL,
 
186
                     EVP_CIPHER_set_asn1_iv,
 
187
                     EVP_CIPHER_get_asn1_iv,NULL)
 
188
 
150
189
static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
151
190
                            const unsigned char *iv, int enc)
152
191
        {