diff options
Diffstat (limited to 'src/lib/libcrypto/des/ncbc_enc.c')
-rw-r--r-- | src/lib/libcrypto/des/ncbc_enc.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c index 1d1a368c22..fda23d522f 100644 --- a/src/lib/libcrypto/des/ncbc_enc.c +++ b/src/lib/libcrypto/des/ncbc_enc.c | |||
@@ -1,4 +1,9 @@ | |||
1 | /* crypto/des/ncbc_enc.c */ | 1 | /* crypto/des/ncbc_enc.c */ |
2 | /* | ||
3 | * #included by: | ||
4 | * cbc_enc.c (DES_cbc_encrypt) | ||
5 | * des_enc.c (DES_ncbc_encrypt) | ||
6 | */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 7 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 8 | * All rights reserved. |
4 | * | 9 | * |
@@ -58,24 +63,21 @@ | |||
58 | 63 | ||
59 | #include "des_locl.h" | 64 | #include "des_locl.h" |
60 | 65 | ||
61 | void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | 66 | #ifdef CBC_ENC_C__DONT_UPDATE_IV |
62 | des_cblock (*input); | 67 | void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
63 | des_cblock (*output); | 68 | DES_key_schedule *_schedule, DES_cblock *ivec, int enc) |
64 | long length; | 69 | #else |
65 | des_key_schedule schedule; | 70 | void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
66 | des_cblock (*ivec); | 71 | DES_key_schedule *_schedule, DES_cblock *ivec, int enc) |
67 | int enc; | 72 | #endif |
68 | { | 73 | { |
69 | register DES_LONG tin0,tin1; | 74 | register DES_LONG tin0,tin1; |
70 | register DES_LONG tout0,tout1,xor0,xor1; | 75 | register DES_LONG tout0,tout1,xor0,xor1; |
71 | register unsigned char *in,*out; | ||
72 | register long l=length; | 76 | register long l=length; |
73 | DES_LONG tin[2]; | 77 | DES_LONG tin[2]; |
74 | unsigned char *iv; | 78 | unsigned char *iv; |
75 | 79 | ||
76 | in=(unsigned char *)input; | 80 | iv = &(*ivec)[0]; |
77 | out=(unsigned char *)output; | ||
78 | iv=(unsigned char *)ivec; | ||
79 | 81 | ||
80 | if (enc) | 82 | if (enc) |
81 | { | 83 | { |
@@ -87,7 +89,7 @@ int enc; | |||
87 | c2l(in,tin1); | 89 | c2l(in,tin1); |
88 | tin0^=tout0; tin[0]=tin0; | 90 | tin0^=tout0; tin[0]=tin0; |
89 | tin1^=tout1; tin[1]=tin1; | 91 | tin1^=tout1; tin[1]=tin1; |
90 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | 92 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); |
91 | tout0=tin[0]; l2c(tout0,out); | 93 | tout0=tin[0]; l2c(tout0,out); |
92 | tout1=tin[1]; l2c(tout1,out); | 94 | tout1=tin[1]; l2c(tout1,out); |
93 | } | 95 | } |
@@ -96,13 +98,15 @@ int enc; | |||
96 | c2ln(in,tin0,tin1,l+8); | 98 | c2ln(in,tin0,tin1,l+8); |
97 | tin0^=tout0; tin[0]=tin0; | 99 | tin0^=tout0; tin[0]=tin0; |
98 | tin1^=tout1; tin[1]=tin1; | 100 | tin1^=tout1; tin[1]=tin1; |
99 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | 101 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); |
100 | tout0=tin[0]; l2c(tout0,out); | 102 | tout0=tin[0]; l2c(tout0,out); |
101 | tout1=tin[1]; l2c(tout1,out); | 103 | tout1=tin[1]; l2c(tout1,out); |
102 | } | 104 | } |
103 | iv=(unsigned char *)ivec; | 105 | #ifndef CBC_ENC_C__DONT_UPDATE_IV |
106 | iv = &(*ivec)[0]; | ||
104 | l2c(tout0,iv); | 107 | l2c(tout0,iv); |
105 | l2c(tout1,iv); | 108 | l2c(tout1,iv); |
109 | #endif | ||
106 | } | 110 | } |
107 | else | 111 | else |
108 | { | 112 | { |
@@ -112,7 +116,7 @@ int enc; | |||
112 | { | 116 | { |
113 | c2l(in,tin0); tin[0]=tin0; | 117 | c2l(in,tin0); tin[0]=tin0; |
114 | c2l(in,tin1); tin[1]=tin1; | 118 | c2l(in,tin1); tin[1]=tin1; |
115 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | 119 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); |
116 | tout0=tin[0]^xor0; | 120 | tout0=tin[0]^xor0; |
117 | tout1=tin[1]^xor1; | 121 | tout1=tin[1]^xor1; |
118 | l2c(tout0,out); | 122 | l2c(tout0,out); |
@@ -120,11 +124,25 @@ int enc; | |||
120 | xor0=tin0; | 124 | xor0=tin0; |
121 | xor1=tin1; | 125 | xor1=tin1; |
122 | } | 126 | } |
123 | iv=(unsigned char *)ivec; | 127 | if (l != -8) |
128 | { | ||
129 | c2l(in,tin0); tin[0]=tin0; | ||
130 | c2l(in,tin1); tin[1]=tin1; | ||
131 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); | ||
132 | tout0=tin[0]^xor0; | ||
133 | tout1=tin[1]^xor1; | ||
134 | l2cn(tout0,tout1,out,l+8); | ||
135 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | ||
136 | xor0=tin0; | ||
137 | xor1=tin1; | ||
138 | #endif | ||
139 | } | ||
140 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | ||
141 | iv = &(*ivec)[0]; | ||
124 | l2c(xor0,iv); | 142 | l2c(xor0,iv); |
125 | l2c(xor1,iv); | 143 | l2c(xor1,iv); |
144 | #endif | ||
126 | } | 145 | } |
127 | tin0=tin1=tout0=tout1=xor0=xor1=0; | 146 | tin0=tin1=tout0=tout1=xor0=xor1=0; |
128 | tin[0]=tin[1]=0; | 147 | tin[0]=tin[1]=0; |
129 | } | 148 | } |
130 | |||