diff options
Diffstat (limited to 'src/lib/libcrypto/des/cfb_enc.c')
-rw-r--r-- | src/lib/libcrypto/des/cfb_enc.c | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c index 720f29a28e..03cabb223c 100644 --- a/src/lib/libcrypto/des/cfb_enc.c +++ b/src/lib/libcrypto/des/cfb_enc.c | |||
@@ -58,7 +58,6 @@ | |||
58 | 58 | ||
59 | #include "e_os.h" | 59 | #include "e_os.h" |
60 | #include "des_locl.h" | 60 | #include "des_locl.h" |
61 | #include <assert.h> | ||
62 | 61 | ||
63 | /* The input and output are loaded in multiples of 8 bits. | 62 | /* The input and output are loaded in multiples of 8 bits. |
64 | * What this means is that if you hame numbits=12 and length=2 | 63 | * What this means is that if you hame numbits=12 and length=2 |
@@ -73,29 +72,19 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, | |||
73 | int enc) | 72 | int enc) |
74 | { | 73 | { |
75 | register DES_LONG d0,d1,v0,v1; | 74 | register DES_LONG d0,d1,v0,v1; |
76 | register unsigned long l=length; | 75 | register unsigned long l=length,n=(numbits+7)/8; |
77 | register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8; | 76 | register int num=numbits,i; |
78 | DES_LONG ti[2]; | 77 | DES_LONG ti[2]; |
79 | unsigned char *iv; | 78 | unsigned char *iv; |
80 | #ifndef L_ENDIAN | ||
81 | unsigned char ovec[16]; | 79 | unsigned char ovec[16]; |
82 | #else | ||
83 | unsigned int sh[4]; | ||
84 | unsigned char *ovec=(unsigned char *)sh; | ||
85 | 80 | ||
86 | /* I kind of count that compiler optimizes away this assertioni,*/ | 81 | if (num > 64) return; |
87 | assert (sizeof(sh[0])==4); /* as this holds true for all, */ | ||
88 | /* but 16-bit platforms... */ | ||
89 | |||
90 | #endif | ||
91 | |||
92 | if (numbits<=0 || numbits > 64) return; | ||
93 | iv = &(*ivec)[0]; | 82 | iv = &(*ivec)[0]; |
94 | c2l(iv,v0); | 83 | c2l(iv,v0); |
95 | c2l(iv,v1); | 84 | c2l(iv,v1); |
96 | if (enc) | 85 | if (enc) |
97 | { | 86 | { |
98 | while (l >= (unsigned long)n) | 87 | while (l >= n) |
99 | { | 88 | { |
100 | l-=n; | 89 | l-=n; |
101 | ti[0]=v0; | 90 | ti[0]=v0; |
@@ -109,40 +98,35 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, | |||
109 | out+=n; | 98 | out+=n; |
110 | /* 30-08-94 - eay - changed because l>>32 and | 99 | /* 30-08-94 - eay - changed because l>>32 and |
111 | * l<<32 are bad under gcc :-( */ | 100 | * l<<32 are bad under gcc :-( */ |
112 | if (numbits == 32) | 101 | if (num == 32) |
113 | { v0=v1; v1=d0; } | 102 | { v0=v1; v1=d0; } |
114 | else if (numbits == 64) | 103 | else if (num == 64) |
115 | { v0=d0; v1=d1; } | 104 | { v0=d0; v1=d1; } |
116 | else | 105 | else |
117 | { | 106 | { |
118 | #ifndef L_ENDIAN | ||
119 | iv=&ovec[0]; | 107 | iv=&ovec[0]; |
120 | l2c(v0,iv); | 108 | l2c(v0,iv); |
121 | l2c(v1,iv); | 109 | l2c(v1,iv); |
122 | l2c(d0,iv); | 110 | l2c(d0,iv); |
123 | l2c(d1,iv); | 111 | l2c(d1,iv); |
124 | #else | 112 | /* shift ovec left most of the bits... */ |
125 | sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; | 113 | memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); |
126 | #endif | 114 | /* now the remaining bits */ |
127 | if (rem==0) | 115 | if(num%8 != 0) |
128 | memmove(ovec,ovec+num,8); | ||
129 | else | ||
130 | for(i=0 ; i < 8 ; ++i) | 116 | for(i=0 ; i < 8 ; ++i) |
131 | ovec[i]=ovec[i+num]<<rem | | 117 | { |
132 | ovec[i+num+1]>>(8-rem); | 118 | ovec[i]<<=num%8; |
133 | #ifdef L_ENDIAN | 119 | ovec[i]|=ovec[i+1]>>(8-num%8); |
134 | v0=sh[0], v1=sh[1]; | 120 | } |
135 | #else | ||
136 | iv=&ovec[0]; | 121 | iv=&ovec[0]; |
137 | c2l(iv,v0); | 122 | c2l(iv,v0); |
138 | c2l(iv,v1); | 123 | c2l(iv,v1); |
139 | #endif | ||
140 | } | 124 | } |
141 | } | 125 | } |
142 | } | 126 | } |
143 | else | 127 | else |
144 | { | 128 | { |
145 | while (l >= (unsigned long)n) | 129 | while (l >= n) |
146 | { | 130 | { |
147 | l-=n; | 131 | l-=n; |
148 | ti[0]=v0; | 132 | ti[0]=v0; |
@@ -152,34 +136,29 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, | |||
152 | in+=n; | 136 | in+=n; |
153 | /* 30-08-94 - eay - changed because l>>32 and | 137 | /* 30-08-94 - eay - changed because l>>32 and |
154 | * l<<32 are bad under gcc :-( */ | 138 | * l<<32 are bad under gcc :-( */ |
155 | if (numbits == 32) | 139 | if (num == 32) |
156 | { v0=v1; v1=d0; } | 140 | { v0=v1; v1=d0; } |
157 | else if (numbits == 64) | 141 | else if (num == 64) |
158 | { v0=d0; v1=d1; } | 142 | { v0=d0; v1=d1; } |
159 | else | 143 | else |
160 | { | 144 | { |
161 | #ifndef L_ENDIAN | ||
162 | iv=&ovec[0]; | 145 | iv=&ovec[0]; |
163 | l2c(v0,iv); | 146 | l2c(v0,iv); |
164 | l2c(v1,iv); | 147 | l2c(v1,iv); |
165 | l2c(d0,iv); | 148 | l2c(d0,iv); |
166 | l2c(d1,iv); | 149 | l2c(d1,iv); |
167 | #else | 150 | /* shift ovec left most of the bits... */ |
168 | sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; | 151 | memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); |
169 | #endif | 152 | /* now the remaining bits */ |
170 | if (rem==0) | 153 | if(num%8 != 0) |
171 | memmove(ovec,ovec+num,8); | ||
172 | else | ||
173 | for(i=0 ; i < 8 ; ++i) | 154 | for(i=0 ; i < 8 ; ++i) |
174 | ovec[i]=ovec[i+num]<<rem | | 155 | { |
175 | ovec[i+num+1]>>(8-rem); | 156 | ovec[i]<<=num%8; |
176 | #ifdef L_ENDIAN | 157 | ovec[i]|=ovec[i+1]>>(8-num%8); |
177 | v0=sh[0], v1=sh[1]; | 158 | } |
178 | #else | ||
179 | iv=&ovec[0]; | 159 | iv=&ovec[0]; |
180 | c2l(iv,v0); | 160 | c2l(iv,v0); |
181 | c2l(iv,v1); | 161 | c2l(iv,v1); |
182 | #endif | ||
183 | } | 162 | } |
184 | d0^=ti[0]; | 163 | d0^=ti[0]; |
185 | d1^=ti[1]; | 164 | d1^=ti[1]; |