OLD | NEW |
1 /* crypto/des/enc_read.c */ | 1 /* crypto/des/enc_read.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include <errno.h> | 60 #include <errno.h> |
61 #include "cryptlib.h" | 61 #include "cryptlib.h" |
62 #include "des_locl.h" | 62 #include "des_locl.h" |
63 | 63 |
64 /* This has some uglies in it but it works - even over sockets. */ | 64 /* This has some uglies in it but it works - even over sockets. */ |
65 /*extern int errno;*/ | 65 /*extern int errno;*/ |
66 OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE; | 66 OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode,DES_PCBC_MODE) |
67 | 67 |
68 | 68 |
69 /* | 69 /* |
70 * WARNINGS: | 70 * WARNINGS: |
71 * | 71 * |
72 * - The data format used by DES_enc_write() and DES_enc_read() | 72 * - The data format used by DES_enc_write() and DES_enc_read() |
73 * has a cryptographic weakness: When asked to write more | 73 * has a cryptographic weakness: When asked to write more |
74 * than MAXWRITE bytes, DES_enc_write will split the data | 74 * than MAXWRITE bytes, DES_enc_write will split the data |
75 * into several chunks that are all encrypted | 75 * into several chunks that are all encrypted |
76 * using the same IV. So don't use these functions unless you | 76 * using the same IV. So don't use these functions unless you |
77 * are sure you know what you do (in which case you might | 77 * are sure you know what you do (in which case you might |
78 * not want to use them anyway). | 78 * not want to use them anyway). |
79 * | 79 * |
80 * - This code cannot handle non-blocking sockets. | 80 * - This code cannot handle non-blocking sockets. |
81 * | 81 * |
82 * - This function uses an internal state and thus cannot be | 82 * - This function uses an internal state and thus cannot be |
83 * used on multiple files. | 83 * used on multiple files. |
84 */ | 84 */ |
85 | 85 |
86 | 86 |
87 int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, | 87 int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, |
88 DES_cblock *iv) | 88 DES_cblock *iv) |
89 { | 89 { |
| 90 #if defined(OPENSSL_NO_POSIX_IO) |
| 91 return(0); |
| 92 #else |
90 /* data to be unencrypted */ | 93 /* data to be unencrypted */ |
91 int net_num=0; | 94 int net_num=0; |
92 static unsigned char *net=NULL; | 95 static unsigned char *net=NULL; |
93 /* extra unencrypted data | 96 /* extra unencrypted data |
94 * for when a block of 100 comes in but is des_read one byte at | 97 * for when a block of 100 comes in but is des_read one byte at |
95 * a time. */ | 98 * a time. */ |
96 static unsigned char *unnet=NULL; | 99 static unsigned char *unnet=NULL; |
97 static int unnet_start=0; | 100 static int unnet_start=0; |
98 static int unnet_left=0; | 101 static int unnet_left=0; |
99 static unsigned char *tmpbuf=NULL; | 102 static unsigned char *tmpbuf=NULL; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 143 } |
141 return(i); | 144 return(i); |
142 } | 145 } |
143 | 146 |
144 /* We need to get more data. */ | 147 /* We need to get more data. */ |
145 if (len > MAXWRITE) len=MAXWRITE; | 148 if (len > MAXWRITE) len=MAXWRITE; |
146 | 149 |
147 /* first - get the length */ | 150 /* first - get the length */ |
148 while (net_num < HDRSIZE) | 151 while (net_num < HDRSIZE) |
149 { | 152 { |
150 #ifndef _WIN32 | 153 #ifndef OPENSSL_SYS_WIN32 |
151 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); | 154 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); |
152 #else | 155 #else |
153 i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); | 156 i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); |
154 #endif | 157 #endif |
155 #ifdef EINTR | 158 #ifdef EINTR |
156 if ((i == -1) && (errno == EINTR)) continue; | 159 if ((i == -1) && (errno == EINTR)) continue; |
157 #endif | 160 #endif |
158 if (i <= 0) return(0); | 161 if (i <= 0) return(0); |
159 net_num+=i; | 162 net_num+=i; |
160 } | 163 } |
161 | 164 |
162 /* we now have at net_num bytes in net */ | 165 /* we now have at net_num bytes in net */ |
163 p=net; | 166 p=net; |
164 /* num=0; */ | 167 /* num=0; */ |
165 n2l(p,num); | 168 n2l(p,num); |
166 /* num should be rounded up to the next group of eight | 169 /* num should be rounded up to the next group of eight |
167 * we make sure that we have read a multiple of 8 bytes from the net. | 170 * we make sure that we have read a multiple of 8 bytes from the net. |
168 */ | 171 */ |
169 if ((num > MAXWRITE) || (num < 0)) /* error */ | 172 if ((num > MAXWRITE) || (num < 0)) /* error */ |
170 return(-1); | 173 return(-1); |
171 rnum=(num < 8)?8:((num+7)/8*8); | 174 rnum=(num < 8)?8:((num+7)/8*8); |
172 | 175 |
173 net_num=0; | 176 net_num=0; |
174 while (net_num < rnum) | 177 while (net_num < rnum) |
175 { | 178 { |
| 179 #ifndef OPENSSL_SYS_WIN32 |
176 i=read(fd,(void *)&(net[net_num]),rnum-net_num); | 180 i=read(fd,(void *)&(net[net_num]),rnum-net_num); |
| 181 #else |
| 182 i=_read(fd,(void *)&(net[net_num]),rnum-net_num); |
| 183 #endif |
177 #ifdef EINTR | 184 #ifdef EINTR |
178 if ((i == -1) && (errno == EINTR)) continue; | 185 if ((i == -1) && (errno == EINTR)) continue; |
179 #endif | 186 #endif |
180 if (i <= 0) return(0); | 187 if (i <= 0) return(0); |
181 net_num+=i; | 188 net_num+=i; |
182 } | 189 } |
183 | 190 |
184 /* Check if there will be data left over. */ | 191 /* Check if there will be data left over. */ |
185 if (len < num) | 192 if (len < num) |
186 { | 193 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 { | 228 { |
222 if (DES_rw_mode & DES_PCBC_MODE) | 229 if (DES_rw_mode & DES_PCBC_MODE) |
223 DES_pcbc_encrypt(net,buf,num,sched,iv, | 230 DES_pcbc_encrypt(net,buf,num,sched,iv, |
224 DES_DECRYPT); | 231 DES_DECRYPT); |
225 else | 232 else |
226 DES_cbc_encrypt(net,buf,num,sched,iv, | 233 DES_cbc_encrypt(net,buf,num,sched,iv, |
227 DES_DECRYPT); | 234 DES_DECRYPT); |
228 } | 235 } |
229 } | 236 } |
230 return num; | 237 return num; |
| 238 #endif /* OPENSSL_NO_POSIX_IO */ |
231 } | 239 } |
232 | 240 |
OLD | NEW |