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

« back to all changes in this revision

Viewing changes to crypto/evp/e_des.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"
92
92
        return 1;
93
93
}
94
94
 
95
 
static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96
 
                          const unsigned char *in, unsigned int inl)
 
95
static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
96
                            const unsigned char *in, unsigned int inl)
97
97
{
98
98
        DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
99
99
                          (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
100
100
        return 1;
101
101
}
102
102
 
 
103
/* Although we have a CFB-r implementation for DES, it doesn't pack the right
 
104
   way, so wrap it here */
 
105
static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
106
                           const unsigned char *in, unsigned int inl)
 
107
    {
 
108
    unsigned int n;
 
109
    unsigned char c[1],d[1];
 
110
 
 
111
    for(n=0 ; n < inl ; ++n)
 
112
        {
 
113
        c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
 
114
        DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
 
115
                        ctx->encrypt);
 
116
        out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
 
117
        }
 
118
    return 1;
 
119
    }
 
120
 
 
121
static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
122
                           const unsigned char *in, unsigned int inl)
 
123
    {
 
124
    DES_cfb_encrypt(in,out,8,inl,ctx->cipher_data,(DES_cblock *)ctx->iv,
 
125
                    ctx->encrypt);
 
126
    return 1;
 
127
    }
 
128
 
103
129
BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
104
130
                        0, des_init_key, NULL,
105
131
                        EVP_CIPHER_set_asn1_iv,
106
132
                        EVP_CIPHER_get_asn1_iv,
107
133
                        NULL)
108
134
 
 
135
BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,0,des_init_key,NULL,
 
136
                     EVP_CIPHER_set_asn1_iv,
 
137
                     EVP_CIPHER_get_asn1_iv,NULL)
 
138
 
 
139
BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,0,des_init_key,NULL,
 
140
                     EVP_CIPHER_set_asn1_iv,
 
141
                     EVP_CIPHER_get_asn1_iv,NULL)
109
142
 
110
143
static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111
144
                        const unsigned char *iv, int enc)