summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_des.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_des.c')
-rw-r--r--src/lib/libcrypto/evp/e_des.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
index 105266a4b3..46e2899825 100644
--- a/src/lib/libcrypto/evp/e_des.c
+++ b/src/lib/libcrypto/evp/e_des.c
@@ -56,9 +56,9 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_DES
60#include <stdio.h> 59#include <stdio.h>
61#include "cryptlib.h" 60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include "evp_locl.h" 64#include "evp_locl.h"
@@ -92,20 +92,55 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
92 return 1; 92 return 1;
93} 93}
94 94
95static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 95static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl) 96 const unsigned char *in, unsigned int inl)
97{ 97{
98 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, 98 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
99 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); 99 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
100 return 1; 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 */
105static 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
121static 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
103BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64, 129BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
104 0, des_init_key, NULL, 130 EVP_CIPH_FLAG_FIPS, des_init_key, NULL,
105 EVP_CIPHER_set_asn1_iv, 131 EVP_CIPHER_set_asn1_iv,
106 EVP_CIPHER_get_asn1_iv, 132 EVP_CIPHER_get_asn1_iv,
107 NULL) 133 NULL)
108 134
135BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
136 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
137 EVP_CIPHER_set_asn1_iv,
138 EVP_CIPHER_get_asn1_iv,NULL)
139
140BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
141 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
142 EVP_CIPHER_set_asn1_iv,
143 EVP_CIPHER_get_asn1_iv,NULL)
109 144
110static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 145static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc) 146 const unsigned char *iv, int enc)