summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/ncbc_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/ncbc_enc.c')
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
index 1d1a368c22..e0e67a417d 100644
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ b/src/lib/libcrypto/des/ncbc_enc.c
@@ -58,24 +58,21 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 61#ifdef CBC_ENC_C__DONT_UPDATE_IV
62des_cblock (*input); 62void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63des_cblock (*output); 63 des_key_schedule schedule, des_cblock *ivec, int enc)
64long length; 64#else
65des_key_schedule schedule; 65void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
66des_cblock (*ivec); 66 des_key_schedule schedule, des_cblock *ivec, int enc)
67int enc; 67#endif
68 { 68 {
69 register DES_LONG tin0,tin1; 69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1; 70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length; 71 register long l=length;
73 DES_LONG tin[2]; 72 DES_LONG tin[2];
74 unsigned char *iv; 73 unsigned char *iv;
75 74
76 in=(unsigned char *)input; 75 iv = &(*ivec)[0];
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79 76
80 if (enc) 77 if (enc)
81 { 78 {
@@ -100,9 +97,11 @@ int enc;
100 tout0=tin[0]; l2c(tout0,out); 97 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out); 98 tout1=tin[1]; l2c(tout1,out);
102 } 99 }
103 iv=(unsigned char *)ivec; 100#ifndef CBC_ENC_C__DONT_UPDATE_IV
101 iv = &(*ivec)[0];
104 l2c(tout0,iv); 102 l2c(tout0,iv);
105 l2c(tout1,iv); 103 l2c(tout1,iv);
104#endif
106 } 105 }
107 else 106 else
108 { 107 {
@@ -120,11 +119,25 @@ int enc;
120 xor0=tin0; 119 xor0=tin0;
121 xor1=tin1; 120 xor1=tin1;
122 } 121 }
123 iv=(unsigned char *)ivec; 122 if (l != -8)
123 {
124 c2l(in,tin0); tin[0]=tin0;
125 c2l(in,tin1); tin[1]=tin1;
126 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
127 tout0=tin[0]^xor0;
128 tout1=tin[1]^xor1;
129 l2cn(tout0,tout1,out,l+8);
130#ifndef CBC_ENC_C__DONT_UPDATE_IV
131 xor0=tin0;
132 xor1=tin1;
133#endif
134 }
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 iv = &(*ivec)[0];
124 l2c(xor0,iv); 137 l2c(xor0,iv);
125 l2c(xor1,iv); 138 l2c(xor1,iv);
139#endif
126 } 140 }
127 tin0=tin1=tout0=tout1=xor0=xor1=0; 141 tin0=tin1=tout0=tout1=xor0=xor1=0;
128 tin[0]=tin[1]=0; 142 tin[0]=tin[1]=0;
129 } 143 }
130