tree checksum vpatch file split hunks

all signers: asciilifeform diana_coman

antecedents: mpi-genesis

press order:

mpi-genesisasciilifeform diana_coman
mpi_second_cutasciilifeform diana_coman

patch:

-
+ B130326CE04125D505761664BF84F3B71836FB198BF39CFECDF464D02103B26015149CABB3D4107D59D4EBF6CC94E8E456916766CC095EE4DB35605718454D79
mpi/bin/README
(0 . 0)(1 . 1)
5 bin
- 2637E827D61AC5BE58C3CC88799EAF49DAED6C957ED6C6647B6D8D787E4F7FD731CDD16DB53CB1FA15E35230E918CD62DA33B4DD410CC073CA4092BC973F5AD1
+
mpi/errors.c
(1 . 113)(0 . 0)
11 /* errors.c - error strings
12 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
13 *
14 * This file is part of GnuPG.
15 *
16 * GnuPG is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * GnuPG is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 */
29
30 #include <config.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34
35 #include "errors.h"
36
37 #ifndef HAVE_STRERROR
38 char *
39 strerror( int n )
40 {
41 extern char *sys_errlist[];
42 extern int sys_nerr;
43 static char buf[15];
44
45 if( n >= 0 && n < sys_nerr )
46 return sys_errlist[n];
47 strcpy( buf, "Unknown error" );
48 return buf;
49 }
50 #endif /* !HAVE_STRERROR */
51
52 const char *
53 g10_errstr( int err )
54 {
55 static char buf[50];
56 const char *p;
57
58 #define X(n,s) case G10ERR_##n : p = s; break;
59 switch( err ) {
60 case -1: p = "eof"; break;
61 case 0: p = "okay"; break;
62 X(GENERAL, N_("general error"))
63 X(UNKNOWN_PACKET, N_("unknown packet type"))
64 X(UNKNOWN_VERSION,N_("unknown version"))
65 X(PUBKEY_ALGO ,N_("unknown pubkey algorithm"))
66 X(DIGEST_ALGO ,N_("unknown digest algorithm"))
67 X(BAD_PUBKEY ,N_("bad public key"))
68 X(BAD_SECKEY ,N_("bad secret key"))
69 X(BAD_SIGN ,N_("bad signature"))
70 X(CHECKSUM , N_("checksum error"))
71 X(BAD_PASS , N_("bad passphrase"))
72 X(NO_PUBKEY ,N_("public key not found"))
73 X(CIPHER_ALGO ,N_("unknown cipher algorithm"))
74 X(KEYRING_OPEN ,N_("can't open the keyring"))
75 X(INVALID_PACKET ,N_("invalid packet"))
76 X(INVALID_ARMOR ,N_("invalid armor"))
77 X(NO_USER_ID ,N_("no such user id"))
78 X(NO_SECKEY ,N_("secret key not available"))
79 X(WRONG_SECKEY ,N_("wrong secret key used"))
80 X(UNSUPPORTED ,N_("not supported"))
81 X(BAD_KEY ,N_("bad key"))
82 X(READ_FILE ,N_("file read error"))
83 X(WRITE_FILE ,N_("file write error"))
84 X(COMPR_ALGO ,N_("unknown compress algorithm"))
85 X(OPEN_FILE ,N_("file open error"))
86 X(CREATE_FILE ,N_("file create error"))
87 X(PASSPHRASE ,N_("invalid passphrase"))
88 X(NI_PUBKEY ,N_("unimplemented pubkey algorithm"))
89 X(NI_CIPHER ,N_("unimplemented cipher algorithm"))
90 X(SIG_CLASS ,N_("unknown signature class"))
91 X(TRUSTDB ,N_("trust database error"))
92 X(BAD_MPI ,N_("bad MPI"))
93 X(RESOURCE_LIMIT ,N_("resource limit"))
94 X(INV_KEYRING ,N_("invalid keyring"))
95 X(BAD_CERT ,N_("bad certificate"))
96 X(INV_USER_ID ,N_("malformed user id"))
97 X(CLOSE_FILE ,N_("file close error"))
98 X(RENAME_FILE ,N_("file rename error"))
99 X(DELETE_FILE ,N_("file delete error"))
100 X(UNEXPECTED ,N_("unexpected data"))
101 X(TIME_CONFLICT ,N_("timestamp conflict"))
102 X(WR_PUBKEY_ALGO ,N_("unusable pubkey algorithm"))
103 X(FILE_EXISTS ,N_("file exists"))
104 X(WEAK_KEY ,N_("weak key"))
105 X(INV_ARG ,N_("invalid argument"))
106 X(BAD_URI ,N_("bad URI"))
107 X(INVALID_URI ,N_("unsupported URI"))
108 X(NETWORK ,N_("network error"))
109 X(SELFTEST_FAILED,"selftest failed")
110 X(NOT_ENCRYPTED ,N_("not encrypted"))
111 X(NOT_PROCESSED ,N_("not processed"))
112 /* the key cannot be used for a specific usage */
113 X(UNU_PUBKEY ,N_("unusable public key"))
114 X(UNU_SECKEY ,N_("unusable secret key"))
115 X(KEYSERVER ,N_("keyserver error"))
116 X(CANCELED ,N_("canceled"))
117 X(NO_CARD ,N_("no card"))
118 X(NO_DATA ,N_("no data"))
119 default: p = buf; sprintf(buf, "g10err=%d", err); break;
120 }
121 #undef X
122 return _(p);
123 }
- CBB804CBF1D96718EEBC82ABDED7FB63514BA10EFD2EB136A606D85BD1896DBEAA0D631CD87BF01C8C1E014350F5664309EC9136A0D4C6EDF63C039227450926
+
mpi/include/compat.h
(1 . 25)(0 . 0)
128 #ifndef _COMPAT_H_
129 #define _COMPAT_H_
130
131 /* Note this isn't identical to a C locale isspace() without \f and
132 \v, but works for the purposes used here. */
133 #define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t')
134
135 int hextobyte( const char *s );
136 int ascii_toupper (int c);
137 int ascii_tolower (int c);
138 int ascii_strcasecmp( const char *a, const char *b );
139 int ascii_strncasecmp( const char *a, const char *b, size_t n);
140
141 #ifndef HAVE_STRSEP
142 char *strsep (char **stringp, const char *delim);
143 #endif
144
145 #if __GNUC__ >= 4
146 char *xstrconcat (const char *s1, ...) __attribute__ ((sentinel(0)));
147 #else
148 char *xstrconcat (const char *s1, ...);
149 #endif
150
151
152 #endif /* !_COMPAT_H_ */
- F16ECF4FD4CFFB8CB4C97BEE3A486E8FEAAA6CE8C2D70FDF6AB80687847AE8700B2DC199476459401505048D1642B4D94FD2E4152D911E8B6D54065DA09EFE66
+
mpi/include/config.h
(1 . 89)(0 . 0)
157 /* config.h.
158 ORIGINALLY Generated from config.h.in by configure.
159 Cleaned up by hand. The price of this is that the knobs must
160 now be turned by hand.
161 */
162
163 #ifndef GNUPG_CONFIG_H_INCLUDED
164 #define GNUPG_CONFIG_H_INCLUDED
165
166 /* Define to 1 if you have the `atexit' function. */
167 #define HAVE_ATEXIT 1
168
169 /* Defined if the mlock() call does not work */
170 /* #undef HAVE_BROKEN_MLOCK */
171
172 /* Defined if a `byte' is typedef'd */
173 /* #undef HAVE_BYTE_TYPEDEF */
174
175 /* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2)
176 with special properties like no file modes */
177 /* #undef HAVE_DOSISH_SYSTEM */
178
179 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
180 #define HAVE_FSEEKO 1
181
182 /* Define to 1 if you have the `getpagesize' function. */
183 #define HAVE_GETPAGESIZE 1
184
185 /* Define to 1 if you have the <inttypes.h> header file. */
186 #define HAVE_INTTYPES_H 1
187
188 /* Define to 1 if you have the <limits.h> header file. */
189 #define HAVE_LIMITS_H 1
190
191 /* Define to 1 if you have the <locale.h> header file. */
192 // #undef HAVE_LOCALE_H
193
194 /* Define to 1 if you have the `memmove' function. */
195 #define HAVE_MEMMOVE 1
196
197 /* Defined if the system supports an mlock() call */
198 #define HAVE_MLOCK 1
199
200 /* Define to 1 if you have the `mmap' function. */
201 #define HAVE_MMAP 1
202
203 /* Define to 1 if you have the `plock' function. */
204 /* #undef HAVE_PLOCK */
205
206 /* Define to 1 if you have the `raise' function. */
207 #define HAVE_RAISE 1
208
209 /* Define to 1 if you have the `stpcpy' function. */
210 #define HAVE_STPCPY 1
211
212 /* Define to 1 if you have the `strcasecmp' function. */
213 #define HAVE_STRCASECMP 1
214
215 /* Define to 1 if you have the `strerror' function. */
216 #define HAVE_STRERROR 1
217
218 /* Define to 1 if you have the `strlwr' function. */
219 /* #undef HAVE_STRLWR */
220
221 /* Define to 1 if you have the `strncasecmp' function. */
222 #define HAVE_STRNCASECMP 1
223
224 /* Define to 1 if you have the `strsep' function. */
225 #define HAVE_STRSEP 1
226
227 /* Define to 1 if you have the `strtoul' function. */
228 #define HAVE_STRTOUL 1
229
230 /* Define to 1 if you have the `sysconf' function. */
231 #define HAVE_SYSCONF 1
232
233 /* Defined if a `u16' is typedef'd */
234 /* #undef HAVE_U16_TYPEDEF */
235
236 /* Defined if a `u32' is typedef'd */
237 /* #undef HAVE_U32_TYPEDEF */
238
239 /* Defined if a `ulong' is typedef'd */
240 #define HAVE_ULONG_TYPEDEF 1
241
242 /* Defined if a `ushort' is typedef'd */
243 #define HAVE_USHORT_TYPEDEF 1
244
245 #endif /*GNUPG_CONFIG_H_INCLUDED*/
- 6C4FAB042DB987C280EA86471C8549A167903CB11073D0B74A426DC78CE9E65A1B66FB2815722ACB069DF807506181548960E60C33EE27C64246672A8457F752
+
mpi/include/errors.h
(1 . 89)(0 . 0)
250 /* errors.h - erro code
251 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
252 *
253 * This file is part of GNUPG.
254 *
255 * GNUPG is free software; you can redistribute it and/or modify
256 * it under the terms of the GNU General Public License as published by
257 * the Free Software Foundation; either version 3 of the License, or
258 * (at your option) any later version.
259 *
260 * GNUPG is distributed in the hope that it will be useful,
261 * but WITHOUT ANY WARRANTY; without even the implied warranty of
262 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
263 * GNU General Public License for more details.
264 *
265 * You should have received a copy of the GNU General Public License
266 * along with this program; if not, see <http://www.gnu.org/licenses/>.
267 */
268 #ifndef G10_ERRORS_H
269 #define G10_ERRORS_H
270
271 #define G10ERR_GENERAL 1
272 #define G10ERR_UNKNOWN_PACKET 2
273 #define G10ERR_UNKNOWN_VERSION 3 /* Unknown version (in packet) */
274 #define G10ERR_PUBKEY_ALGO 4 /* Unknown pubkey algorithm */
275 #define G10ERR_DIGEST_ALGO 5 /* Unknown digest algorithm */
276 #define G10ERR_BAD_PUBKEY 6 /* Bad public key */
277 #define G10ERR_BAD_SECKEY 7 /* Bad secret key */
278 #define G10ERR_BAD_SIGN 8 /* Bad signature */
279 #define G10ERR_NO_PUBKEY 9 /* public key not found */
280 #define G10ERR_CHECKSUM 10 /* checksum error */
281 #define G10ERR_BAD_PASS 11 /* Bad passphrase */
282 #define G10ERR_CIPHER_ALGO 12 /* Unknown cipher algorithm */
283 #define G10ERR_KEYRING_OPEN 13
284 #define G10ERR_INVALID_PACKET 14
285 #define G10ERR_INVALID_ARMOR 15
286 #define G10ERR_NO_USER_ID 16
287 #define G10ERR_NO_SECKEY 17 /* secret key not available */
288 #define G10ERR_WRONG_SECKEY 18 /* wrong seckey used */
289 #define G10ERR_UNSUPPORTED 19
290 #define G10ERR_BAD_KEY 20 /* bad (session) key */
291 #define G10ERR_READ_FILE 21
292 #define G10ERR_WRITE_FILE 22
293 #define G10ERR_COMPR_ALGO 23 /* Unknown compress algorithm */
294 #define G10ERR_OPEN_FILE 24
295 #define G10ERR_CREATE_FILE 25
296 #define G10ERR_PASSPHRASE 26 /* invalid passphrase */
297 #define G10ERR_NI_PUBKEY 27
298 #define G10ERR_NI_CIPHER 28
299 #define G10ERR_SIG_CLASS 29
300 #define G10ERR_BAD_MPI 30
301 #define G10ERR_RESOURCE_LIMIT 31
302 #define G10ERR_INV_KEYRING 32
303 #define G10ERR_TRUSTDB 33 /* a problem with the trustdb */
304 #define G10ERR_BAD_CERT 34 /* bad certicate */
305 #define G10ERR_INV_USER_ID 35
306 #define G10ERR_CLOSE_FILE 36
307 #define G10ERR_RENAME_FILE 37
308 #define G10ERR_DELETE_FILE 38
309 #define G10ERR_UNEXPECTED 39
310 #define G10ERR_TIME_CONFLICT 40
311 #define G10ERR_WR_PUBKEY_ALGO 41 /* unusabe pubkey algo */
312 #define G10ERR_FILE_EXISTS 42
313 #define G10ERR_WEAK_KEY 43 /* NOTE: hardcoded into the cipher modules */
314 #define G10ERR_WRONG_KEYLEN 44 /* NOTE: hardcoded into the cipher modules */
315 #define G10ERR_INV_ARG 45
316 #define G10ERR_BAD_URI 46 /* syntax error in URI */
317 #define G10ERR_INVALID_URI 47 /* e.g. unsupported scheme */
318 #define G10ERR_NETWORK 48 /* general network error */
319 #define G10ERR_UNKNOWN_HOST 49
320 #define G10ERR_SELFTEST_FAILED 50
321 #define G10ERR_NOT_ENCRYPTED 51
322 #define G10ERR_NOT_PROCESSED 52
323 #define G10ERR_UNU_PUBKEY 53
324 #define G10ERR_UNU_SECKEY 54
325 #define G10ERR_KEYSERVER 55
326 #define G10ERR_CANCELED 56
327 #define G10ERR_NO_CARD 57
328 #define G10ERR_NO_DATA 58
329
330 #ifndef HAVE_STRERROR
331 char *strerror (int n);
332 #endif
333
334 #ifdef _WIN32
335 const char * w32_strerror (int w32_errno);
336 #endif
337
338 #endif /*G10_ERRORS_H*/
- 42269E10B09731558FE6D6E4F8D52F3C3CE10AD1C67496E22F7EC0E19C6D6586F1491921486E90A468905A68D6414D7B7F68914582206CCC2CE2E3ED1E2D3F3D
+
mpi/include/iobuf.h
(1 . 161)(0 . 0)
343 /* iobuf.h - I/O buffer
344 * Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
345 *
346 * This file is part of GNUPG.
347 *
348 * GNUPG is free software; you can redistribute it and/or modify
349 * it under the terms of the GNU General Public License as published by
350 * the Free Software Foundation; either version 3 of the License, or
351 * (at your option) any later version.
352 *
353 * GNUPG is distributed in the hope that it will be useful,
354 * but WITHOUT ANY WARRANTY; without even the implied warranty of
355 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356 * GNU General Public License for more details.
357 *
358 * You should have received a copy of the GNU General Public License
359 * along with this program; if not, see <http://www.gnu.org/licenses/>.
360 */
361
362 #ifndef G10_IOBUF_H
363 #define G10_IOBUF_H
364
365 #include "types.h"
366
367
368 #define DBG_IOBUF iobuf_debug_mode
369
370 #define IOBUFCTRL_INIT 1
371 #define IOBUFCTRL_FREE 2
372 #define IOBUFCTRL_UNDERFLOW 3
373 #define IOBUFCTRL_FLUSH 4
374 #define IOBUFCTRL_DESC 5
375 #define IOBUFCTRL_CANCEL 6
376 #define IOBUFCTRL_USER 16
377
378 typedef struct iobuf_struct *IOBUF;
379 typedef struct iobuf_struct *iobuf_t;
380
381 /* fixme: we should hide most of this stuff */
382 struct iobuf_struct {
383 int use; /* 1 input , 2 output, 3 temp */
384 off_t nlimit;
385 off_t nbytes; /* used together with nlimit */
386 off_t ntotal; /* total bytes read (position of stream) */
387 int nofast; /* used by the iobuf_get() */
388 void *directfp;
389 struct {
390 size_t size; /* allocated size */
391 size_t start; /* number of invalid bytes at the begin of the buffer */
392 size_t len; /* currently filled to this size */
393 byte *buf;
394 } d;
395 int filter_eof;
396 int error;
397 int (*filter)( void *opaque, int control,
398 IOBUF chain, byte *buf, size_t *len);
399 void *filter_ov; /* value for opaque */
400 int filter_ov_owner;
401 char *real_fname;
402 IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */
403 int no, subno;
404 const char *desc;
405 void *opaque; /* can be used to hold any information */
406 /* this value is copied to all instances */
407 struct {
408 size_t size; /* allocated size */
409 size_t start; /* number of invalid bytes at the begin of the buffer */
410 size_t len; /* currently filled to this size */
411 byte *buf;
412 } unget;
413 };
414
415 #ifndef EXTERN_UNLESS_MAIN_MODULE
416 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
417 #define EXTERN_UNLESS_MAIN_MODULE extern
418 #else
419 #define EXTERN_UNLESS_MAIN_MODULE
420 #endif
421 #endif
422 EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
423
424 void iobuf_enable_special_filenames ( int yes );
425 int iobuf_is_pipe_filename (const char *fname);
426 IOBUF iobuf_alloc(int use, size_t bufsize);
427 IOBUF iobuf_temp(void);
428 IOBUF iobuf_temp_with_content( const char *buffer, size_t length );
429 IOBUF iobuf_open( const char *fname );
430 IOBUF iobuf_fdopen( int fd, const char *mode );
431 IOBUF iobuf_sockopen( int fd, const char *mode );
432 IOBUF iobuf_create( const char *fname );
433 IOBUF iobuf_append( const char *fname );
434 IOBUF iobuf_openrw( const char *fname );
435 int iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval );
436 int iobuf_close( IOBUF iobuf );
437 int iobuf_cancel( IOBUF iobuf );
438
439 int iobuf_push_filter( IOBUF a, int (*f)(void *opaque, int control,
440 IOBUF chain, byte *buf, size_t *len), void *ov );
441 int iobuf_push_filter2( IOBUF a,
442 int (*f)(void *opaque, int control,
443 IOBUF chain, byte *buf, size_t *len),
444 void *ov, int rel_ov );
445 int iobuf_flush(IOBUF a);
446 void iobuf_clear_eof(IOBUF a);
447 #define iobuf_set_error(a) do { (a)->error = 1; } while(0)
448 #define iobuf_error(a) ((a)->error)
449
450 void iobuf_set_limit( IOBUF a, off_t nlimit );
451
452 off_t iobuf_tell( IOBUF a );
453 int iobuf_seek( IOBUF a, off_t newpos );
454
455 int iobuf_readbyte(IOBUF a);
456 int iobuf_read(IOBUF a, byte *buf, unsigned buflen );
457 unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer,
458 unsigned *length_of_buffer, unsigned *max_length );
459 int iobuf_peek(IOBUF a, byte *buf, unsigned buflen );
460 int iobuf_writebyte(IOBUF a, unsigned c);
461 int iobuf_write(IOBUF a, byte *buf, unsigned buflen );
462 int iobuf_writestr(IOBUF a, const char *buf );
463
464 void iobuf_flush_temp( IOBUF temp );
465 int iobuf_write_temp( IOBUF a, IOBUF temp );
466 size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen );
467 void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp );
468
469 int iobuf_get_fd (IOBUF a);
470 off_t iobuf_get_filelength (IOBUF a, int *overflow);
471 #define IOBUF_FILELENGTH_LIMIT 0xffffffff
472 const char *iobuf_get_real_fname( IOBUF a );
473 const char *iobuf_get_fname( IOBUF a );
474
475 void iobuf_set_partial_block_mode( IOBUF a, size_t len );
476
477 int iobuf_translate_file_handle ( int fd, int for_write );
478
479 /* Get a byte form the iobuf; must check for eof prior to this function.
480 * This function returns values in the range 0 .. 255 or -1 to indicate EOF
481 * iobuf_get_noeof() does not return -1 to indicate EOF, but masks the
482 * returned value to be in the range 0..255.
483 */
484 #define iobuf_get(a) \
485 ( ((a)->nofast || (a)->d.start >= (a)->d.len )? \
486 iobuf_readbyte((a)) : ( (a)->nbytes++, (a)->d.buf[(a)->d.start++] ) )
487 #define iobuf_get_noeof(a) (iobuf_get((a))&0xff)
488
489 /* write a byte to the iobuf and return true on write error
490 * This macro does only write the low order byte
491 */
492 #define iobuf_put(a,c) iobuf_writebyte(a,c)
493
494 #define iobuf_where(a) "[don't know]"
495 #define iobuf_id(a) ((a)->no)
496
497 #define iobuf_get_temp_buffer(a) ( (a)->d.buf )
498 #define iobuf_get_temp_length(a) ( (a)->d.len )
499 #define iobuf_is_temp(a) ( (a)->use == 3 )
500
501 void iobuf_skip_rest (IOBUF a, unsigned long n, int partial);
502
503 #endif /*G10_IOBUF_H*/
-
+ A441A78465E16D369E66F080D444BC97EF7C0E0D9208E88565D8646A1B31BACAC8B39411C4092C2FC56BD07CDF8FD686940F18424BF1928C9220B68B46840330
mpi/include/knobs.h
(0 . 0)(1 . 75)
508 /* knobs.h -- Originally generated from config.h.in by autoconf.
509 * But there is no more autoconf in this project.
510 *
511 * No Such Labs. (C) 2015. See README.
512 *
513 * This program is free software: you can redistribute it and/or modify
514 * it under the terms of the GNU General Public License as published by
515 * the Free Software Foundation, either version 3 of the License, or
516 * (at your option) any later version.
517 *
518 * This program is distributed in the hope that it will be useful,
519 * but WITHOUT ANY WARRANTY; without even the implied warranty of
520 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
521 * GNU General Public License for more details.
522 *
523 * You should have received a copy of the GNU General Public License
524 * along with this program. If not, see <http://www.gnu.org/licenses/>.
525 */
526
527 #ifndef GNUPG_CONFIG_H_INCLUDED
528 #define GNUPG_CONFIG_H_INCLUDED
529
530 /* Report memory usage. */
531 //#define M_DEBUG 1
532
533 /* Define to 1 if you have the `atexit' function. */
534 #define HAVE_ATEXIT 1
535
536 /* Defined if the mlock() call does not work */
537 /* #undef HAVE_BROKEN_MLOCK */
538
539 /* Defined if a `byte' is typedef'd */
540 /* #undef HAVE_BYTE_TYPEDEF */
541
542 /* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2)
543 with special properties like no file modes */
544 /* #undef HAVE_DOSISH_SYSTEM */
545
546 /* Define to 1 if you have the `getpagesize' function. */
547 #define HAVE_GETPAGESIZE 1
548
549 /* Define to 1 if you have the <inttypes.h> header file. */
550 #define HAVE_INTTYPES_H 1
551
552 /* Define to 1 if you have the `memmove' function. */
553 #define HAVE_MEMMOVE 1
554
555 /* Defined if the system supports an mlock() call */
556 #define HAVE_MLOCK 1
557
558 /* Define to 1 if you have the `mmap' function. */
559 #define HAVE_MMAP 1
560
561 /* Define to 1 if you have the `plock' function. */
562 /* #undef HAVE_PLOCK */
563
564 /* Define to 1 if you have the `raise' function. */
565 #define HAVE_RAISE 1
566
567 /* Define to 1 if you have the `sysconf' function. */
568 #define HAVE_SYSCONF 1
569
570 /* Defined if a `u16' is typedef'd */
571 /* #undef HAVE_U16_TYPEDEF */
572
573 /* Defined if a `u32' is typedef'd */
574 /* #undef HAVE_U32_TYPEDEF */
575
576 /* Defined if a `ulong' is typedef'd */
577 #define HAVE_ULONG_TYPEDEF 1
578
579 /* Defined if a `ushort' is typedef'd */
580 #define HAVE_USHORT_TYPEDEF 1
581
582 #endif /*GNUPG_CONFIG_H_INCLUDED*/
- 042BA62021E6A33FA5F28447D8D268D4FD9A66D49BD10B904AA5F5C9FB6A30345F5CFEA787FBA1145B328F56E77C39E4D7C3D6DF94CCD4B7696B9FE2C8AA7055
+ A4A9188BECDE0BEF5A0F54061C6758B618A85CE7C483AF33F5D7655EB1CE7165A8FFC185BF37AE4D3781DEAB518DB3D4FE946692406DE0BD73212331EF400F27
mpi/include/longlong.h
(1 . 22)(1 . 24)
587 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
588 Note: I added some stuff for use with gnupg
589
590 Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998,
591 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
592
593 This file is free software; you can redistribute it and/or modify
594 it under the terms of the GNU Lesser General Public License as published by
595 the Free Software Foundation; either version 2.1 of the License, or (at your
596 option) any later version.
597
598 This file is distributed in the hope that it will be useful, but
599 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
600 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
601 License for more details.
602
603 You should have received a copy of the GNU Lesser General Public License
604 along with this file; if not, see <http://www.gnu.org/licenses/>. */
605
606 * Modified by No Such Labs. (C) 2015. See README.
607 *
608 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
609 * SHA256(gnupg-1.4.10.tar.gz):
610 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
611 * (C) 1994-2005 Free Software Foundation, Inc.
612 *
613 * This program is free software: you can redistribute it and/or modify
614 * it under the terms of the GNU General Public License as published by
615 * the Free Software Foundation, either version 3 of the License, or
616 * (at your option) any later version.
617 *
618 * This program is distributed in the hope that it will be useful,
619 * but WITHOUT ANY WARRANTY; without even the implied warranty of
620 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
621 * GNU General Public License for more details.
622 *
623 * You should have received a copy of the GNU General Public License
624 * along with this program. If not, see <http://www.gnu.org/licenses/>.
625 */
626
627 /* You have to define the following before including this file:
628
- B48416427E71FE46868283490813E4D0A22DA9F4B17EFF706673A9B05380AE2D85EC9B183DB47EAA8AA197B7C7629EB873E63E5F8A66208BF230A794B6967FAB
+ 6580645F16FEA9A37EFF8460584FCA09F39B1EC9BA88E00AA0207C75267F7190810CF45F2733C9960AAEC0DAAAC7FE74785F38287AA61CB4CD5D4F50EA1158C9
mpi/include/memory.h
(1 . 34)(1 . 36)
633 /* memory.h - memory allocation
634 * Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
635 * Modified by No Such Labs. (C) 2015. See README.
636 *
637 * This file is part of GNUPG.
638 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
639 * SHA256(gnupg-1.4.10.tar.gz):
640 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
641 * (C) 1994-2005 Free Software Foundation, Inc.
642 *
643 * GNUPG is free software; you can redistribute it and/or modify
644 * This program is free software: you can redistribute it and/or modify
645 * it under the terms of the GNU General Public License as published by
646 * the Free Software Foundation; either version 3 of the License, or
647 * the Free Software Foundation, either version 3 of the License, or
648 * (at your option) any later version.
649 *
650 * GNUPG is distributed in the hope that it will be useful,
651 * This program is distributed in the hope that it will be useful,
652 * but WITHOUT ANY WARRANTY; without even the implied warranty of
653 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
654 * GNU General Public License for more details.
655 *
656 * You should have received a copy of the GNU General Public License
657 * along with this program; if not, see <http://www.gnu.org/licenses/>.
658 * along with this program. If not, see <http://www.gnu.org/licenses/>.
659 */
660
661 #ifndef G10_MEMORY_H
662 #define G10_MEMORY_H
663
664 #ifdef M_DEBUG
665
666 #ifndef STR
667 #define STR(v) #v
668 #endif
669 #ifndef __riscos__
670
671 #define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]"
672 #else /* __riscos__ */
673 #define M_DBGINFO(a) "["__FILE__ ":" STR(a) "]"
674 #endif /* __riscos__ */
675
676 #define xmalloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) )
677 #define xtrymalloc(n) m_debug_trymalloc ((n), M_DBGINFO( __LINE__ ))
678 #define xmalloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) )
(91 . 12)(93 . 8)
680 #define DBG_MEMSTAT memory_stat_debug_mode
681
682 #ifndef EXTERN_UNLESS_MAIN_MODULE
683 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
684 #define EXTERN_UNLESS_MAIN_MODULE extern
685 #else
686 #define EXTERN_UNLESS_MAIN_MODULE
687 #endif
688 #endif
689 EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode;
690 EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
691
- FB2AFC7686790FA12E3143E79C4728DAC3E43C4056C647650D216B7EC7350F7651F6C44C4393858E8BAB02719B7674AD7F29E1FCB10511DE0A5AE4A2C12AF5A6
+
mpi/include/mpi-asm-defs.h
(1 . 10)(0 . 0)
696 /* This file defines some basic constants for the MPI machinery. We
697 * need to define the types on a per-CPU basis, so it is done with
698 * this file here. */
699 #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG)
700
701
702
703
704
705
- E539EF777487B66317CD23B7D19F883A9BAB67A9CB984DFB5D1A5DF4575A66CB44B7EC199AC0829B1270EDFA68F182D646CE944C14F5C401654E1E0F68271BAF
+ 0BC1BE9F757231B114821A55B106387358B919237DCEDC3C4F23C0DF61F7ACD00656CEFBA6A48313304FCFBCE2ABF528EC2FBA998C0F67784DE486D00B8F6CC2
mpi/include/mpi.h
(1 . 47)(1 . 36)
710 /* mpi.h - Multi Precision Integers
711 * Copyright (C) 1994, 1996, 1998, 1999,
712 * 2000, 2001 Free Software Foundation, Inc.
713 * Modified by No Such Labs. (C) 2015. See README.
714 *
715 * This file is part of GNUPG.
716 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
717 * SHA256(gnupg-1.4.10.tar.gz):
718 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
719 * (C) 1994-2005 Free Software Foundation, Inc.
720 *
721 * GNUPG is free software; you can redistribute it and/or modify
722 * This program is free software: you can redistribute it and/or modify
723 * it under the terms of the GNU General Public License as published by
724 * the Free Software Foundation; either version 3 of the License, or
725 * the Free Software Foundation, either version 3 of the License, or
726 * (at your option) any later version.
727 *
728 * GNUPG is distributed in the hope that it will be useful,
729 * This program is distributed in the hope that it will be useful,
730 * but WITHOUT ANY WARRANTY; without even the implied warranty of
731 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
732 * GNU General Public License for more details.
733 *
734 * You should have received a copy of the GNU General Public License
735 * along with this program; if not, see <http://www.gnu.org/licenses/>.
736 *
737 * Note: This code is heavily based on the GNU MP Library.
738 * Actually it's the same code with only minor changes in the
739 * way the data is stored; this is to support the abstraction
740 * of an optional secure memory allocation which may be used
741 * to avoid revealing of sensitive data due to paging etc.
742 * The GNU MP Library itself is published under the LGPL;
743 * however I decided to publish this code under the plain GPL.
744 * along with this program. If not, see <http://www.gnu.org/licenses/>.
745 */
746
747 #ifndef G10_MPI_H
748 #define G10_MPI_H
749
750 #include <config.h>
751 #include <stdio.h>
752 #include "iobuf.h"
753 #include "knobs.h"
754 #include "types.h"
755 #include "memory.h"
756
757 #ifndef EXTERN_UNLESS_MAIN_MODULE
758 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
759 #define EXTERN_UNLESS_MAIN_MODULE extern
760 #else
761 #define EXTERN_UNLESS_MAIN_MODULE
762 #endif
763 #endif
764
765 #define DBG_MPI mpi_debug_mode
766 EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode;
(92 . 18)(81 . 10)
768 unsigned int mpi_get_flags (MPI a);
769
770 /*-- mpicoder.c --*/
771 int mpi_write( IOBUF out, MPI a );
772 #ifdef M_DEBUG
773 #define mpi_read(a,b,c) mpi_debug_read((a),(b),(c), M_DBGINFO( __LINE__ ) )
774 MPI mpi_debug_read(IOBUF inp, unsigned *nread, int secure, const char *info);
775 #else
776 MPI mpi_read(IOBUF inp, unsigned *nread, int secure);
777 #endif
778 MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
779 int mpi_fromstr(MPI val, const char *str);
780 int mpi_print( FILE *fp, MPI a, int mode );
781 void g10_log_mpidump( const char *text, MPI a );
782 u32 mpi_get_keyid( MPI a, u32 *keyid );
783 //void g10_log_mpidump( const char *text, MPI a );
784 byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign );
785 byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign );
786 void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign );
- DF6064B02A11C90FB20945DAD1ECC4753A231F894D6CF60E133D6196D924442E0FA08C1D38421A97511F4007A9545C6A980960A20817E6EAECF4CE36E920F151
+ F1A5F8EE7289D1AA4526A7AE2CABE769EE43FA525AE47658A12D6856B51174D174C96CD1E93BE6836BB29F53725BE73649A0AF667CDD4E71A08431B984BDA8C4
mpi/include/mpi-inline.h
(1 . 28)(1 . 23)
791 /* mpi-inline.h - Internal to the Multi Precision Integers
792 * Copyright (C) 1994, 1996, 1998, 1999 Free Software Foundation, Inc.
793 * Modified by No Such Labs. (C) 2015. See README.
794 *
795 * This file is part of GnuPG.
796 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
797 * SHA256(gnupg-1.4.10.tar.gz):
798 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
799 * (C) 1994-2005 Free Software Foundation, Inc.
800 *
801 * GnuPG is free software; you can redistribute it and/or modify
802 * This program is free software: you can redistribute it and/or modify
803 * it under the terms of the GNU General Public License as published by
804 * the Free Software Foundation; either version 3 of the License, or
805 * the Free Software Foundation, either version 3 of the License, or
806 * (at your option) any later version.
807 *
808 * GnuPG is distributed in the hope that it will be useful,
809 * This program is distributed in the hope that it will be useful,
810 * but WITHOUT ANY WARRANTY; without even the implied warranty of
811 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
812 * GNU General Public License for more details.
813 *
814 * You should have received a copy of the GNU General Public License
815 * along with this program; if not, see <http://www.gnu.org/licenses/>.
816 *
817 * Note: This code is heavily based on the GNU MP Library.
818 * Actually it's the same code with only minor changes in the
819 * way the data is stored; this is to support the abstraction
820 * of an optional secure memory allocation which may be used
821 * to avoid revealing of sensitive data due to paging etc.
822 * The GNU MP Library itself is published under the LGPL;
823 * however I decided to publish this code under the plain GPL.
824 * along with this program. If not, see <http://www.gnu.org/licenses/>.
825 */
826
827 #ifndef G10_MPI_INLINE_H
- 98C4253D69C7531F96DC7631D3D26C5733D5104A3DDBD9EAFD622F8AACD8619E71ABB55D0C951B148E9D33887DAB0EDF2CBD9C9B38CA908BC8E04ED930943FDE
+ D1B3EAED32DC555D5F779EDE28A995D2AC6BF3A5BF87362955675B11BAD91A928FBF62B7FC7FCA5EF1A2C8D33409978EF73D5D879564ED3829C5FC6DACD6CDFD
mpi/include/mpi-internal.h
(1 . 36)(1 . 32)
832 /* mpi-internal.h - Internal to the Multi Precision Integers
833 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
834 * Copyright (C) 1998, 2000 Free Software Foundation, Inc.
835 * Modified by No Such Labs. (C) 2015. See README.
836 *
837 * This file is part of GnuPG.
838 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
839 * SHA256(gnupg-1.4.10.tar.gz):
840 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
841 * (C) 1994-2005 Free Software Foundation, Inc.
842 *
843 * GnuPG is free software; you can redistribute it and/or modify
844 * This program is free software: you can redistribute it and/or modify
845 * it under the terms of the GNU General Public License as published by
846 * the Free Software Foundation; either version 3 of the License, or
847 * the Free Software Foundation, either version 3 of the License, or
848 * (at your option) any later version.
849 *
850 * GnuPG is distributed in the hope that it will be useful,
851 * This program is distributed in the hope that it will be useful,
852 * but WITHOUT ANY WARRANTY; without even the implied warranty of
853 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
854 * GNU General Public License for more details.
855 *
856 * You should have received a copy of the GNU General Public License
857 * along with this program; if not, see <http://www.gnu.org/licenses/>.
858 *
859 * Note: This code is heavily based on the GNU MP Library.
860 * Actually it's the same code with only minor changes in the
861 * way the data is stored; this is to support the abstraction
862 * of an optional secure memory allocation which may be used
863 * to avoid revealing of sensitive data due to paging etc.
864 * The GNU MP Library itself is published under the LGPL;
865 * however I decided to publish this code under the plain GPL.
866 * along with this program. If not, see <http://www.gnu.org/licenses/>.
867 */
868
869 #ifndef G10_MPI_INTERNAL_H
870 #define G10_MPI_INTERNAL_H
871
872 #include "mpi.h"
873 #include "mpi-asm-defs.h"
874
875 /* from the old mpi-asm-defs.h */
876 #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG)
877
878 #if BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_INT
879 typedef unsigned int mpi_limb_t;
- 85D1DE1E79681B0CECE4CAEA7CA324374FB41317C449585E8CD4D23FAE4EF10923285545645FAC2921D3C53A0C897E33DA32D895B9BD0B761F696D0D8E036479
+
mpi/include/ttyio.h
(1 . 58)(0 . 0)
884 /* ttyio.h
885 * Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
886 *
887 * This file is part of GNUPG.
888 *
889 * GNUPG is free software; you can redistribute it and/or modify
890 * it under the terms of the GNU General Public License as published by
891 * the Free Software Foundation; either version 3 of the License, or
892 * (at your option) any later version.
893 *
894 * GNUPG is distributed in the hope that it will be useful,
895 * but WITHOUT ANY WARRANTY; without even the implied warranty of
896 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
897 * GNU General Public License for more details.
898 *
899 * You should have received a copy of the GNU General Public License
900 * along with this program; if not, see <http://www.gnu.org/licenses/>.
901 */
902 #ifndef G10_TTYIO_H
903 #define G10_TTYIO_H
904
905 #ifdef HAVE_LIBREADLINE
906 #include <stdio.h>
907 #include <readline/readline.h>
908 #endif
909
910 const char *tty_get_ttyname (void);
911 int tty_batchmode( int onoff );
912 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
913 void tty_printf (const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
914 void tty_fprintf (FILE *fp, const char *fmt, ... )
915 __attribute__ ((format (printf,2,3)));
916 #else
917 void tty_printf (const char *fmt, ... );
918 void tty_fprintf (FILE *fp, const char *fmt, ... );
919 #endif
920 void tty_print_string( const byte *p, size_t n );
921 void tty_print_utf8_string( const byte *p, size_t n );
922 void tty_print_utf8_string2( const byte *p, size_t n, size_t max_n );
923 char *tty_get( const char *prompt );
924 char *tty_get_hidden( const char *prompt );
925 void tty_kill_prompt(void);
926 int tty_get_answer_is_yes( const char *prompt );
927 int tty_no_terminal(int onoff);
928
929 #ifdef HAVE_LIBREADLINE
930 void tty_enable_completion(rl_completion_func_t *completer);
931 void tty_disable_completion(void);
932 #else
933 /* Use a macro to stub out these functions since a macro has no need
934 to typedef a "rl_completion_func_t" which would be undefined
935 without readline. */
936 #define tty_enable_completion(x)
937 #define tty_disable_completion()
938 #endif
939 void tty_cleanup_after_signal (void);
940
941 #endif /*G10_TTYIO_H*/
- D355F8BB711647E95451CF2D53F8C496013D9C797ACC81560FAE155C5850823C880D647347426A4562DA568A6CDE708FDCCBD1E881568816156C0801C7E47FD7
+ 7080AB52C460BB847F724212473D3F0B93AA44175577E977E937BC2246E11BE0B0BA2439B9E1053A1C898B606617717260D61937D7BA70B034B77CED2149EA83
mpi/include/types.h
(1 . 20)(1 . 23)
946 /* types.h - some common typedefs
947 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
948 * Modified by No Such Labs. (C) 2015. See README.
949 *
950 * This file is part of GNUPG.
951 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
952 * SHA256(gnupg-1.4.10.tar.gz):
953 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
954 * (C) 1994-2005 Free Software Foundation, Inc.
955 *
956 * GNUPG is free software; you can redistribute it and/or modify
957 * This program is free software: you can redistribute it and/or modify
958 * it under the terms of the GNU General Public License as published by
959 * the Free Software Foundation; either version 3 of the License, or
960 * the Free Software Foundation, either version 3 of the License, or
961 * (at your option) any later version.
962 *
963 * GNUPG is distributed in the hope that it will be useful,
964 * This program is distributed in the hope that it will be useful,
965 * but WITHOUT ANY WARRANTY; without even the implied warranty of
966 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
967 * GNU General Public License for more details.
968 *
969 * You should have received a copy of the GNU General Public License
970 * along with this program; if not, see <http://www.gnu.org/licenses/>.
971 * along with this program. If not, see <http://www.gnu.org/licenses/>.
972 */
973
974 #ifndef G10_TYPES_H
(46 . 14)(49 . 7)
976
977 #ifndef HAVE_BYTE_TYPEDEF
978 #undef byte /* maybe there is a macro with this name */
979 #ifndef __riscos__
980 typedef unsigned char byte;
981 #else
982 /* Norcroft treats char = unsigned char as legal assignment
983 but char* = unsigned char* as illegal assignment
984 and the same applies to the signed variants as well */
985 typedef char byte;
986 #endif
987 #define HAVE_BYTE_TYPEDEF
988 #endif
989
- 5B4ADEDB0DDA25D37413FD81037EF2D94722CEE3B58B5A5314DA3816308540588319A280819E272845D154B6F2FDBDCECE3A73C15B2802F33BC6BFE484F0B4A5
+ 60F97FC937B6974E1AD4AA0D6728491D71127244D9FF43369612222359802A7816F57FE6060354582782A04CE62B6568BABAC0A0BF886FD6D8CBE3A17F540BCA
mpi/include/util.h
(1 . 22)(1 . 25)
994 /* util.h
995 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
996 * 2006 Free Software Foundation, Inc.
997 * Modified by No Such Labs. (C) 2015. See README.
998 *
999 * This file is part of GNUPG.
1000 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1001 * SHA256(gnupg-1.4.10.tar.gz):
1002 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1003 * (C) 1994-2005 Free Software Foundation, Inc.
1004 *
1005 * GNUPG is free software; you can redistribute it and/or modify
1006 * This program is free software: you can redistribute it and/or modify
1007 * it under the terms of the GNU General Public License as published by
1008 * the Free Software Foundation; either version 3 of the License, or
1009 * the Free Software Foundation, either version 3 of the License, or
1010 * (at your option) any later version.
1011 *
1012 * GNUPG is distributed in the hope that it will be useful,
1013 * This program is distributed in the hope that it will be useful,
1014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1016 * GNU General Public License for more details.
1017 *
1018 * You should have received a copy of the GNU General Public License
1019 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1020 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1021 */
1022
1023 #ifndef G10_UTIL_H
1024 #define G10_UTIL_H
1025
(25 . 244)(28 . 25)
1027 #endif
1028
1029 #include "types.h"
1030 #include "errors.h"
1031 #include "types.h"
1032 #include "mpi.h"
1033 #include "compat.h"
1034
1035 typedef struct {
1036 int *argc; /* pointer to argc (value subject to change) */
1037 char ***argv; /* pointer to argv (value subject to change) */
1038 unsigned flags; /* Global flags (DO NOT CHANGE) */
1039 int err; /* print error about last option */
1040 /* 1 = warning, 2 = abort */
1041 int r_opt; /* return option */
1042 int r_type; /* type of return value (0 = no argument found)*/
1043 union {
1044 int ret_int;
1045 long ret_long;
1046 ulong ret_ulong;
1047 char *ret_str;
1048 } r; /* Return values */
1049 struct {
1050 int idx;
1051 int inarg;
1052 int stopped;
1053 const char *last;
1054 void *aliases;
1055 const void *cur_alias;
1056 } internal; /* DO NOT CHANGE */
1057 } ARGPARSE_ARGS;
1058
1059 typedef struct {
1060 int short_opt;
1061 const char *long_opt;
1062 unsigned flags;
1063 const char *description; /* optional option description */
1064 } ARGPARSE_OPTS;
1065
1066 /*-- logger.c --*/
1067 void log_set_logfile( const char *name, int fd );
1068 FILE *log_stream(void);
1069 void g10_log_print_prefix(const char *text);
1070 void log_set_name( const char *name );
1071 const char *log_get_name(void);
1072 void log_set_pid( int pid );
1073 int log_get_errorcount( int clear );
1074 void log_inc_errorcount(void);
1075 int log_set_strict(int val);
1076 void g10_log_hexdump( const char *text, const char *buf, size_t len );
1077
1078 #if defined (__riscos__) \
1079 || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
1080 void g10_log_bug( const char *fmt, ... )
1081 __attribute__ ((noreturn, format (printf,1,2)));
1082 void g10_log_bug0( const char *, int, const char * ) __attribute__ ((noreturn));
1083 void g10_log_fatal( const char *fmt, ... )
1084 __attribute__ ((noreturn, format (printf,1,2)));
1085 void g10_log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1086 void g10_log_info( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1087 void g10_log_warning( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1088 void g10_log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1089 #ifndef __riscos__
1090 #define BUG() g10_log_bug0( __FILE__ , __LINE__, __FUNCTION__ )
1091 #else
1092 #define BUG() g10_log_bug0( __FILE__ , __LINE__, __func__ )
1093 #endif
1094 #else
1095 void g10_log_bug( const char *fmt, ... );
1096 void g10_log_bug0( const char *, int );
1097 void g10_log_fatal( const char *fmt, ... );
1098 void g10_log_error( const char *fmt, ... );
1099 void g10_log_info( const char *fmt, ... );
1100 void g10_log_warning( const char *fmt, ... );
1101 void g10_log_debug( const char *fmt, ... );
1102 #define BUG() g10_log_bug0( __FILE__ , __LINE__ )
1103 #endif
1104 #define log_hexdump printf
1105 #define log_bug printf
1106 #define log_bug0 printf
1107 #define log_fatal printf
1108 #define log_error printf
1109 #define log_info printf
1110 #define log_warning printf
1111 #define log_debug printf
1112
1113 #define g10_log_print_prefix printf
1114
1115 #define log_hexdump g10_log_hexdump
1116 #define log_bug g10_log_bug
1117 #define log_bug0 g10_log_bug0
1118 #define log_fatal g10_log_fatal
1119 #define log_error g10_log_error
1120 #define log_info g10_log_info
1121 #define log_warning g10_log_warning
1122 #define log_debug g10_log_debug
1123
1124
1125 /*-- errors.c --*/
1126 const char * g10_errstr( int no );
1127
1128 /*-- argparse.c --*/
1129 int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
1130 int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
1131 ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
1132 void usage( int level );
1133 const char *default_strusage( int level );
1134
1135
1136 /*-- (main program) --*/
1137 const char *strusage( int level );
1138
1139
1140 /*-- dotlock.c --*/
1141 struct dotlock_handle;
1142 typedef struct dotlock_handle *DOTLOCK;
1143
1144 void disable_dotlock(void);
1145 DOTLOCK create_dotlock( const char *file_to_lock );
1146 void destroy_dotlock ( DOTLOCK h );
1147 int make_dotlock( DOTLOCK h, long timeout );
1148 int release_dotlock( DOTLOCK h );
1149 void remove_lockfiles (void);
1150
1151 /*-- fileutil.c --*/
1152 char * make_basename(const char *filepath, const char *inputpath);
1153 char * make_dirname(const char *filepath);
1154 char *make_filename( const char *first_part, ... );
1155 int compare_filenames( const char *a, const char *b );
1156 int same_file_p (const char *name1, const char *name2);
1157 const char *print_fname_stdin( const char *s );
1158 const char *print_fname_stdout( const char *s );
1159 int is_file_compressed(const char *s, int *r_status);
1160
1161 /*-- miscutil.c --*/
1162 u32 make_timestamp(void);
1163 u32 scan_isodatestr( const char *string );
1164 u32 isotime2seconds (const char *string);
1165 const char *strtimevalue( u32 stamp );
1166 const char *strtimestamp( u32 stamp ); /* GMT */
1167 const char *isotimestamp( u32 stamp ); /* GMT with hh:mm:ss */
1168 const char *asctimestamp( u32 stamp ); /* localized */
1169 void print_string( FILE *fp, const byte *p, size_t n, int delim );
1170 void print_string2( FILE *fp, const byte *p, size_t n, int delim, int delim2 );
1171 void print_utf8_string( FILE *fp, const byte *p, size_t n );
1172 void print_utf8_string2( FILE *fp, const byte *p, size_t n, int delim);
1173 char *make_printable_string( const byte *p, size_t n, int delim );
1174 int answer_is_yes_no_default( const char *s, int def_answer );
1175 int answer_is_yes( const char *s );
1176 int answer_is_yes_no_quit( const char *s );
1177 int answer_is_okay_cancel (const char *s, int def_answer);
1178 int match_multistr(const char *multistr,const char *match);
1179
1180 /*-- strgutil.c --*/
1181 void free_strlist( STRLIST sl );
1182 #define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0)
1183 STRLIST add_to_strlist( STRLIST *list, const char *string );
1184 STRLIST add_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
1185 STRLIST append_to_strlist( STRLIST *list, const char *string );
1186 STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
1187 STRLIST strlist_prev( STRLIST head, STRLIST node );
1188 STRLIST strlist_last( STRLIST node );
1189 char *pop_strlist( STRLIST *list );
1190 const char *memistr( const char *buf, size_t buflen, const char *sub );
1191 const char *ascii_memistr( const char *buf, size_t buflen, const char *sub );
1192 char *mem2str( char *, const void *, size_t);
1193 char *trim_spaces( char *string );
1194 unsigned int trim_trailing_chars( byte *line, unsigned int len,
1195 const char *trimchars);
1196 unsigned int trim_trailing_ws( byte *line, unsigned len );
1197 unsigned int check_trailing_chars( const byte *line, unsigned int len,
1198 const char *trimchars );
1199 unsigned int check_trailing_ws( const byte *line, unsigned int len );
1200 int string_count_chr( const char *string, int c );
1201 int set_native_charset( const char *newset );
1202 const char* get_native_charset(void);
1203 char *native_to_utf8( const char *string );
1204 char *utf8_to_native( const char *string, size_t length, int delim);
1205 char *string_to_utf8 (const char *string);
1206
1207 int ascii_isupper (int c);
1208 int ascii_islower (int c);
1209 int ascii_memcasecmp( const char *a, const char *b, size_t n);
1210
1211 #ifndef HAVE_STPCPY
1212 char *stpcpy(char *a,const char *b);
1213 #endif
1214 #ifndef HAVE_STRLWR
1215 char *strlwr(char *a);
1216 #endif
1217 #ifndef HAVE_STRCASECMP
1218 int strcasecmp( const char *, const char *b);
1219 #endif
1220 #ifndef HAVE_STRNCASECMP
1221 int strncasecmp (const char *, const char *b, size_t n);
1222 #endif
1223 #ifndef HAVE_STRTOUL
1224 #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
1225 #endif
1226 #ifndef HAVE_MEMMOVE
1227 #define memmove(d, s, n) bcopy((s), (d), (n))
1228 #endif
1229
1230 /*-- membuf.c --*/
1231 /* The definition of the structure is private, we only need it here,
1232 so it can be allocated on the stack. */
1233 struct private_membuf_s {
1234 size_t len;
1235 size_t size;
1236 char *buf;
1237 int out_of_core;
1238 };
1239
1240 typedef struct private_membuf_s membuf_t;
1241
1242 void init_membuf (membuf_t *mb, int initiallen);
1243 void put_membuf (membuf_t *mb, const void *buf, size_t len);
1244 void *get_membuf (membuf_t *mb, size_t *len);
1245
1246
1247
1248 #if defined (_WIN32)
1249 /*-- w32reg.c --*/
1250 char *read_w32_registry_string( const char *root,
1251 const char *dir, const char *name );
1252 int write_w32_registry_string(const char *root, const char *dir,
1253 const char *name, const char *value);
1254
1255 #endif /*_WIN32*/
1256
1257 /*-- strgutil.c --*/
1258 char *xasprintf (const char *fmt, ...);
1259 char *xtryasprintf (const char *fmt, ...);
1260
1261
1262 /*-- pka.c --*/
1263 char *get_pka_info (const char *address, unsigned char *fpr);
1264
1265 /*-- cert.c --*/
1266 int get_cert(const char *name,size_t max_size,IOBUF *iobuf,
1267 unsigned char **fpr,size_t *fpr_len,char **url);
1268
1269 /*-- convert.c --*/
1270 int hex2bin (const char *string, void *buffer, size_t length);
1271 int hexcolon2bin (const char *string, void *buffer, size_t length);
1272 char *bin2hex (const void *buffer, size_t length, char *stringbuf);
1273 char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf);
1274 const char *hex2str (const char *hexstring,
1275 char *buffer, size_t bufsize, size_t *buflen);
1276 char *hex2str_alloc (const char *hexstring, size_t *r_count);
1277
1278
1279 /**** other missing stuff ****/
1280 #ifndef HAVE_ATEXIT /* For SunOS */
(273 . 10)(57 . 6)
1282 #define raise(a) kill(getpid(), (a))
1283 #endif
1284
1285 /*-- Replacement functions from funcname.c --*/
1286
1287
1288
1289 /******** some macros ************/
1290 #ifndef STR
1291 #define STR(v) #v
(302 . 33)(82 . 5)
1293 *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
1294 #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
1295
1296 /******* RISC OS stuff ***********/
1297 #ifdef __riscos__
1298 int riscos_load_module(const char *name, const char * const path[], int fatal);
1299 int riscos_get_filetype_from_string(const char *string, int len);
1300 int riscos_get_filetype(const char *filename);
1301 void riscos_set_filetype_by_number(const char *filename, int type);
1302 void riscos_set_filetype_by_mimetype(const char *filename, const char *mimetype);
1303 pid_t riscos_getpid(void);
1304 int riscos_kill(pid_t pid, int sig);
1305 int riscos_access(const char *path, int amode);
1306 int riscos_getchar(void);
1307 char *riscos_make_basename(const char *filepath, const char *inputpath);
1308 int riscos_check_regexp(const char *exp, const char *string, int debug);
1309 int riscos_fdopenfile(const char *filename, const int allow_write);
1310 void riscos_close_fds(void);
1311 int riscos_renamefile(const char *old, const char *new);
1312 char *riscos_gstrans(const char *old);
1313 void riscos_not_implemented(const char *feature);
1314 #ifdef DEBUG
1315 void riscos_dump_fdlist(void);
1316 void riscos_list_openfiles(void);
1317 #endif
1318 #ifndef __RISCOS__C__
1319 #define getpid riscos_getpid
1320 #define kill(a,b) riscos_kill((a),(b))
1321 #define access(a,b) riscos_access((a),(b))
1322 #endif /* !__RISCOS__C__ */
1323 #endif /* __riscos__ */
1324
1325 #endif /*G10_UTIL_H*/
- C5DDDD9D52900BA3D847422F9DBA2799BE2954AD9CCA3B9AA6FB1654DD89EE00575C52D15BD65E98D3054D4646943372CA8AD591F610EA7761D21FE4C3AE6187
+
mpi/iobuf.c
(1 . 2326)(0 . 0)
1330 /* iobuf.c - file handling
1331 * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2008,
1332 * 2009 Free Software Foundation, Inc.
1333 *
1334 * This file is part of GnuPG.
1335 *
1336 * GnuPG is free software; you can redistribute it and/or modify
1337 * it under the terms of the GNU General Public License as published by
1338 * the Free Software Foundation; either version 3 of the License, or
1339 * (at your option) any later version.
1340 *
1341 * GnuPG is distributed in the hope that it will be useful,
1342 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1343 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1344 * GNU General Public License for more details.
1345 *
1346 * You should have received a copy of the GNU General Public License
1347 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1348 */
1349
1350 #include <config.h>
1351 #include <stdio.h>
1352 #include <stdlib.h>
1353 #include <string.h>
1354 #include <errno.h>
1355 #include <ctype.h>
1356 #include <assert.h>
1357 #include <sys/types.h>
1358 #include <sys/stat.h>
1359 #include <fcntl.h>
1360 #include <unistd.h>
1361 #ifdef HAVE_DOSISH_SYSTEM
1362 #include <windows.h>
1363 #endif
1364 #ifdef __riscos__
1365 #include <kernel.h>
1366 #include <swis.h>
1367 #endif /* __riscos__ */
1368
1369 #include "memory.h"
1370 #include "util.h"
1371 #include "iobuf.h"
1372
1373 /* The size of the internal buffers.
1374 NOTE: If you change this value you MUST also adjust the regression
1375 test "armored_key_8192" in armor.test! */
1376 #define IOBUF_BUFFER_SIZE 8192
1377
1378
1379 #undef FILE_FILTER_USES_STDIO
1380
1381 #ifdef HAVE_DOSISH_SYSTEM
1382 #define USE_SETMODE 1
1383 #endif
1384
1385 #ifdef FILE_FILTER_USES_STDIO
1386 #define my_fileno(a) fileno ((a))
1387 #define my_fopen_ro(a,b) fopen ((a),(b))
1388 #define my_fopen(a,b) fopen ((a),(b))
1389 typedef FILE *FILEP_OR_FD;
1390 #define INVALID_FP NULL
1391 #define FILEP_OR_FD_FOR_STDIN (stdin)
1392 #define FILEP_OR_FD_FOR_STDOUT (stdout)
1393 typedef struct {
1394 FILE *fp; /* open file handle */
1395 int keep_open;
1396 int no_cache;
1397 int print_only_name; /* flags indicating that fname is not a real file*/
1398 char fname[1]; /* name of the file */
1399 } file_filter_ctx_t ;
1400 #else
1401 #define my_fileno(a) (a)
1402 #define my_fopen_ro(a,b) fd_cache_open ((a),(b))
1403 #define my_fopen(a,b) direct_open ((a),(b))
1404 #ifdef HAVE_DOSISH_SYSTEM
1405 typedef HANDLE FILEP_OR_FD;
1406 #define INVALID_FP ((HANDLE)-1)
1407 #define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE))
1408 #define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE))
1409 #undef USE_SETMODE
1410 #else
1411 typedef int FILEP_OR_FD;
1412 #define INVALID_FP (-1)
1413 #define FILEP_OR_FD_FOR_STDIN (0)
1414 #define FILEP_OR_FD_FOR_STDOUT (1)
1415 #endif
1416 typedef struct {
1417 FILEP_OR_FD fp; /* open file handle */
1418 int keep_open;
1419 int no_cache;
1420 int eof_seen;
1421 int print_only_name; /* flags indicating that fname is not a real file*/
1422 char fname[1]; /* name of the file */
1423 } file_filter_ctx_t ;
1424
1425 struct close_cache_s {
1426 struct close_cache_s *next;
1427 FILEP_OR_FD fp;
1428 char fname[1];
1429 };
1430 typedef struct close_cache_s *CLOSE_CACHE;
1431 static CLOSE_CACHE close_cache;
1432 #endif
1433
1434 #ifdef _WIN32
1435 typedef struct {
1436 int sock;
1437 int keep_open;
1438 int no_cache;
1439 int eof_seen;
1440 int print_only_name; /* flags indicating that fname is not a real file*/
1441 char fname[1]; /* name of the file */
1442 } sock_filter_ctx_t ;
1443 #endif /*_WIN32*/
1444
1445 /* The first partial length header block must be of size 512
1446 * to make it easier (and efficienter) we use a min. block size of 512
1447 * for all chunks (but the last one) */
1448 #define OP_MIN_PARTIAL_CHUNK 512
1449 #define OP_MIN_PARTIAL_CHUNK_2POW 9
1450
1451 typedef struct {
1452 int use;
1453 size_t size;
1454 size_t count;
1455 int partial; /* 1 = partial header, 2 in last partial packet */
1456 char *buffer; /* used for partial header */
1457 size_t buflen; /* used size of buffer */
1458 int first_c; /* of partial header (which is > 0)*/
1459 int eof;
1460 } block_filter_ctx_t;
1461
1462 static int special_names_enabled;
1463
1464 static int underflow(IOBUF a);
1465 static int translate_file_handle ( int fd, int for_write );
1466
1467
1468
1469 #ifndef FILE_FILTER_USES_STDIO
1470
1471 /* This is a replacement for strcmp. Under W32 it does not
1472 distinguish between backslash and slash. */
1473 static int
1474 fd_cache_strcmp (const char *a, const char *b)
1475 {
1476 #ifdef HAVE_DOSISH_SYSTEM
1477 for (; *a && *b; a++, b++)
1478 {
1479 if (*a != *b && !((*a == '/' && *b == '\\')
1480 || (*a == '\\' && *b == '/')) )
1481 break;
1482 }
1483 return *(const unsigned char *)a - *(const unsigned char *)b;
1484 #else
1485 return strcmp (a, b);
1486 #endif
1487 }
1488
1489 /*
1490 * Invalidate (i.e. close) a cached iobuf or all iobufs if NULL is
1491 * used for FNAME.
1492 */
1493 static int
1494 fd_cache_invalidate (const char *fname)
1495 {
1496 CLOSE_CACHE cc;
1497 int err=0;
1498
1499 if (!fname) {
1500 if( DBG_IOBUF )
1501 log_debug ("fd_cache_invalidate (all)\n");
1502
1503 for (cc=close_cache; cc; cc = cc->next ) {
1504 if ( cc->fp != INVALID_FP ) {
1505 #ifdef HAVE_DOSISH_SYSTEM
1506 CloseHandle (cc->fp);
1507 #else
1508 close(cc->fp);
1509 #endif
1510 cc->fp = INVALID_FP;
1511 }
1512 }
1513 return err;
1514 }
1515
1516 if( DBG_IOBUF )
1517 log_debug ("fd_cache_invalidate (%s)\n", fname);
1518
1519 for (cc=close_cache; cc; cc = cc->next ) {
1520 if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) {
1521 if( DBG_IOBUF )
1522 log_debug (" did (%s)\n", cc->fname);
1523 #ifdef HAVE_DOSISH_SYSTEM
1524 if(CloseHandle (cc->fp)==0)
1525 err=-1;
1526 #else
1527 err=close(cc->fp);
1528 #endif
1529 cc->fp = INVALID_FP;
1530 }
1531 }
1532
1533 return err;
1534 }
1535
1536 static int
1537 fd_cache_synchronize(const char *fname)
1538 {
1539 int err=0;
1540
1541 #ifndef HAVE_DOSISH_SYSTEM
1542 CLOSE_CACHE cc;
1543
1544 if( DBG_IOBUF )
1545 log_debug ("fd_cache_synchronize (%s)\n", fname);
1546
1547 for (cc=close_cache; cc; cc = cc->next )
1548 {
1549 if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) )
1550 {
1551 if( DBG_IOBUF )
1552 log_debug (" did (%s)\n", cc->fname);
1553
1554 err=fsync(cc->fp);
1555 }
1556 }
1557 #endif
1558
1559 return err;
1560 }
1561
1562 static FILEP_OR_FD
1563 direct_open (const char *fname, const char *mode)
1564 {
1565 #ifdef HAVE_DOSISH_SYSTEM
1566 unsigned long da, cd, sm;
1567 HANDLE hfile;
1568
1569 /* Note, that we do not handle all mode combinations */
1570
1571 /* According to the ReactOS source it seems that open() of the
1572 * standard MSW32 crt does open the file in share mode which is
1573 * something new for MS applications ;-)
1574 */
1575 if ( strchr (mode, '+') ) {
1576 fd_cache_invalidate (fname);
1577 da = GENERIC_READ|GENERIC_WRITE;
1578 cd = OPEN_EXISTING;
1579 sm = FILE_SHARE_READ | FILE_SHARE_WRITE;
1580 }
1581 else if ( strchr (mode, 'w') ) {
1582 fd_cache_invalidate (fname);
1583 da = GENERIC_WRITE;
1584 cd = CREATE_ALWAYS;
1585 sm = FILE_SHARE_WRITE;
1586 }
1587 else {
1588 da = GENERIC_READ;
1589 cd = OPEN_EXISTING;
1590 sm = FILE_SHARE_READ;
1591 }
1592
1593 hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
1594 return hfile;
1595 #else
1596 int oflag;
1597 int cflag = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
1598
1599 /* Note, that we do not handle all mode combinations */
1600 if ( strchr (mode, '+') ) {
1601 fd_cache_invalidate (fname);
1602 oflag = O_RDWR;
1603 }
1604 else if ( strchr (mode, 'w') ) {
1605 fd_cache_invalidate (fname);
1606 oflag = O_WRONLY | O_CREAT | O_TRUNC;
1607 }
1608 else {
1609 oflag = O_RDONLY;
1610 }
1611 #ifdef O_BINARY
1612 if (strchr (mode, 'b'))
1613 oflag |= O_BINARY;
1614 #endif
1615 #ifndef __riscos__
1616 return open (fname, oflag, cflag );
1617 #else
1618 {
1619 struct stat buf;
1620 int rc = stat( fname, &buf );
1621
1622 /* Don't allow iobufs on directories */
1623 if( !rc && S_ISDIR(buf.st_mode) && !S_ISREG(buf.st_mode) )
1624 return __set_errno( EISDIR );
1625 else
1626 return open( fname, oflag, cflag );
1627 }
1628 #endif
1629 #endif
1630 }
1631
1632
1633 /*
1634 * Instead of closing an FD we keep it open and cache it for later reuse
1635 * Note that this caching strategy only works if the process does not chdir.
1636 */
1637 static void
1638 fd_cache_close (const char *fname, FILEP_OR_FD fp)
1639 {
1640 CLOSE_CACHE cc;
1641
1642 assert (fp);
1643 if ( !fname || !*fname ) {
1644 #ifdef HAVE_DOSISH_SYSTEM
1645 CloseHandle (fp);
1646 #else
1647 close(fp);
1648 #endif
1649 if( DBG_IOBUF )
1650 log_debug ("fd_cache_close (%d) real\n", (int)fp);
1651 return;
1652 }
1653 /* try to reuse a slot */
1654 for (cc=close_cache; cc; cc = cc->next ) {
1655 if ( cc->fp == INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) {
1656 cc->fp = fp;
1657 if( DBG_IOBUF )
1658 log_debug ("fd_cache_close (%s) used existing slot\n", fname);
1659 return;
1660 }
1661 }
1662 /* add a new one */
1663 if( DBG_IOBUF )
1664 log_debug ("fd_cache_close (%s) new slot created\n", fname);
1665 cc = xmalloc_clear (sizeof *cc + strlen (fname));
1666 strcpy (cc->fname, fname);
1667 cc->fp = fp;
1668 cc->next = close_cache;
1669 close_cache = cc;
1670 }
1671
1672 /*
1673 * Do an direct_open on FNAME but first try to reuse one from the fd_cache
1674 */
1675 static FILEP_OR_FD
1676 fd_cache_open (const char *fname, const char *mode)
1677 {
1678 CLOSE_CACHE cc;
1679
1680 assert (fname);
1681 for (cc=close_cache; cc; cc = cc->next ) {
1682 if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) {
1683 FILEP_OR_FD fp = cc->fp;
1684 cc->fp = INVALID_FP;
1685 if( DBG_IOBUF )
1686 log_debug ("fd_cache_open (%s) using cached fp\n", fname);
1687 #ifdef HAVE_DOSISH_SYSTEM
1688 if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) {
1689 log_error ("rewind file failed on handle %p: %s\n",
1690 fp, w32_strerror (errno));
1691 fp = INVALID_FP;
1692 }
1693 #else
1694 if ( lseek (fp, 0, SEEK_SET) == (off_t)-1 ) {
1695 log_error("can't rewind fd %d: %s\n", fp, strerror(errno) );
1696 fp = INVALID_FP;
1697 }
1698 #endif
1699 return fp;
1700 }
1701 }
1702 if( DBG_IOBUF )
1703 log_debug ("fd_cache_open (%s) not cached\n", fname);
1704 return direct_open (fname, mode);
1705 }
1706
1707
1708 #endif /*FILE_FILTER_USES_STDIO*/
1709
1710
1711 /****************
1712 * Read data from a file into buf which has an allocated length of *LEN.
1713 * return the number of read bytes in *LEN. OPAQUE is the FILE * of
1714 * the stream. A is not used.
1715 * control may be:
1716 * IOBUFCTRL_INIT: called just before the function is linked into the
1717 * list of function. This can be used to prepare internal
1718 * data structures of the function.
1719 * IOBUFCTRL_FREE: called just before the function is removed from the
1720 * list of functions and can be used to release internal
1721 * data structures or close a file etc.
1722 * IOBUFCTRL_UNDERFLOW: called by iobuf_underflow to fill the buffer
1723 * with new stuff. *RET_LEN is the available size of the
1724 * buffer, and should be set to the number of bytes
1725 * which were put into the buffer. The function
1726 * returns 0 to indicate success, -1 on EOF and
1727 * G10ERR_xxxxx for other errors.
1728 *
1729 * IOBUFCTRL_FLUSH: called by iobuf_flush() to write out the collected stuff.
1730 * *RET_LAN is the number of bytes in BUF.
1731 *
1732 * IOBUFCTRL_CANCEL: send to all filters on behalf of iobuf_cancel. The
1733 * filter may take appropriate action on this message.
1734 */
1735 static int
1736 file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
1737 {
1738 file_filter_ctx_t *a = opaque;
1739 FILEP_OR_FD f = a->fp;
1740 size_t size = *ret_len;
1741 size_t nbytes = 0;
1742 int rc = 0;
1743
1744 #ifdef FILE_FILTER_USES_STDIO
1745 if( control == IOBUFCTRL_UNDERFLOW ) {
1746 assert( size ); /* need a buffer */
1747 if ( feof(f)) { /* On terminals you could easiely read as many EOFs as you call */
1748 rc = -1; /* fread() or fgetc() repeatly. Every call will block until you press */
1749 *ret_len = 0; /* CTRL-D. So we catch this case before we call fread() again. */
1750 }
1751 else {
1752 clearerr( f );
1753 nbytes = fread( buf, 1, size, f );
1754 if( feof(f) && !nbytes ) {
1755 rc = -1; /* okay: we can return EOF now. */
1756 }
1757 else if( ferror(f) && errno != EPIPE ) {
1758 log_error("%s: read error: %s\n",
1759 a->fname, strerror(errno));
1760 rc = G10ERR_READ_FILE;
1761 }
1762 *ret_len = nbytes;
1763 }
1764 }
1765 else if( control == IOBUFCTRL_FLUSH ) {
1766 if( size ) {
1767 clearerr( f );
1768 nbytes = fwrite( buf, 1, size, f );
1769 if( ferror(f) ) {
1770 log_error("%s: write error: %s\n", a->fname, strerror(errno));
1771 rc = G10ERR_WRITE_FILE;
1772 }
1773 }
1774 *ret_len = nbytes;
1775 }
1776 else if( control == IOBUFCTRL_INIT ) {
1777 a->keep_open = a->no_cache = 0;
1778 }
1779 else if( control == IOBUFCTRL_DESC ) {
1780 *(char**)buf = "file_filter";
1781 }
1782 else if( control == IOBUFCTRL_FREE ) {
1783 if( f != stdin && f != stdout ) {
1784 if( DBG_IOBUF )
1785 log_debug("%s: close fd %d\n", a->fname, fileno(f) );
1786 if (!a->keep_open)
1787 fclose(f);
1788 }
1789 f = NULL;
1790 xfree(a); /* we can free our context now */
1791 }
1792 #else /* !stdio implementation */
1793
1794 if( control == IOBUFCTRL_UNDERFLOW ) {
1795 assert( size ); /* need a buffer */
1796 if ( a->eof_seen) {
1797 rc = -1;
1798 *ret_len = 0;
1799 }
1800 else {
1801 #ifdef HAVE_DOSISH_SYSTEM
1802 unsigned long nread;
1803
1804 nbytes = 0;
1805 if ( !ReadFile ( f, buf, size, &nread, NULL ) ) {
1806 if ((int)GetLastError () != ERROR_BROKEN_PIPE) {
1807 log_error ("%s: read error: %s\n", a->fname,
1808 w32_strerror (0));
1809 rc = G10ERR_READ_FILE;
1810 }
1811 }
1812 else if ( !nread ) {
1813 a->eof_seen = 1;
1814 rc = -1;
1815 }
1816 else {
1817 nbytes = nread;
1818 }
1819
1820 #else
1821
1822 int n;
1823
1824 nbytes = 0;
1825 do {
1826 n = read ( f, buf, size );
1827 } while (n == -1 && errno == EINTR );
1828 if ( n == -1 ) { /* error */
1829 if (errno != EPIPE) {
1830 log_error("%s: read error: %s\n",
1831 a->fname, strerror(errno));
1832 rc = G10ERR_READ_FILE;
1833 }
1834 }
1835 else if ( !n ) { /* eof */
1836 a->eof_seen = 1;
1837 rc = -1;
1838 }
1839 else {
1840 nbytes = n;
1841 }
1842 #endif
1843 *ret_len = nbytes;
1844 }
1845 }
1846 else if( control == IOBUFCTRL_FLUSH ) {
1847 if( size ) {
1848 #ifdef HAVE_DOSISH_SYSTEM
1849 byte *p = buf;
1850 unsigned long n;
1851
1852 nbytes = size;
1853 do {
1854 if (size && !WriteFile (f, p, nbytes, &n, NULL)) {
1855 log_error ("%s: write error: %s\n", a->fname,
1856 w32_strerror (0));
1857 rc = G10ERR_WRITE_FILE;
1858 break;
1859 }
1860 p += n;
1861 nbytes -= n;
1862 } while ( nbytes );
1863 nbytes = p - buf;
1864 #else
1865 byte *p = buf;
1866 int n;
1867
1868 nbytes = size;
1869 do {
1870 do {
1871 n = write ( f, p, nbytes );
1872 } while ( n == -1 && errno == EINTR );
1873 if ( n > 0 ) {
1874 p += n;
1875 nbytes -= n;
1876 }
1877 } while ( n != -1 && nbytes );
1878 if( n == -1 ) {
1879 log_error("%s: write error: %s\n", a->fname, strerror(errno));
1880 rc = G10ERR_WRITE_FILE;
1881 }
1882 nbytes = p - buf;
1883 #endif
1884 }
1885 *ret_len = nbytes;
1886 }
1887 else if ( control == IOBUFCTRL_INIT ) {
1888 a->eof_seen = 0;
1889 a->keep_open = 0;
1890 a->no_cache = 0;
1891 }
1892 else if ( control == IOBUFCTRL_DESC ) {
1893 *(char**)buf = "file_filter(fd)";
1894 }
1895 else if ( control == IOBUFCTRL_FREE ) {
1896 #ifdef HAVE_DOSISH_SYSTEM
1897 if ( f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT ) {
1898 if( DBG_IOBUF )
1899 log_debug("%s: close handle %p\n", a->fname, f );
1900 if (!a->keep_open)
1901 fd_cache_close (a->no_cache?NULL:a->fname, f);
1902 }
1903 #else
1904 if ( (int)f != 0 && (int)f != 1 ) {
1905 if( DBG_IOBUF )
1906 log_debug("%s: close fd %d\n", a->fname, f );
1907 if (!a->keep_open)
1908 fd_cache_close (a->no_cache?NULL:a->fname, f);
1909 }
1910 f = INVALID_FP;
1911 #endif
1912 xfree (a); /* we can free our context now */
1913 }
1914 #endif /* !stdio implementation */
1915 return rc;
1916 }
1917
1918 #ifdef _WIN32
1919 /* Becuase sockets are an special object under Lose32 we have to
1920 * use a special filter */
1921 static int
1922 sock_filter (void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
1923 {
1924 sock_filter_ctx_t *a = opaque;
1925 size_t size = *ret_len;
1926 size_t nbytes = 0;
1927 int rc = 0;
1928
1929 if( control == IOBUFCTRL_UNDERFLOW ) {
1930 assert( size ); /* need a buffer */
1931 if ( a->eof_seen) {
1932 rc = -1;
1933 *ret_len = 0;
1934 }
1935 else {
1936 int nread;
1937
1938 nread = recv ( a->sock, buf, size, 0 );
1939 if ( nread == SOCKET_ERROR ) {
1940 int ec = (int)WSAGetLastError ();
1941 log_error("socket read error: ec=%d\n", ec);
1942 rc = G10ERR_READ_FILE;
1943 }
1944 else if ( !nread ) {
1945 a->eof_seen = 1;
1946 rc = -1;
1947 }
1948 else {
1949 nbytes = nread;
1950 }
1951 *ret_len = nbytes;
1952 }
1953 }
1954 else if( control == IOBUFCTRL_FLUSH ) {
1955 if( size ) {
1956 byte *p = buf;
1957 int n;
1958
1959 nbytes = size;
1960 do {
1961 n = send (a->sock, p, nbytes, 0);
1962 if ( n == SOCKET_ERROR ) {
1963 int ec = (int)WSAGetLastError ();
1964 log_error("socket write error: ec=%d\n", ec);
1965 rc = G10ERR_WRITE_FILE;
1966 break;
1967 }
1968 p += n;
1969 nbytes -= n;
1970 } while ( nbytes );
1971 nbytes = p - buf;
1972 }
1973 *ret_len = nbytes;
1974 }
1975 else if ( control == IOBUFCTRL_INIT ) {
1976 a->eof_seen = 0;
1977 a->keep_open = 0;
1978 a->no_cache = 0;
1979 }
1980 else if ( control == IOBUFCTRL_DESC ) {
1981 *(char**)buf = "sock_filter";
1982 }
1983 else if ( control == IOBUFCTRL_FREE ) {
1984 if (!a->keep_open)
1985 closesocket (a->sock);
1986 xfree (a); /* we can free our context now */
1987 }
1988 return rc;
1989 }
1990 #endif /*_WIN32*/
1991
1992 /****************
1993 * This is used to implement the block write mode.
1994 * Block reading is done on a byte by byte basis in readbyte(),
1995 * without a filter
1996 */
1997 static int
1998 block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
1999 {
2000 block_filter_ctx_t *a = opaque;
2001 size_t size = *ret_len;
2002 int c, needed, rc = 0;
2003 char *p;
2004
2005 if( control == IOBUFCTRL_UNDERFLOW ) {
2006 size_t n=0;
2007
2008 p = buf;
2009 assert( size ); /* need a buffer */
2010 if( a->eof ) /* don't read any further */
2011 rc = -1;
2012 while( !rc && size ) {
2013 if( !a->size ) { /* get the length bytes */
2014 if( a->partial == 2 ) {
2015 a->eof = 1;
2016 if( !n )
2017 rc = -1;
2018 break;
2019 }
2020 else if( a->partial ) {
2021 /* These OpenPGP introduced huffman like encoded length
2022 * bytes are really a mess :-( */
2023 if( a->first_c ) {
2024 c = a->first_c;
2025 a->first_c = 0;
2026 }
2027 else if( (c = iobuf_get(chain)) == -1 ) {
2028 log_error("block_filter: 1st length byte missing\n");
2029 rc = G10ERR_READ_FILE;
2030 break;
2031 }
2032 if( c < 192 ) {
2033 a->size = c;
2034 a->partial = 2;
2035 if( !a->size ) {
2036 a->eof = 1;
2037 if( !n )
2038 rc = -1;
2039 break;
2040 }
2041 }
2042 else if( c < 224 ) {
2043 a->size = (c - 192) * 256;
2044 if( (c = iobuf_get(chain)) == -1 ) {
2045 log_error("block_filter: 2nd length byte missing\n");
2046 rc = G10ERR_READ_FILE;
2047 break;
2048 }
2049 a->size += c + 192;
2050 a->partial = 2;
2051 if( !a->size ) {
2052 a->eof = 1;
2053 if( !n )
2054 rc = -1;
2055 break;
2056 }
2057 }
2058 else if( c == 255 ) {
2059 a->size = iobuf_get(chain) << 24;
2060 a->size |= iobuf_get(chain) << 16;
2061 a->size |= iobuf_get(chain) << 8;
2062 if( (c = iobuf_get(chain)) == -1 ) {
2063 log_error("block_filter: invalid 4 byte length\n");
2064 rc = G10ERR_READ_FILE;
2065 break;
2066 }
2067 a->size |= c;
2068 a->partial = 2;
2069 if( !a->size ) {
2070 a->eof = 1;
2071 if( !n )
2072 rc = -1;
2073 break;
2074 }
2075 }
2076 else { /* next partial body length */
2077 a->size = 1 << (c & 0x1f);
2078 }
2079 /* log_debug("partial: ctx=%p c=%02x size=%u\n", a, c, a->size);*/
2080 }
2081 else
2082 BUG();
2083 }
2084
2085 while( !rc && size && a->size ) {
2086 needed = size < a->size ? size : a->size;
2087 c = iobuf_read( chain, p, needed );
2088 if( c < needed ) {
2089 if( c == -1 ) c = 0;
2090 log_error("block_filter %p: read error (size=%lu,a->size=%lu)\n",
2091 a, (ulong)size+c, (ulong)a->size+c);
2092 rc = G10ERR_READ_FILE;
2093 }
2094 else {
2095 size -= c;
2096 a->size -= c;
2097 p += c;
2098 n += c;
2099 }
2100 }
2101 }
2102 *ret_len = n;
2103 }
2104 else if( control == IOBUFCTRL_FLUSH ) {
2105 if( a->partial ) { /* the complicated openpgp scheme */
2106 size_t blen, n, nbytes = size + a->buflen;
2107
2108 assert( a->buflen <= OP_MIN_PARTIAL_CHUNK );
2109 if( nbytes < OP_MIN_PARTIAL_CHUNK ) {
2110 /* not enough to write a partial block out; so we store it*/
2111 if( !a->buffer )
2112 a->buffer = xmalloc( OP_MIN_PARTIAL_CHUNK );
2113 memcpy( a->buffer + a->buflen, buf, size );
2114 a->buflen += size;
2115 }
2116 else { /* okay, we can write out something */
2117 /* do this in a loop to use the most efficient block lengths */
2118 p = buf;
2119 do {
2120 /* find the best matching block length - this is limited
2121 * by the size of the internal buffering */
2122 for( blen=OP_MIN_PARTIAL_CHUNK*2,
2123 c=OP_MIN_PARTIAL_CHUNK_2POW+1; blen <= nbytes;
2124 blen *=2, c++ )
2125 ;
2126 blen /= 2; c--;
2127 /* write the partial length header */
2128 assert( c <= 0x1f ); /*;-)*/
2129 c |= 0xe0;
2130 iobuf_put( chain, c );
2131 if( (n=a->buflen) ) { /* write stuff from the buffer */
2132 assert( n == OP_MIN_PARTIAL_CHUNK);
2133 if( iobuf_write(chain, a->buffer, n ) )
2134 rc = G10ERR_WRITE_FILE;
2135 a->buflen = 0;
2136 nbytes -= n;
2137 }
2138 if( (n = nbytes) > blen )
2139 n = blen;
2140 if( n && iobuf_write(chain, p, n ) )
2141 rc = G10ERR_WRITE_FILE;
2142 p += n;
2143 nbytes -= n;
2144 } while( !rc && nbytes >= OP_MIN_PARTIAL_CHUNK );
2145 /* store the rest in the buffer */
2146 if( !rc && nbytes ) {
2147 assert( !a->buflen );
2148 assert( nbytes < OP_MIN_PARTIAL_CHUNK );
2149 if( !a->buffer )
2150 a->buffer = xmalloc( OP_MIN_PARTIAL_CHUNK );
2151 memcpy( a->buffer, p, nbytes );
2152 a->buflen = nbytes;
2153 }
2154 }
2155 }
2156 else
2157 BUG();
2158 }
2159 else if( control == IOBUFCTRL_INIT ) {
2160 if( DBG_IOBUF )
2161 log_debug("init block_filter %p\n", a );
2162 if( a->partial )
2163 a->count = 0;
2164 else if( a->use == 1 )
2165 a->count = a->size = 0;
2166 else
2167 a->count = a->size; /* force first length bytes */
2168 a->eof = 0;
2169 a->buffer = NULL;
2170 a->buflen = 0;
2171 }
2172 else if( control == IOBUFCTRL_DESC ) {
2173 *(char**)buf = "block_filter";
2174 }
2175 else if( control == IOBUFCTRL_FREE ) {
2176 if( a->use == 2 ) { /* write the end markers */
2177 if( a->partial ) {
2178 u32 len;
2179 /* write out the remaining bytes without a partial header
2180 * the length of this header may be 0 - but if it is
2181 * the first block we are not allowed to use a partial header
2182 * and frankly we can't do so, because this length must be
2183 * a power of 2. This is _really_ complicated because we
2184 * have to check the possible length of a packet prior
2185 * to it's creation: a chain of filters becomes complicated
2186 * and we need a lot of code to handle compressed packets etc.
2187 * :-(((((((
2188 */
2189 /* construct header */
2190 len = a->buflen;
2191 /*log_debug("partial: remaining length=%u\n", len );*/
2192 if( len < 192 )
2193 rc = iobuf_put(chain, len );
2194 else if( len < 8384 ) {
2195 if( !(rc=iobuf_put( chain, ((len-192) / 256) + 192)) )
2196 rc = iobuf_put( chain, ((len-192) % 256));
2197 }
2198 else { /* use a 4 byte header */
2199 if( !(rc=iobuf_put( chain, 0xff )) )
2200 if( !(rc=iobuf_put( chain, (len >> 24)&0xff )) )
2201 if( !(rc=iobuf_put( chain, (len >> 16)&0xff )) )
2202 if( !(rc=iobuf_put( chain, (len >> 8)&0xff )))
2203 rc=iobuf_put( chain, len & 0xff );
2204 }
2205 if( !rc && len )
2206 rc = iobuf_write(chain, a->buffer, len );
2207 if( rc ) {
2208 log_error("block_filter: write error: %s\n",strerror(errno));
2209 rc = G10ERR_WRITE_FILE;
2210 }
2211 xfree( a->buffer ); a->buffer = NULL; a->buflen = 0;
2212 }
2213 else
2214 BUG();
2215 }
2216 else if( a->size ) {
2217 log_error("block_filter: pending bytes!\n");
2218 }
2219 if( DBG_IOBUF )
2220 log_debug("free block_filter %p\n", a );
2221 xfree(a); /* we can free our context now */
2222 }
2223
2224 return rc;
2225 }
2226
2227
2228 static void
2229 print_chain( IOBUF a )
2230 {
2231 if( !DBG_IOBUF )
2232 return;
2233 for(; a; a = a->chain ) {
2234 size_t dummy_len = 0;
2235 const char *desc = "[none]";
2236
2237 if( a->filter )
2238 a->filter( a->filter_ov, IOBUFCTRL_DESC, NULL,
2239 (byte*)&desc, &dummy_len );
2240
2241 log_debug("iobuf chain: %d.%d `%s' filter_eof=%d start=%d len=%d\n",
2242 a->no, a->subno, desc?desc:"?", a->filter_eof,
2243 (int)a->d.start, (int)a->d.len );
2244 }
2245 }
2246
2247 int
2248 iobuf_print_chain( IOBUF a )
2249 {
2250 print_chain(a);
2251 return 0;
2252 }
2253
2254 /****************
2255 * Allocate a new io buffer, with no function assigned.
2256 * Use is the desired usage: 1 for input, 2 for output, 3 for temp buffer
2257 * BUFSIZE is a suggested buffer size.
2258 */
2259 IOBUF
2260 iobuf_alloc(int use, size_t bufsize)
2261 {
2262 IOBUF a;
2263 static int number=0;
2264
2265 a = xmalloc_clear(sizeof *a);
2266 a->use = use;
2267 a->d.buf = xmalloc( bufsize );
2268 a->d.size = bufsize;
2269 a->no = ++number;
2270 a->subno = 0;
2271 a->opaque = NULL;
2272 a->real_fname = NULL;
2273 return a;
2274 }
2275
2276 int
2277 iobuf_close ( IOBUF a )
2278 {
2279 IOBUF a2;
2280 size_t dummy_len=0;
2281 int rc=0;
2282
2283 if( a && a->directfp ) {
2284 fclose( a->directfp );
2285 xfree( a->real_fname );
2286 if( DBG_IOBUF )
2287 log_debug("iobuf_close -> %p\n", a->directfp );
2288 return 0;
2289 }
2290
2291 for( ; a && !rc ; a = a2 ) {
2292 a2 = a->chain;
2293 if( a->use == 2 && (rc=iobuf_flush(a)) )
2294 log_error("iobuf_flush failed on close: %s\n", g10_errstr(rc));
2295
2296 if( DBG_IOBUF )
2297 log_debug("iobuf-%d.%d: close `%s'\n", a->no, a->subno,
2298 a->desc?a->desc:"?");
2299 if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE,
2300 a->chain, NULL, &dummy_len)) )
2301 log_error("IOBUFCTRL_FREE failed on close: %s\n", g10_errstr(rc) );
2302 xfree(a->real_fname);
2303 if (a->d.buf) {
2304 memset (a->d.buf, 0, a->d.size); /* erase the buffer */
2305 xfree(a->d.buf);
2306 }
2307 xfree(a);
2308 }
2309 return rc;
2310 }
2311
2312 int
2313 iobuf_cancel( IOBUF a )
2314 {
2315 const char *s;
2316 IOBUF a2;
2317 int rc;
2318 #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
2319 char *remove_name = NULL;
2320 #endif
2321
2322 if( a && a->use == 2 ) {
2323 s = iobuf_get_real_fname(a);
2324 if( s && *s ) {
2325 #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
2326 remove_name = xstrdup ( s );
2327 #else
2328 remove(s);
2329 #endif
2330 }
2331 }
2332
2333 /* send a cancel message to all filters */
2334 for( a2 = a; a2 ; a2 = a2->chain ) {
2335 size_t dummy;
2336 if( a2->filter )
2337 a2->filter( a2->filter_ov, IOBUFCTRL_CANCEL, a2->chain,
2338 NULL, &dummy );
2339 }
2340
2341 rc = iobuf_close(a);
2342 #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
2343 if ( remove_name ) {
2344 /* Argg, MSDOS does not allow to remove open files. So
2345 * we have to do it here */
2346 remove ( remove_name );
2347 xfree ( remove_name );
2348 }
2349 #endif
2350 return rc;
2351 }
2352
2353
2354 /****************
2355 * create a temporary iobuf, which can be used to collect stuff
2356 * in an iobuf and later be written by iobuf_write_temp() to another
2357 * iobuf.
2358 */
2359 IOBUF
2360 iobuf_temp()
2361 {
2362 IOBUF a;
2363
2364 a = iobuf_alloc(3, IOBUF_BUFFER_SIZE );
2365
2366 return a;
2367 }
2368
2369 IOBUF
2370 iobuf_temp_with_content( const char *buffer, size_t length )
2371 {
2372 IOBUF a;
2373
2374 a = iobuf_alloc(3, length );
2375 memcpy( a->d.buf, buffer, length );
2376 a->d.len = length;
2377
2378 return a;
2379 }
2380
2381 void
2382 iobuf_enable_special_filenames ( int yes )
2383 {
2384 special_names_enabled = yes;
2385 }
2386
2387 /*
2388 * see whether the filename has the for "-&nnnn", where n is a
2389 * non-zero number.
2390 * Returns this number or -1 if it is not the case.
2391 */
2392 static int
2393 check_special_filename ( const char *fname )
2394 {
2395 if ( special_names_enabled
2396 && fname && *fname == '-' && fname[1] == '&' ) {
2397 int i;
2398
2399 fname += 2;
2400 for (i=0; digitp (fname+i); i++ )
2401 ;
2402 if ( !fname[i] )
2403 return atoi (fname);
2404 }
2405 return -1;
2406 }
2407
2408 /* This fucntion returns true if FNAME indicates a PIPE (stdout or
2409 stderr) or a special file name if those are enabled. */
2410 int
2411 iobuf_is_pipe_filename (const char *fname)
2412 {
2413 if (!fname || (*fname=='-' && !fname[1]) )
2414 return 1;
2415 return check_special_filename (fname) != -1;
2416 }
2417
2418 /****************
2419 * Create a head iobuf for reading from a file
2420 * returns: NULL if an error occures and sets errno
2421 */
2422 IOBUF
2423 iobuf_open( const char *fname )
2424 {
2425 IOBUF a;
2426 FILEP_OR_FD fp;
2427 file_filter_ctx_t *fcx;
2428 size_t len;
2429 int print_only = 0;
2430 int fd;
2431
2432 if( !fname || (*fname=='-' && !fname[1]) ) {
2433 fp = FILEP_OR_FD_FOR_STDIN;
2434 #ifdef USE_SETMODE
2435 setmode ( my_fileno(fp) , O_BINARY );
2436 #endif
2437 fname = "[stdin]";
2438 print_only = 1;
2439 }
2440 else if ( (fd = check_special_filename ( fname )) != -1 )
2441 return iobuf_fdopen ( translate_file_handle (fd,0), "rb" );
2442 else if( (fp = my_fopen_ro(fname, "rb")) == INVALID_FP )
2443 return NULL;
2444 a = iobuf_alloc(1, IOBUF_BUFFER_SIZE );
2445 fcx = xmalloc( sizeof *fcx + strlen(fname) );
2446 fcx->fp = fp;
2447 fcx->print_only_name = print_only;
2448 strcpy(fcx->fname, fname );
2449 if( !print_only )
2450 a->real_fname = xstrdup( fname );
2451 a->filter = file_filter;
2452 a->filter_ov = fcx;
2453 file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2454 file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
2455 if( DBG_IOBUF )
2456 log_debug("iobuf-%d.%d: open `%s' fd=%d\n",
2457 a->no, a->subno, fname, (int)my_fileno(fcx->fp) );
2458
2459 return a;
2460 }
2461
2462 /****************
2463 * Create a head iobuf for reading from a file
2464 * returns: NULL if an error occures and sets errno
2465 */
2466 IOBUF
2467 iobuf_fdopen( int fd, const char *mode )
2468 {
2469 IOBUF a;
2470 FILEP_OR_FD fp;
2471 file_filter_ctx_t *fcx;
2472 size_t len;
2473
2474 #ifdef FILE_FILTER_USES_STDIO
2475 if( !(fp = fdopen(fd, mode)) )
2476 return NULL;
2477 #else
2478 fp = (FILEP_OR_FD)fd;
2479 #endif
2480 a = iobuf_alloc( strchr( mode, 'w')? 2:1, IOBUF_BUFFER_SIZE );
2481 fcx = xmalloc( sizeof *fcx + 20 );
2482 fcx->fp = fp;
2483 fcx->print_only_name = 1;
2484 sprintf(fcx->fname, "[fd %d]", fd );
2485 a->filter = file_filter;
2486 a->filter_ov = fcx;
2487 file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2488 file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
2489 if( DBG_IOBUF )
2490 log_debug("iobuf-%d.%d: fdopen `%s'\n", a->no, a->subno, fcx->fname );
2491 iobuf_ioctl (a,3,1,NULL); /* disable fd caching */
2492 return a;
2493 }
2494
2495
2496 IOBUF
2497 iobuf_sockopen ( int fd, const char *mode )
2498 {
2499 IOBUF a;
2500 #ifdef _WIN32
2501 sock_filter_ctx_t *scx;
2502 size_t len;
2503
2504 a = iobuf_alloc( strchr( mode, 'w')? 2:1, IOBUF_BUFFER_SIZE );
2505 scx = xmalloc( sizeof *scx + 25 );
2506 scx->sock = fd;
2507 scx->print_only_name = 1;
2508 sprintf(scx->fname, "[sock %d]", fd );
2509 a->filter = sock_filter;
2510 a->filter_ov = scx;
2511 sock_filter( scx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2512 sock_filter( scx, IOBUFCTRL_INIT, NULL, NULL, &len );
2513 if( DBG_IOBUF )
2514 log_debug("iobuf-%d.%d: sockopen `%s'\n", a->no, a->subno, scx->fname);
2515 iobuf_ioctl (a,3,1,NULL); /* disable fd caching */
2516 #else
2517 a = iobuf_fdopen (fd, mode);
2518 #endif
2519 return a;
2520 }
2521
2522 /****************
2523 * create an iobuf for writing to a file; the file will be created.
2524 */
2525 IOBUF
2526 iobuf_create( const char *fname )
2527 {
2528 IOBUF a;
2529 FILEP_OR_FD fp;
2530 file_filter_ctx_t *fcx;
2531 size_t len;
2532 int print_only = 0;
2533 int fd;
2534
2535 if( !fname || (*fname=='-' && !fname[1]) ) {
2536 fp = FILEP_OR_FD_FOR_STDOUT;
2537 #ifdef USE_SETMODE
2538 setmode ( my_fileno(fp) , O_BINARY );
2539 #endif
2540 fname = "[stdout]";
2541 print_only = 1;
2542 }
2543 else if ( (fd = check_special_filename ( fname )) != -1 )
2544 return iobuf_fdopen ( translate_file_handle (fd, 1), "wb" );
2545 else if( (fp = my_fopen(fname, "wb")) == INVALID_FP )
2546 return NULL;
2547 a = iobuf_alloc(2, IOBUF_BUFFER_SIZE );
2548 fcx = xmalloc( sizeof *fcx + strlen(fname) );
2549 fcx->fp = fp;
2550 fcx->print_only_name = print_only;
2551 strcpy(fcx->fname, fname );
2552 if( !print_only )
2553 a->real_fname = xstrdup( fname );
2554 a->filter = file_filter;
2555 a->filter_ov = fcx;
2556 file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2557 file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
2558 if( DBG_IOBUF )
2559 log_debug("iobuf-%d.%d: create `%s'\n", a->no, a->subno,
2560 a->desc?a->desc:"?" );
2561
2562 return a;
2563 }
2564
2565 /****************
2566 * append to an iobuf; if the file does not exist, create it.
2567 * cannot be used for stdout.
2568 * Note: This is not used.
2569 */
2570 #if 0 /* not used */
2571 IOBUF
2572 iobuf_append( const char *fname )
2573 {
2574 IOBUF a;
2575 FILE *fp;
2576 file_filter_ctx_t *fcx;
2577 size_t len;
2578
2579 if( !fname )
2580 return NULL;
2581 else if( !(fp = my_fopen(fname, "ab")) )
2582 return NULL;
2583 a = iobuf_alloc(2, IOBUF_BUFFER_SIZE );
2584 fcx = xmalloc( sizeof *fcx + strlen(fname) );
2585 fcx->fp = fp;
2586 strcpy(fcx->fname, fname );
2587 a->real_fname = xstrdup( fname );
2588 a->filter = file_filter;
2589 a->filter_ov = fcx;
2590 file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2591 file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
2592 if( DBG_IOBUF )
2593 log_debug("iobuf-%d.%d: append `%s'\n", a->no, a->subno,
2594 a->desc?a->desc:"?" );
2595
2596 return a;
2597 }
2598 #endif
2599
2600 IOBUF
2601 iobuf_openrw( const char *fname )
2602 {
2603 IOBUF a;
2604 FILEP_OR_FD fp;
2605 file_filter_ctx_t *fcx;
2606 size_t len;
2607
2608 if( !fname )
2609 return NULL;
2610 else if( (fp = my_fopen(fname, "r+b")) == INVALID_FP )
2611 return NULL;
2612 a = iobuf_alloc(2, IOBUF_BUFFER_SIZE );
2613 fcx = xmalloc( sizeof *fcx + strlen(fname) );
2614 fcx->fp = fp;
2615 strcpy(fcx->fname, fname );
2616 a->real_fname = xstrdup( fname );
2617 a->filter = file_filter;
2618 a->filter_ov = fcx;
2619 file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
2620 file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
2621 if( DBG_IOBUF )
2622 log_debug("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno,
2623 a->desc?a->desc:"?");
2624
2625 return a;
2626 }
2627
2628
2629 int
2630 iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
2631 {
2632 if ( cmd == 1 ) { /* keep system filepointer/descriptor open */
2633 if( DBG_IOBUF )
2634 log_debug("iobuf-%d.%d: ioctl `%s' keep=%d\n",
2635 a? a->no:-1, a?a->subno:-1,
2636 a&&a->desc?a->desc:"?", intval );
2637 for( ; a; a = a->chain )
2638 if( !a->chain && a->filter == file_filter ) {
2639 file_filter_ctx_t *b = a->filter_ov;
2640 b->keep_open = intval;
2641 return 0;
2642 }
2643 #ifdef _WIN32
2644 else if( !a->chain && a->filter == sock_filter ) {
2645 sock_filter_ctx_t *b = a->filter_ov;
2646 b->keep_open = intval;
2647 return 0;
2648 }
2649 #endif
2650 }
2651 else if ( cmd == 2 ) { /* invalidate cache */
2652 if( DBG_IOBUF )
2653 log_debug("iobuf-*.*: ioctl `%s' invalidate\n",
2654 ptrval? (char*)ptrval:"[all]");
2655 if ( !a && !intval ) {
2656 #ifndef FILE_FILTER_USES_STDIO
2657 return fd_cache_invalidate (ptrval);
2658 #endif
2659 return 0;
2660 }
2661 }
2662 else if ( cmd == 3 ) { /* disallow/allow caching */
2663 if( DBG_IOBUF )
2664 log_debug("iobuf-%d.%d: ioctl `%s' no_cache=%d\n",
2665 a? a->no:-1, a?a->subno:-1,
2666 a&&a->desc?a->desc:"?", intval );
2667 for( ; a; a = a->chain )
2668 if( !a->chain && a->filter == file_filter ) {
2669 file_filter_ctx_t *b = a->filter_ov;
2670 b->no_cache = intval;
2671 return 0;
2672 }
2673 #ifdef _WIN32
2674 else if( !a->chain && a->filter == sock_filter ) {
2675 sock_filter_ctx_t *b = a->filter_ov;
2676 b->no_cache = intval;
2677 return 0;
2678 }
2679 #endif
2680 }
2681 else if(cmd==4)
2682 {
2683 /* Do a fsync on the open fd and return any errors to the
2684 caller of iobuf_ioctl */
2685 if( DBG_IOBUF )
2686 log_debug("iobuf-*.*: ioctl `%s' fsync\n",
2687 ptrval? (char*)ptrval:"<null>");
2688
2689 if(!a && !intval && ptrval)
2690 {
2691 #ifndef FILE_FILTER_USES_STDIO
2692 return fd_cache_synchronize (ptrval);
2693 #else
2694 return 0;
2695 #endif
2696 }
2697 }
2698
2699 return -1;
2700 }
2701
2702
2703 /****************
2704 * Register an i/o filter.
2705 */
2706 int
2707 iobuf_push_filter( IOBUF a,
2708 int (*f)(void *opaque, int control,
2709 IOBUF chain, byte *buf, size_t *len), void *ov )
2710 {
2711 return iobuf_push_filter2( a, f, ov, 0 );
2712 }
2713
2714 int
2715 iobuf_push_filter2( IOBUF a,
2716 int (*f)(void *opaque, int control,
2717 IOBUF chain, byte *buf, size_t *len),
2718 void *ov, int rel_ov )
2719 {
2720 IOBUF b;
2721 size_t dummy_len=0;
2722 int rc=0;
2723
2724 if( a->directfp )
2725 BUG();
2726
2727 if( a->use == 2 && (rc=iobuf_flush(a)) )
2728 return rc;
2729 /* make a copy of the current stream, so that
2730 * A is the new stream and B the original one.
2731 * The contents of the buffers are transferred to the
2732 * new stream.
2733 */
2734 b = xmalloc(sizeof *b);
2735 memcpy(b, a, sizeof *b );
2736 /* fixme: it is stupid to keep a copy of the name at every level
2737 * but we need the name somewhere because the name known by file_filter
2738 * may have been released when we need the name of the file */
2739 b->real_fname = a->real_fname? xstrdup(a->real_fname):NULL;
2740 /* remove the filter stuff from the new stream */
2741 a->filter = NULL;
2742 a->filter_ov = NULL;
2743 a->filter_ov_owner = 0;
2744 a->filter_eof = 0;
2745 if( a->use == 3 )
2746 a->use = 2; /* make a write stream from a temp stream */
2747
2748 if( a->use == 2 ) { /* allocate a fresh buffer for the original stream */
2749 b->d.buf = xmalloc( a->d.size );
2750 b->d.len = 0;
2751 b->d.start = 0;
2752 }
2753 else { /* allocate a fresh buffer for the new stream */
2754 a->d.buf = xmalloc( a->d.size );
2755 a->d.len = 0;
2756 a->d.start = 0;
2757 }
2758 /* disable nlimit for the new stream */
2759 a->ntotal = b->ntotal + b->nbytes;
2760 a->nlimit = a->nbytes = 0;
2761 a->nofast &= ~1;
2762 /* make a link from the new stream to the original stream */
2763 a->chain = b;
2764 a->opaque = b->opaque;
2765
2766 /* setup the function on the new stream */
2767 a->filter = f;
2768 a->filter_ov = ov;
2769 a->filter_ov_owner = rel_ov;
2770
2771 a->subno = b->subno + 1;
2772 f( ov, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &dummy_len );
2773
2774 if( DBG_IOBUF ) {
2775 log_debug("iobuf-%d.%d: push `%s'\n", a->no, a->subno,
2776 a->desc?a->desc:"?" );
2777 print_chain( a );
2778 }
2779
2780 /* now we can initialize the new function if we have one */
2781 if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_INIT, a->chain,
2782 NULL, &dummy_len)) )
2783 log_error("IOBUFCTRL_INIT failed: %s\n", g10_errstr(rc) );
2784 return rc;
2785 }
2786
2787 /****************
2788 * Remove an i/o filter.
2789 */
2790 static int
2791 pop_filter( IOBUF a, int (*f)(void *opaque, int control,
2792 IOBUF chain, byte *buf, size_t *len), void *ov )
2793 {
2794 IOBUF b;
2795 size_t dummy_len=0;
2796 int rc=0;
2797
2798 if( a->directfp )
2799 BUG();
2800
2801 if( DBG_IOBUF )
2802 log_debug("iobuf-%d.%d: pop `%s'\n", a->no, a->subno,
2803 a->desc?a->desc:"?" );
2804 if( !a->filter ) { /* this is simple */
2805 b = a->chain;
2806 assert(b);
2807 xfree(a->d.buf);
2808 xfree(a->real_fname);
2809 memcpy(a,b, sizeof *a);
2810 xfree(b);
2811 return 0;
2812 }
2813 for(b=a ; b; b = b->chain )
2814 if( b->filter == f && (!ov || b->filter_ov == ov) )
2815 break;
2816 if( !b )
2817 log_bug("pop_filter(): filter function not found\n");
2818
2819 /* flush this stream if it is an output stream */
2820 if( a->use == 2 && (rc=iobuf_flush(b)) ) {
2821 log_error("iobuf_flush failed in pop_filter: %s\n", g10_errstr(rc));
2822 return rc;
2823 }
2824 /* and tell the filter to free it self */
2825 if( b->filter && (rc = b->filter(b->filter_ov, IOBUFCTRL_FREE, b->chain,
2826 NULL, &dummy_len)) ) {
2827 log_error("IOBUFCTRL_FREE failed: %s\n", g10_errstr(rc) );
2828 return rc;
2829 }
2830 if( b->filter_ov && b->filter_ov_owner ) {
2831 xfree( b->filter_ov );
2832 b->filter_ov = NULL;
2833 }
2834
2835
2836 /* and see how to remove it */
2837 if( a == b && !b->chain )
2838 log_bug("can't remove the last filter from the chain\n");
2839 else if( a == b ) { /* remove the first iobuf from the chain */
2840 /* everything from b is copied to a. This is save because
2841 * a flush has been done on the to be removed entry
2842 */
2843 b = a->chain;
2844 xfree(a->d.buf);
2845 xfree(a->real_fname);
2846 memcpy(a,b, sizeof *a);
2847 xfree(b);
2848 if( DBG_IOBUF )
2849 log_debug("iobuf-%d.%d: popped filter\n", a->no, a->subno );
2850 }
2851 else if( !b->chain ) { /* remove the last iobuf from the chain */
2852 log_bug("Ohh jeee, trying to remove a head filter\n");
2853 }
2854 else { /* remove an intermediate iobuf from the chain */
2855 log_bug("Ohh jeee, trying to remove an intermediate filter\n");
2856 }
2857
2858 return rc;
2859 }
2860
2861
2862 /****************
2863 * read underflow: read more bytes into the buffer and return
2864 * the first byte or -1 on EOF.
2865 */
2866 static int
2867 underflow(IOBUF a)
2868 {
2869 size_t len;
2870 int rc;
2871
2872 assert( a->d.start == a->d.len );
2873 if( a->use == 3 )
2874 return -1; /* EOF because a temp buffer can't do an underflow */
2875
2876 if( a->filter_eof ) {
2877 if( a->chain ) {
2878 IOBUF b = a->chain;
2879 if( DBG_IOBUF )
2880 log_debug("iobuf-%d.%d: pop `%s' in underflow\n",
2881 a->no, a->subno, a->desc?a->desc:"?" );
2882 xfree(a->d.buf);
2883 xfree(a->real_fname);
2884 memcpy(a, b, sizeof *a);
2885 xfree(b);
2886 print_chain(a);
2887 }
2888 else
2889 a->filter_eof = 0; /* for the top level filter */
2890 if( DBG_IOBUF )
2891 log_debug("iobuf-%d.%d: underflow: eof (due to filter eof)\n",
2892 a->no, a->subno );
2893 return -1; /* return one(!) EOF */
2894 }
2895 if( a->error ) {
2896 if( DBG_IOBUF )
2897 log_debug("iobuf-%d.%d: error\n", a->no, a->subno );
2898 return -1;
2899 }
2900
2901 if( a->directfp ) {
2902 FILE *fp = a->directfp;
2903
2904 len = fread( a->d.buf, 1, a->d.size, fp);
2905 if( len < a->d.size ) {
2906 if( ferror(fp) )
2907 a->error = 1;
2908 }
2909 a->d.len = len;
2910 a->d.start = 0;
2911 return len? a->d.buf[a->d.start++] : -1;
2912 }
2913
2914
2915 if( a->filter ) {
2916 len = a->d.size;
2917 if( DBG_IOBUF )
2918 log_debug("iobuf-%d.%d: underflow: req=%lu\n",
2919 a->no, a->subno, (ulong)len );
2920 rc = a->filter( a->filter_ov, IOBUFCTRL_UNDERFLOW, a->chain,
2921 a->d.buf, &len );
2922 if( DBG_IOBUF ) {
2923 log_debug("iobuf-%d.%d: underflow: got=%lu rc=%d\n",
2924 a->no, a->subno, (ulong)len, rc );
2925 /* if( a->no == 1 ) */
2926 /* log_hexdump (" data:", a->d.buf, len); */
2927 }
2928 if( a->use == 1 && rc == -1 ) { /* EOF: we can remove the filter */
2929 size_t dummy_len=0;
2930
2931 /* and tell the filter to free itself */
2932 if( (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE, a->chain,
2933 NULL, &dummy_len)) )
2934 log_error("IOBUFCTRL_FREE failed: %s\n", g10_errstr(rc) );
2935 if( a->filter_ov && a->filter_ov_owner ) {
2936 xfree( a->filter_ov );
2937 a->filter_ov = NULL;
2938 }
2939 a->filter = NULL;
2940 a->desc = NULL;
2941 a->filter_ov = NULL;
2942 a->filter_eof = 1;
2943 if( !len && a->chain ) {
2944 IOBUF b = a->chain;
2945 if( DBG_IOBUF )
2946 log_debug("iobuf-%d.%d: pop in underflow (!len)\n",
2947 a->no, a->subno);
2948 xfree(a->d.buf);
2949 xfree(a->real_fname);
2950 memcpy(a,b, sizeof *a);
2951 xfree(b);
2952 print_chain(a);
2953 }
2954 }
2955 else if( rc )
2956 a->error = 1;
2957
2958 if( !len ) {
2959 if( DBG_IOBUF )
2960 log_debug("iobuf-%d.%d: underflow: eof\n", a->no, a->subno );
2961 return -1;
2962 }
2963 a->d.len = len;
2964 a->d.start = 0;
2965 return a->d.buf[a->d.start++];
2966 }
2967 else {
2968 if( DBG_IOBUF )
2969 log_debug("iobuf-%d.%d: underflow: eof (no filter)\n",
2970 a->no, a->subno );
2971 return -1; /* no filter; return EOF */
2972 }
2973 }
2974
2975
2976 int
2977 iobuf_flush(IOBUF a)
2978 {
2979 size_t len;
2980 int rc;
2981
2982 if( a->directfp )
2983 return 0;
2984
2985 if( a->use == 3 ) { /* increase the temp buffer */
2986 char *newbuf;
2987 size_t newsize = a->d.size + IOBUF_BUFFER_SIZE;
2988
2989 if( DBG_IOBUF )
2990 log_debug("increasing temp iobuf from %lu to %lu\n",
2991 (ulong)a->d.size, (ulong)newsize );
2992 newbuf = xmalloc( newsize );
2993 memcpy( newbuf, a->d.buf, a->d.len );
2994 xfree(a->d.buf);
2995 a->d.buf = newbuf;
2996 a->d.size = newsize;
2997 return 0;
2998 }
2999 else if( a->use != 2 )
3000 log_bug("flush on non-output iobuf\n");
3001 else if( !a->filter )
3002 log_bug("iobuf_flush: no filter\n");
3003 len = a->d.len;
3004 rc = a->filter( a->filter_ov, IOBUFCTRL_FLUSH, a->chain, a->d.buf, &len );
3005 if( !rc && len != a->d.len ) {
3006 log_info("iobuf_flush did not write all!\n");
3007 rc = G10ERR_WRITE_FILE;
3008 }
3009 else if( rc )
3010 a->error = 1;
3011 a->d.len = 0;
3012
3013 return rc;
3014 }
3015
3016
3017 /****************
3018 * Read a byte from the iobuf; returns -1 on EOF
3019 */
3020 int
3021 iobuf_readbyte(IOBUF a)
3022 {
3023 int c;
3024
3025 /* nlimit does not work together with unget */
3026 /* nbytes is also not valid! */
3027 if( a->unget.buf ) {
3028 if( a->unget.start < a->unget.len )
3029 return a->unget.buf[a->unget.start++];
3030 xfree(a->unget.buf);
3031 a->unget.buf = NULL;
3032 a->nofast &= ~2;
3033 }
3034
3035 if( a->nlimit && a->nbytes >= a->nlimit )
3036 return -1; /* forced EOF */
3037
3038 if( a->d.start < a->d.len ) {
3039 c = a->d.buf[a->d.start++];
3040 }
3041 else if( (c=underflow(a)) == -1 )
3042 return -1; /* EOF */
3043
3044 a->nbytes++;
3045 return c;
3046 }
3047
3048
3049 int
3050 iobuf_read(IOBUF a, byte *buf, unsigned buflen )
3051 {
3052 int c, n;
3053
3054 if( a->unget.buf || a->nlimit ) {
3055 /* handle special cases */
3056 for(n=0 ; n < buflen; n++ ) {
3057 if( (c = iobuf_readbyte(a)) == -1 ) {
3058 if( !n )
3059 return -1; /* eof */
3060 break;
3061 }
3062 else
3063 if( buf ) *buf = c;
3064 if( buf ) buf++;
3065 }
3066 return n;
3067 }
3068
3069 n = 0;
3070 do {
3071 if( n < buflen && a->d.start < a->d.len ) {
3072 unsigned size = a->d.len - a->d.start;
3073 if( size > buflen - n )
3074 size = buflen - n;
3075 if( buf )
3076 memcpy( buf, a->d.buf + a->d.start, size );
3077 n += size;
3078 a->d.start += size;
3079 if( buf )
3080 buf += size;
3081 }
3082 if( n < buflen ) {
3083 if( (c=underflow(a)) == -1 ) {
3084 a->nbytes += n;
3085 return n? n : -1/*EOF*/;
3086 }
3087 if( buf )
3088 *buf++ = c;
3089 n++;
3090 }
3091 } while( n < buflen );
3092 a->nbytes += n;
3093 return n;
3094 }
3095
3096
3097 /****************
3098 * Have a look at the iobuf.
3099 * NOTE: This only works in special cases.
3100 */
3101 int
3102 iobuf_peek(IOBUF a, byte *buf, unsigned buflen )
3103 {
3104 int n=0;
3105
3106 if( a->filter_eof )
3107 return -1;
3108
3109 if( !(a->d.start < a->d.len) ) {
3110 if( underflow(a) == -1 )
3111 return -1;
3112 /* and unget this character */
3113 assert(a->d.start == 1);
3114 a->d.start = 0;
3115 }
3116
3117 for(n=0 ; n < buflen && (a->d.start+n) < a->d.len ; n++, buf++ )
3118 *buf = a->d.buf[n];
3119 return n;
3120 }
3121
3122
3123
3124
3125 int
3126 iobuf_writebyte(IOBUF a, unsigned c)
3127 {
3128
3129 if( a->directfp )
3130 BUG();
3131
3132 if( a->d.len == a->d.size )
3133 if( iobuf_flush(a) )
3134 return -1;
3135
3136 assert( a->d.len < a->d.size );
3137 a->d.buf[a->d.len++] = c;
3138 return 0;
3139 }
3140
3141
3142 int
3143 iobuf_write(IOBUF a, byte *buf, unsigned buflen )
3144 {
3145
3146 if( a->directfp )
3147 BUG();
3148
3149 do {
3150 if( buflen && a->d.len < a->d.size ) {
3151 unsigned size = a->d.size - a->d.len;
3152 if( size > buflen ) size = buflen;
3153 memcpy( a->d.buf + a->d.len, buf, size );
3154 buflen -= size;
3155 buf += size;
3156 a->d.len += size;
3157 }
3158 if( buflen ) {
3159 if( iobuf_flush(a) )
3160 return -1;
3161 }
3162 } while( buflen );
3163 return 0;
3164 }
3165
3166
3167 int
3168 iobuf_writestr(IOBUF a, const char *buf )
3169 {
3170 for( ; *buf; buf++ )
3171 if( iobuf_writebyte(a, *buf) )
3172 return -1;
3173 return 0;
3174 }
3175
3176
3177
3178 /****************
3179 * copy the contents of TEMP to A.
3180 */
3181 int
3182 iobuf_write_temp( IOBUF a, IOBUF temp )
3183 {
3184 while( temp->chain )
3185 pop_filter( temp, temp->filter, NULL );
3186 return iobuf_write(a, temp->d.buf, temp->d.len );
3187 }
3188
3189 /****************
3190 * copy the contents of the temp io stream to BUFFER.
3191 */
3192 size_t
3193 iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen )
3194 {
3195 size_t n = a->d.len;
3196
3197 if( n > buflen )
3198 n = buflen;
3199 memcpy( buffer, a->d.buf, n );
3200 return n;
3201 }
3202
3203
3204 /****************
3205 * Call this function to terminate processing of the temp stream
3206 * without closing it. This removes all filters from the stream
3207 * makes sure that iobuf_get_temp_{buffer,length}() returns correct
3208 * values.
3209 */
3210 void
3211 iobuf_flush_temp( IOBUF temp )
3212 {
3213 while( temp->chain )
3214 pop_filter( temp, temp->filter, NULL );
3215 }
3216
3217
3218 /****************
3219 * Set a limit on how many bytes may be read from the input stream A.
3220 * Setting the limit to 0 disables this feature.
3221 */
3222 void
3223 iobuf_set_limit( IOBUF a, off_t nlimit )
3224 {
3225 if( nlimit )
3226 a->nofast |= 1;
3227 else
3228 a->nofast &= ~1;
3229 a->nlimit = nlimit;
3230 a->ntotal += a->nbytes;
3231 a->nbytes = 0;
3232 }
3233
3234
3235
3236 /* Return the length of an open file A. IF OVERFLOW is not NULL it
3237 will be set to true if the file is larger than what off_t can cope
3238 with. The function return 0 on error or on overflow condition. */
3239 off_t
3240 iobuf_get_filelength (IOBUF a, int *overflow )
3241 {
3242 struct stat st;
3243
3244 if (overflow)
3245 *overflow = 0;
3246
3247 if( a->directfp ) {
3248 FILE *fp = a->directfp;
3249
3250 if( !fstat(fileno(fp), &st) )
3251 return st.st_size;
3252 log_error("fstat() failed: %s\n", strerror(errno) );
3253 return 0;
3254 }
3255
3256 /* Hmmm: file_filter may have already been removed */
3257 for( ; a; a = a->chain )
3258 if( !a->chain && a->filter == file_filter ) {
3259 file_filter_ctx_t *b = a->filter_ov;
3260 FILEP_OR_FD fp = b->fp;
3261
3262 #if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO)
3263 ulong size;
3264 static int (* __stdcall get_file_size_ex)
3265 (void *handle, LARGE_INTEGER *size);
3266 static int get_file_size_ex_initialized;
3267
3268 if (!get_file_size_ex_initialized)
3269 {
3270 void *handle;
3271
3272 handle = dlopen ("kernel32.dll", RTLD_LAZY);
3273 if (handle)
3274 {
3275 get_file_size_ex = dlsym (handle, "GetFileSizeEx");
3276 if (!get_file_size_ex)
3277 dlclose (handle);
3278 }
3279 get_file_size_ex_initialized = 1;
3280 }
3281
3282 if (get_file_size_ex)
3283 {
3284 /* This is a newer system with GetFileSizeEx; we use
3285 this then becuase it seem that GetFileSize won't
3286 return a proper error in case a file is larger than
3287 4GB. */
3288 LARGE_INTEGER size;
3289
3290 if (get_file_size_ex (fp, &size))
3291 {
3292 if (!size.u.HighPart)
3293 return size.u.LowPart;
3294 if (overflow)
3295 *overflow = 1;
3296 return 0;
3297 }
3298 }
3299 else
3300 {
3301 if ((size=GetFileSize (fp, NULL)) != 0xffffffff)
3302 return size;
3303 }
3304 log_error ("GetFileSize for handle %p failed: %s\n",
3305 fp, w32_strerror (0));
3306 #else
3307 if( !fstat(my_fileno(fp), &st) )
3308 return st.st_size;
3309 log_error("fstat() failed: %s\n", strerror(errno) );
3310 #endif
3311 break;
3312 }
3313
3314 return 0;
3315 }
3316
3317
3318 /* Return the file descriptor of the underlying file or -1 if it is
3319 not available. */
3320 int
3321 iobuf_get_fd (IOBUF a)
3322 {
3323 if (a->directfp)
3324 return fileno ( (FILE*)a->directfp );
3325
3326 for ( ; a; a = a->chain )
3327 if (!a->chain && a->filter == file_filter)
3328 {
3329 file_filter_ctx_t *b = a->filter_ov;
3330 FILEP_OR_FD fp = b->fp;
3331
3332 return my_fileno (fp);
3333 }
3334
3335 return -1;
3336 }
3337
3338
3339 /****************
3340 * Tell the file position, where the next read will take place
3341 */
3342 off_t
3343 iobuf_tell( IOBUF a )
3344 {
3345 return a->ntotal + a->nbytes;
3346 }
3347
3348
3349 #if !defined(HAVE_FSEEKO) && !defined(fseeko)
3350
3351 #ifdef HAVE_LIMITS_H
3352 # include <limits.h>
3353 #endif
3354 #ifndef LONG_MAX
3355 # define LONG_MAX ((long) ((unsigned long) -1 >> 1))
3356 #endif
3357 #ifndef LONG_MIN
3358 # define LONG_MIN (-1 - LONG_MAX)
3359 #endif
3360
3361 /****************
3362 * A substitute for fseeko, for hosts that don't have it.
3363 */
3364 static int
3365 fseeko( FILE *stream, off_t newpos, int whence )
3366 {
3367 while( newpos != (long) newpos ) {
3368 long pos = newpos < 0 ? LONG_MIN : LONG_MAX;
3369 if( fseek( stream, pos, whence ) != 0 )
3370 return -1;
3371 newpos -= pos;
3372 whence = SEEK_CUR;
3373 }
3374 return fseek( stream, (long)newpos, whence );
3375 }
3376 #endif
3377
3378 /****************
3379 * This is a very limited implementation. It simply discards all internal
3380 * buffering and removes all filters but the first one.
3381 */
3382 int
3383 iobuf_seek( IOBUF a, off_t newpos )
3384 {
3385 file_filter_ctx_t *b = NULL;
3386
3387 if( a->directfp ) {
3388 FILE *fp = a->directfp;
3389 if( fseeko( fp, newpos, SEEK_SET ) ) {
3390 log_error("can't seek: %s\n", strerror(errno) );
3391 return -1;
3392 }
3393 clearerr(fp);
3394 }
3395 else {
3396 for( ; a; a = a->chain ) {
3397 if( !a->chain && a->filter == file_filter ) {
3398 b = a->filter_ov;
3399 break;
3400 }
3401 }
3402 if( !a )
3403 return -1;
3404 #ifdef FILE_FILTER_USES_STDIO
3405 if( fseeko( b->fp, newpos, SEEK_SET ) ) {
3406 log_error("can't fseek: %s\n", strerror(errno) );
3407 return -1;
3408 }
3409 #else
3410 #ifdef HAVE_DOSISH_SYSTEM
3411 if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) {
3412 log_error ("SetFilePointer failed on handle %p: %s\n",
3413 b->fp, w32_strerror (0));
3414 return -1;
3415 }
3416 #else
3417 if ( lseek (b->fp, newpos, SEEK_SET) == (off_t)-1 ) {
3418 log_error("can't lseek: %s\n", strerror(errno) );
3419 return -1;
3420 }
3421 #endif
3422 #endif
3423 }
3424 a->d.len = 0; /* discard buffer */
3425 a->d.start = 0;
3426 a->nbytes = 0;
3427 a->nlimit = 0;
3428 a->nofast &= ~1;
3429 a->ntotal = newpos;
3430 a->error = 0;
3431 /* remove filters, but the last */
3432 if( a->chain )
3433 log_debug("pop_filter called in iobuf_seek - please report\n");
3434 while( a->chain )
3435 pop_filter( a, a->filter, NULL );
3436
3437 return 0;
3438 }
3439
3440
3441
3442
3443
3444
3445 /****************
3446 * Retrieve the real filename
3447 */
3448 const char *
3449 iobuf_get_real_fname( IOBUF a )
3450 {
3451 if( a->real_fname )
3452 return a->real_fname;
3453
3454 /* the old solution */
3455 for( ; a; a = a->chain )
3456 if( !a->chain && a->filter == file_filter ) {
3457 file_filter_ctx_t *b = a->filter_ov;
3458 return b->print_only_name? NULL : b->fname;
3459 }
3460
3461 return NULL;
3462 }
3463
3464
3465 /****************
3466 * Retrieve the filename
3467 */
3468 const char *
3469 iobuf_get_fname( IOBUF a )
3470 {
3471 for( ; a; a = a->chain )
3472 if( !a->chain && a->filter == file_filter ) {
3473 file_filter_ctx_t *b = a->filter_ov;
3474 return b->fname;
3475 }
3476
3477 return NULL;
3478 }
3479
3480
3481 /****************
3482 * enable partial block mode as described in the OpenPGP draft.
3483 * LEN is the first length byte on read, but ignored on writes.
3484 */
3485 void
3486 iobuf_set_partial_block_mode( IOBUF a, size_t len )
3487 {
3488 block_filter_ctx_t *ctx = xmalloc_clear( sizeof *ctx );
3489
3490 assert( a->use == 1 || a->use == 2 );
3491 ctx->use = a->use;
3492 if( !len ) {
3493 if( a->use == 1 )
3494 log_debug("pop_filter called in set_partial_block_mode"
3495 " - please report\n");
3496 pop_filter(a, block_filter, NULL );
3497 }
3498 else {
3499 ctx->partial = 1;
3500 ctx->size = 0;
3501 ctx->first_c = len;
3502 iobuf_push_filter(a, block_filter, ctx );
3503 }
3504 }
3505
3506
3507 /****************
3508 * Same as fgets() but if the buffer is too short a larger one will
3509 * be allocated up to some limit *max_length.
3510 * A line is considered a byte stream ending in a LF.
3511 * Returns the length of the line. EOF is indicated by a line of
3512 * length zero. The last LF may be missing due to an EOF.
3513 * is max_length is zero on return, the line has been truncated.
3514 *
3515 * Note: The buffer is allocated with enough space to append a CR,LF,EOL
3516 */
3517 unsigned
3518 iobuf_read_line( IOBUF a, byte **addr_of_buffer,
3519 unsigned *length_of_buffer, unsigned *max_length )
3520 {
3521 int c;
3522 char *buffer = *addr_of_buffer;
3523 unsigned length = *length_of_buffer;
3524 unsigned nbytes = 0;
3525 unsigned maxlen = *max_length;
3526 char *p;
3527
3528 if( !buffer ) { /* must allocate a new buffer */
3529 length = 256;
3530 buffer = xmalloc( length );
3531 *addr_of_buffer = buffer;
3532 *length_of_buffer = length;
3533 }
3534
3535 length -= 3; /* reserve 3 bytes (cr,lf,eol) */
3536 p = buffer;
3537 while( (c=iobuf_get(a)) != -1 ) {
3538 if( nbytes == length ) { /* increase the buffer */
3539 if( length > maxlen ) { /* this is out limit */
3540 /* skip the rest of the line */
3541 while( c != '\n' && (c=iobuf_get(a)) != -1 )
3542 ;
3543 *p++ = '\n'; /* always append a LF (we have reserved space) */
3544 nbytes++;
3545 *max_length = 0; /* indicate truncation */
3546 break;
3547 }
3548 length += 3; /* correct for the reserved byte */
3549 length += length < 1024? 256 : 1024;
3550 buffer = xrealloc( buffer, length );
3551 *addr_of_buffer = buffer;
3552 *length_of_buffer = length;
3553 length -= 3; /* and reserve again */
3554 p = buffer + nbytes;
3555 }
3556 *p++ = c;
3557 nbytes++;
3558 if( c == '\n' )
3559 break;
3560 }
3561 *p = 0; /* make sure the line is a string */
3562
3563 return nbytes;
3564 }
3565
3566 /* This is the non iobuf specific function */
3567 int
3568 iobuf_translate_file_handle ( int fd, int for_write )
3569 {
3570 #ifdef _WIN32
3571 {
3572 int x;
3573
3574 if ( fd <= 2 )
3575 return fd; /* do not do this for error, stdin, stdout, stderr */
3576
3577 x = _open_osfhandle ( fd, for_write? 1:0 );
3578 if (x==-1 )
3579 log_error ("failed to translate osfhandle %p\n", (void*)fd );
3580 else {
3581 /*log_info ("_open_osfhandle %p yields %d%s\n",
3582 (void*)fd, x, for_write? " for writing":"" );*/
3583 fd = x;
3584 }
3585 }
3586 #endif
3587 return fd;
3588 }
3589
3590 static int
3591 translate_file_handle ( int fd, int for_write )
3592 {
3593 #ifdef _WIN32
3594 #ifdef FILE_FILTER_USES_STDIO
3595 fd = iobuf_translate_file_handle (fd, for_write);
3596 #else
3597 {
3598 int x;
3599
3600 if ( fd == 0 )
3601 x = (int)GetStdHandle (STD_INPUT_HANDLE);
3602 else if (fd == 1)
3603 x = (int)GetStdHandle (STD_OUTPUT_HANDLE);
3604 else if (fd == 2)
3605 x = (int)GetStdHandle (STD_ERROR_HANDLE);
3606 else
3607 x = fd;
3608
3609 if (x == -1)
3610 log_debug ("GetStdHandle(%d) failed: %s\n",
3611 fd, w32_strerror (0));
3612
3613 fd = x;
3614 }
3615 #endif
3616 #endif
3617 return fd;
3618 }
3619
3620
3621 void
3622 iobuf_skip_rest(IOBUF a, unsigned long n, int partial)
3623 {
3624 if ( partial ) {
3625 for (;;) {
3626 if (a->nofast || a->d.start >= a->d.len) {
3627 if (iobuf_readbyte (a) == -1) {
3628 break;
3629 }
3630 } else {
3631 unsigned long count = a->d.len - a->d.start;
3632 a->nbytes += count;
3633 a->d.start = a->d.len;
3634 }
3635 }
3636 } else {
3637 unsigned long remaining = n;
3638 while (remaining > 0) {
3639 if (a->nofast || a->d.start >= a->d.len) {
3640 if (iobuf_readbyte (a) == -1) {
3641 break;
3642 }
3643 --remaining;
3644 } else {
3645 unsigned long count = a->d.len - a->d.start;
3646 if (count > remaining) {
3647 count = remaining;
3648 }
3649 a->nbytes += count;
3650 a->d.start += count;
3651 remaining -= count;
3652 }
3653 }
3654 }
3655 }
- A4CA272E00EBA069786CB1EDFB3F7054C5B31630A22AE66C012878D4BCEE96B11298141730589F0A0DDB04EEFF1C2F4EEF5A25D88447226F32EAA5346595EA96
+
mpi/logger.c
(1 . 262)(0 . 0)
3660 /* logger.c - log functions
3661 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3662 *
3663 * This file is part of GnuPG.
3664 *
3665 * GnuPG is free software; you can redistribute it and/or modify
3666 * it under the terms of the GNU General Public License as published by
3667 * the Free Software Foundation; either version 3 of the License, or
3668 * (at your option) any later version.
3669 *
3670 * GnuPG is distributed in the hope that it will be useful,
3671 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3672 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3673 * GNU General Public License for more details.
3674 *
3675 * You should have received a copy of the GNU General Public License
3676 * along with this program; if not, see <http://www.gnu.org/licenses/>.
3677 */
3678
3679 #include <config.h>
3680 #include <stdio.h>
3681 #include <stdlib.h>
3682 #include <stdarg.h>
3683 #include <string.h>
3684 #include <errno.h>
3685
3686 #include "util.h"
3687
3688 static char pidstring[15];
3689 static char *pgm_name;
3690 static int errorcount;
3691 static int strict;
3692 static FILE *logfp;
3693
3694 /****************
3695 * Set the logfile to use (not yet implemneted) or, if logfile is NULL,
3696 * the Fd where logoutputs should go.
3697 */
3698 void
3699 log_set_logfile( const char *name, int fd )
3700 {
3701 if( name )
3702 BUG();
3703
3704 if( logfp && logfp != stderr && logfp != stdout )
3705 fclose( logfp );
3706 if( fd == 1 )
3707 logfp = stdout;
3708 else if( fd == 2 )
3709 logfp = stderr;
3710 else
3711 logfp = fdopen( fd, "a" );
3712 if( !logfp ) {
3713 logfp = stderr;
3714 log_fatal("can't open fd %d for logging: %s\n", fd, strerror(errno));
3715 }
3716 }
3717
3718 FILE *
3719 log_stream()
3720 {
3721 if( !logfp )
3722 logfp = stderr;
3723 return logfp;
3724 }
3725
3726
3727 void
3728 log_set_name( const char *name )
3729 {
3730 xfree(pgm_name);
3731 if( name )
3732 pgm_name = xstrdup(name);
3733 else
3734 pgm_name = NULL;
3735 }
3736
3737 const char *
3738 log_get_name(void)
3739 {
3740 return pgm_name? pgm_name : "";
3741 }
3742
3743
3744 void
3745 log_set_pid( int pid )
3746 {
3747 if( pid )
3748 sprintf(pidstring,"[%u]", (unsigned)pid );
3749 else
3750 *pidstring = 0;
3751 }
3752
3753 int
3754 log_get_errorcount( int clear)
3755 {
3756 int n = errorcount;
3757 if( clear )
3758 errorcount = 0;
3759 return n;
3760 }
3761
3762 void
3763 log_inc_errorcount()
3764 {
3765 errorcount++;
3766 }
3767
3768 int
3769 log_set_strict(int val)
3770 {
3771 int old=strict;
3772 strict=val;
3773 return old;
3774 }
3775
3776 void
3777 g10_log_print_prefix(const char *text)
3778 {
3779 if( !logfp )
3780 logfp = stderr;
3781 if( pgm_name )
3782 fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text );
3783 else
3784 fprintf(logfp, "?%s: %s", pidstring, text );
3785 #ifdef __riscos__
3786 fflush( logfp );
3787 #endif /* __riscos__ */
3788 }
3789
3790
3791 void
3792 g10_log_info( const char *fmt, ... )
3793 {
3794 va_list arg_ptr ;
3795
3796 g10_log_print_prefix("");
3797 va_start( arg_ptr, fmt ) ;
3798 vfprintf(logfp,fmt,arg_ptr) ;
3799 va_end(arg_ptr);
3800 #ifdef __riscos__
3801 fflush( logfp );
3802 #endif /* __riscos__ */
3803 }
3804
3805
3806 void
3807 g10_log_warning( const char *fmt, ... )
3808 {
3809 va_list arg_ptr ;
3810
3811 if(strict)
3812 {
3813 errorcount++;
3814 g10_log_print_prefix(_("ERROR: "));
3815 }
3816 else
3817 g10_log_print_prefix(_("WARNING: "));
3818
3819 va_start( arg_ptr, fmt ) ;
3820 vfprintf(logfp,fmt,arg_ptr) ;
3821 va_end(arg_ptr);
3822 #ifdef __riscos__
3823 fflush( logfp );
3824 #endif /* __riscos__ */
3825 }
3826
3827
3828 void
3829 g10_log_error( const char *fmt, ... )
3830 {
3831 va_list arg_ptr ;
3832
3833 g10_log_print_prefix("");
3834 va_start( arg_ptr, fmt ) ;
3835 vfprintf(logfp,fmt,arg_ptr) ;
3836 va_end(arg_ptr);
3837 errorcount++;
3838 #ifdef __riscos__
3839 fflush( logfp );
3840 #endif /* __riscos__ */
3841 }
3842
3843
3844 void
3845 g10_log_fatal( const char *fmt, ... )
3846 {
3847 va_list arg_ptr ;
3848
3849 g10_log_print_prefix("fatal: ");
3850 va_start( arg_ptr, fmt ) ;
3851 vfprintf(logfp,fmt,arg_ptr) ;
3852 va_end(arg_ptr);
3853 secmem_dump_stats();
3854 #ifdef __riscos__
3855 fflush( logfp );
3856 #endif /* __riscos__ */
3857 exit(2);
3858 }
3859
3860 void
3861 g10_log_bug( const char *fmt, ... )
3862 {
3863 va_list arg_ptr ;
3864
3865 putc('\n', stderr );
3866 g10_log_print_prefix("Ohhhh jeeee: ");
3867 va_start( arg_ptr, fmt ) ;
3868 vfprintf(stderr,fmt,arg_ptr) ;
3869 va_end(arg_ptr);
3870 fflush(stderr);
3871 secmem_dump_stats();
3872 abort();
3873 }
3874
3875 #if defined (__riscos__) \
3876 || ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
3877 void
3878 g10_log_bug0( const char *file, int line, const char *func )
3879 {
3880 log_bug(_("... this is a bug (%s:%d:%s)\n"), file, line, func );
3881 }
3882 #else
3883 void
3884 g10_log_bug0( const char *file, int line )
3885 {
3886 log_bug(_("you found a bug ... (%s:%d)\n"), file, line);
3887 }
3888 #endif
3889
3890 void
3891 g10_log_debug( const char *fmt, ... )
3892 {
3893 va_list arg_ptr ;
3894
3895 g10_log_print_prefix("DBG: ");
3896 va_start( arg_ptr, fmt ) ;
3897 vfprintf(logfp,fmt,arg_ptr) ;
3898 va_end(arg_ptr);
3899 #ifdef __riscos__
3900 fflush( logfp );
3901 #endif /* __riscos__ */
3902 }
3903
3904
3905
3906 void
3907 g10_log_hexdump( const char *text, const char *buf, size_t len )
3908 {
3909 int i;
3910
3911 g10_log_print_prefix(text);
3912 for(i=0; i < len; i++ )
3913 fprintf(logfp, " %02X", ((const byte*)buf)[i] );
3914 fputc('\n', logfp);
3915 #ifdef __riscos__
3916 fflush( logfp );
3917 #endif /* __riscos__ */
3918 }
3919
3920
3921
- D946187EDC8013ACEC997499092EB30464487922925230FBFE5D21EA6CD76320625E947B8F47CF19EC4C47987CC5DCD0C22E6DBFB4B40E4B0F93189C29B5BFC9
+ 50746FE355731DA38601BCF9CEE34DDBA73D8C28B950912F6A4FBD5D2F614CBEB8A245F4EC0E9E97EE7D21AA0A39CF1337A519B78EB81B27C77A750EA893BA8B
mpi/Makefile
(17 . 6)(17 . 7)
3926
3927 $(PROGRAM): $(OBJECTS)
3928 ar rcs $(DIST)/$(PROGRAM) $(OBJECTS)
3929 #ld -o $(DIST)/$(PROGRAM).o $(OBJECTS) -lc
3930
3931 clean :
3932 rm -rf nul core *flymake* $(BUILD)/*.o $(DIST)/$(PROGRAM) *~ bin/*
- 9DEA2170DE57AC92123D3DAC0FD5930BC5C1A5AC88CA1C2FDA88C8555091A38E5862FD7AC5BCED9393349F66AB970707B27D759FE0041F358A0D205E066ECDE0
+ 4E3DCB1355D54A4A2CC9EEBDDFEEAB38E3EDD49F20EF18A7DDCA12CB57497820AE200708B20FA697CEC54E4B65CD8AD3F2487ADD90DEFC420EB33B94AB460304
mpi/memory.c
(1 . 23)(1 . 26)
3937 /* memory.c - memory allocation
3938 * Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
3939 * Modified by No Such Labs. (C) 2015. See README.
3940 *
3941 * This file is part of GnuPG.
3942 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
3943 * SHA256(gnupg-1.4.10.tar.gz):
3944 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
3945 * (C) 1994-2005 Free Software Foundation, Inc.
3946 *
3947 * GnuPG is free software; you can redistribute it and/or modify
3948 * This program is free software: you can redistribute it and/or modify
3949 * it under the terms of the GNU General Public License as published by
3950 * the Free Software Foundation; either version 3 of the License, or
3951 * the Free Software Foundation, either version 3 of the License, or
3952 * (at your option) any later version.
3953 *
3954 * GnuPG is distributed in the hope that it will be useful,
3955 * This program is distributed in the hope that it will be useful,
3956 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3957 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3958 * GNU General Public License for more details.
3959 *
3960 * You should have received a copy of the GNU General Public License
3961 * along with this program; if not, see <http://www.gnu.org/licenses/>.
3962 *
3963 *
3964 * We use our own memory allocation functions instead of plain malloc(),
3965 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3966 */
3967
3968 /* We use our own memory allocation functions instead of plain malloc(),
3969 * so that we can provide some special enhancements:
3970 * a) functions to provide memory from a secure memory.
3971 * b) by looking at the requested allocation size we
(27 . 17)(30 . 16)
3973 * d) memory checking if compiled with M_GUARD
3974 */
3975
3976 #include <config.h>
3977 #include <stdio.h>
3978 #include <stdlib.h>
3979 #include <string.h>
3980 #include <stdarg.h>
3981 #include <string.h>
3982
3983 #include "knobs.h"
3984 #include "types.h"
3985 #include "memory.h"
3986 #include "util.h"
3987
3988
3989 #define MAGIC_NOR_BYTE 0x55
3990 #define MAGIC_SEC_BYTE 0xcc
3991 #define MAGIC_END_BYTE 0xaa
(76 . 14)(78 . 10)
3993 #define FNAMEXM(a) m_debug_ ##a
3994 #define FNAMEPRT , const char *info
3995 #define FNAMEARG , info
3996 #ifndef __riscos__
3997
3998 #define store_len(p,n,m) do { add_entry(p,n,m, \
3999 info, __FUNCTION__); } while(0)
4000 #else
4001 #define store_len(p,n,m) do { add_entry(p,n,m, \
4002 info, __func__ ); } while(0)
4003 #endif
4004 #else
4005 #define FNAME(a) m_ ##a
4006 #define FNAMEX(a) x ##a
4007 #define FNAMEXM(a) xm ##a
(337 . 11)(335 . 7)
4009
4010 for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) {
4011 if( e->inuse ) {
4012 #ifndef __riscos__
4013 check_mem(e->user_p-4-EXTRA_ALIGN, info);
4014 #else
4015 check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info);
4016 #endif
4017 }
4018 }
4019 }
(411 . 10)(405 . 7)
4021 log_info ("(this may be caused by too many secret keys used "
4022 "simultaneously or due to excessive large key sizes)\n");
4023 }
4024 #if defined(M_GUARD) && defined(__riscos__)
4025 abort();
4026 #endif
4027 exit (2);
4028 exit(2);
4029 }
4030
4031 /****************
(678 . 4)(669 . 3)
4033 out_of_core (nbytes, 1);
4034 return xmalloc_secure_clear (nbytes);
4035 }
4036
- FFCEA4F2389EB4919DF50FC60423606D2835E4BE6A853FA885754CF04C397FE96D4A688ECCD591C60BC687846AE1E230304D3554B3E504E2E53662270342C591
+ 956452037539C9B7F45834858A92E436FB65D7482B6B44D2624E2279E9203B59D992A0D405F778638B5E03ADB9F51A545D5C5B55CC31D59453523FBD75F2BE5B
mpi/mpi-add.c
(1 . 35)(1 . 29)
4041 /* mpi-add.c - MPI functions
4042 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4043 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
4044 * Modified by No Such Labs. (C) 2015. See README.
4045 *
4046 * This file is part of GnuPG.
4047 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4048 * SHA256(gnupg-1.4.10.tar.gz):
4049 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4050 * (C) 1994-2005 Free Software Foundation, Inc.
4051 *
4052 * GnuPG is free software; you can redistribute it and/or modify
4053 * This program is free software: you can redistribute it and/or modify
4054 * it under the terms of the GNU General Public License as published by
4055 * the Free Software Foundation; either version 3 of the License, or
4056 * the Free Software Foundation, either version 3 of the License, or
4057 * (at your option) any later version.
4058 *
4059 * GnuPG is distributed in the hope that it will be useful,
4060 * This program is distributed in the hope that it will be useful,
4061 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4062 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4063 * GNU General Public License for more details.
4064 *
4065 * You should have received a copy of the GNU General Public License
4066 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4067 *
4068 * Note: This code is heavily based on the GNU MP Library.
4069 * Actually it's the same code with only minor changes in the
4070 * way the data is stored; this is to support the abstraction
4071 * of an optional secure memory allocation which may be used
4072 * to avoid revealing of sensitive data due to paging etc.
4073 * The GNU MP Library itself is published under the LGPL;
4074 * however I decided to publish this code under the plain GPL.
4075 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4076 */
4077
4078 #include <config.h>
4079 #include <stdio.h>
4080 #include <stdlib.h>
4081
4082 #include "knobs.h"
4083 #include "mpi-internal.h"
4084
4085
- A48F6DCD95712D600A89EFAE6DC7425B5CADE2869B48AA49D6D6FC5C42D63EC462E2A1FCB08CB1DF5468A9A5AD8C8DD419DC7FB8F5758AD0D93007960B19A153
+ D3AB216D028E41835D4511CD451A4D774B268DC38A17322DCDEEED542A949E5DBAEECBB377DAA353B7E31ADA19EBE05247FF696CA571D2862DD26C631AA124EE
mpi/mpi-bit.c
(1 . 26)(1 . 30)
4090 /* mpi-bit.c - MPI bit level fucntions
4091 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4092 * Modified by No Such Labs. (C) 2015. See README.
4093 *
4094 * This file is part of GnuPG.
4095 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4096 * SHA256(gnupg-1.4.10.tar.gz):
4097 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4098 * (C) 1994-2005 Free Software Foundation, Inc.
4099 *
4100 * GnuPG is free software; you can redistribute it and/or modify
4101 * This program is free software: you can redistribute it and/or modify
4102 * it under the terms of the GNU General Public License as published by
4103 * the Free Software Foundation; either version 3 of the License, or
4104 * the Free Software Foundation, either version 3 of the License, or
4105 * (at your option) any later version.
4106 *
4107 * GnuPG is distributed in the hope that it will be useful,
4108 * This program is distributed in the hope that it will be useful,
4109 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4110 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4111 * GNU General Public License for more details.
4112 *
4113 * You should have received a copy of the GNU General Public License
4114 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4115 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4116 */
4117
4118 #include <config.h>
4119 #include <stdio.h>
4120 #include <stdlib.h>
4121 #include <assert.h>
4122
4123 #include "knobs.h"
4124 #include "mpi-internal.h"
4125 #include "longlong.h"
4126
- 83C978461CA2FC606EAB05035DB9A67D600396F013E5CE0DB8CC110D8881E9BE513D540B27DAECC8B0293178D7AB27EE52F5C947A0B9976863B9094F82EBD522
+ C16F3EACAC322384CD8D5AC67D1A3F287E5A32EA9CD3A8AF650F97952739D9BC361BC1808390C5B1E6F914FC119BBCDAB020F7B403B9ADB2A03593569DA5326D
mpi/mpi-cmp.c
(1 . 25)(1 . 29)
4131 /* mpi-cmp.c - MPI functions
4132 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4133 * Modified by No Such Labs. (C) 2015. See README.
4134 *
4135 * This file is part of GnuPG.
4136 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4137 * SHA256(gnupg-1.4.10.tar.gz):
4138 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4139 * (C) 1994-2005 Free Software Foundation, Inc.
4140 *
4141 * GnuPG is free software; you can redistribute it and/or modify
4142 * This program is free software: you can redistribute it and/or modify
4143 * it under the terms of the GNU General Public License as published by
4144 * the Free Software Foundation; either version 3 of the License, or
4145 * the Free Software Foundation, either version 3 of the License, or
4146 * (at your option) any later version.
4147 *
4148 * GnuPG is distributed in the hope that it will be useful,
4149 * This program is distributed in the hope that it will be useful,
4150 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4151 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4152 * GNU General Public License for more details.
4153 *
4154 * You should have received a copy of the GNU General Public License
4155 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4156 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4157 */
4158
4159 #include <config.h>
4160 #include <stdio.h>
4161 #include <stdlib.h>
4162
4163 #include "knobs.h"
4164 #include "mpi-internal.h"
4165
4166 int
- 6A4860EA723098A2E2BA703D8748F6D26C22D1AE72647A5CCCA67AB93976390B0D992BA870796BE3DA3B736B1A11B36F700A93214AE5926EC2652D1EDEE390A3
+ 86D94794C314885A11E11ADBAEB4F4C4E4576BDECD18E35FA758AC471D151322E051D57488DF4910BDF315B1670F5B3E0D6E1423856209FC6EC05CAE1704E6B8
mpi/mpicoder.c
(1 . 31)(1 . 33)
4171 /* mpicoder.c - Coder for the external representation of MPIs
4172 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
4173 * Modified by No Such Labs. (C) 2015. See README.
4174 *
4175 * This file is part of GnuPG.
4176 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4177 * SHA256(gnupg-1.4.10.tar.gz):
4178 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4179 * (C) 1994-2005 Free Software Foundation, Inc.
4180 *
4181 * GnuPG is free software; you can redistribute it and/or modify
4182 * This program is free software: you can redistribute it and/or modify
4183 * it under the terms of the GNU General Public License as published by
4184 * the Free Software Foundation; either version 3 of the License, or
4185 * the Free Software Foundation, either version 3 of the License, or
4186 * (at your option) any later version.
4187 *
4188 * GnuPG is distributed in the hope that it will be useful,
4189 * This program is distributed in the hope that it will be useful,
4190 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4191 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4192 * GNU General Public License for more details.
4193 *
4194 * You should have received a copy of the GNU General Public License
4195 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4196 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4197 */
4198
4199 #include <config.h>
4200 #include <stdio.h>
4201 #include <string.h>
4202 #include <stdlib.h>
4203 #include <assert.h>
4204
4205 #include "knobs.h"
4206 #include "mpi.h"
4207 #include "mpi-internal.h"
4208 #include "iobuf.h"
4209 #include "memory.h"
4210 #include "util.h"
4211
(35 . 110)(37 . 6)
4213
4214 #define MAX_EXTERN_MPI_BITS 16384
4215
4216 /****************
4217 * write an mpi to out.
4218 */
4219 int
4220 mpi_write( IOBUF out, MPI a )
4221 {
4222 int rc;
4223 unsigned nbits = mpi_get_nbits(a);
4224 byte *p, *buf;
4225 unsigned n;
4226
4227 if( nbits > MAX_EXTERN_MPI_BITS )
4228 log_bug("mpi_encode: mpi too large (%u bits)\n", nbits);
4229
4230 iobuf_put(out, (nbits >>8) );
4231 iobuf_put(out, (nbits) );
4232
4233 p = buf = mpi_get_buffer( a, &n, NULL );
4234 rc = iobuf_write( out, p, n );
4235 xfree(buf);
4236 return rc;
4237 }
4238
4239
4240 /****************
4241 * Read an external representation of an mpi and return the MPI
4242 * The external format is a 16 bit unsigned value stored in network byte order,
4243 * giving the number of bits for the following integer. The integer is stored
4244 * with MSB first (left padded with zeroes to align on a byte boundary).
4245 */
4246 MPI
4247 #ifdef M_DEBUG
4248 mpi_debug_read(IOBUF inp, unsigned *ret_nread, int secure, const char *info)
4249 #else
4250 mpi_read(IOBUF inp, unsigned *ret_nread, int secure)
4251 #endif
4252 {
4253 int c, i, j;
4254 unsigned int nmax = *ret_nread;
4255 unsigned nbits, nbytes, nlimbs, nread=0;
4256 mpi_limb_t a;
4257 MPI val = NULL;
4258
4259 if (nread == nmax)
4260 goto overflow;
4261 if( (c = iobuf_get(inp)) == -1 )
4262 goto leave;
4263 nread++;
4264 nbits = c << 8;
4265
4266 if (nread == nmax)
4267 goto overflow;
4268 if( (c = iobuf_get(inp)) == -1 )
4269 goto leave;
4270 nread++;
4271 nbits |= c;
4272
4273 if( nbits > MAX_EXTERN_MPI_BITS ) {
4274 log_error("mpi too large for this implementation (%u bits)\n", nbits);
4275 goto leave;
4276 }
4277
4278 nbytes = (nbits+7) / 8;
4279 nlimbs = (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB;
4280 #ifdef M_DEBUG
4281 val = secure? mpi_debug_alloc_secure( nlimbs, info )
4282 : mpi_debug_alloc( nlimbs, info );
4283 #else
4284 val = secure? mpi_alloc_secure( nlimbs )
4285 : mpi_alloc( nlimbs );
4286 #endif
4287 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
4288 i %= BYTES_PER_MPI_LIMB;
4289 val->nbits = nbits;
4290 j= val->nlimbs = nlimbs;
4291 val->sign = 0;
4292 for( ; j > 0; j-- ) {
4293 a = 0;
4294 for(; i < BYTES_PER_MPI_LIMB; i++ ) {
4295 if (nread == nmax) {
4296 #ifdef M_DEBUG
4297 mpi_debug_free (val);
4298 #else
4299 mpi_free (val);
4300 #endif
4301 val = NULL;
4302 goto overflow;
4303 }
4304 a <<= 8;
4305 a |= iobuf_get(inp) & 0xff; nread++;
4306 }
4307 i = 0;
4308 val->d[j-1] = a;
4309 }
4310
4311 leave:
4312 *ret_nread = nread;
4313 return val;
4314 overflow:
4315 log_error ("mpi larger than indicated length (%u bytes)\n", nmax);
4316 *ret_nread = nread;
4317 return val;
4318 }
4319
4320
4321 MPI
4322 mpi_read_from_buffer(byte *buffer, unsigned int *ret_nread, int secure)
(309 . 6)(207 . 7)
4324 }
4325
4326
4327 /*
4328 void
4329 g10_log_mpidump( const char *text, MPI a )
4330 {
(318 . 31)(217 . 7)
4332 mpi_print(fp, a, 1 );
4333 fputc('\n', fp);
4334 }
4335
4336 /****************
4337 * Special function to get the low 8 bytes from an mpi.
4338 * This can be used as a keyid; KEYID is an 2 element array.
4339 * Return the low 4 bytes.
4340 */
4341 u32
4342 mpi_get_keyid( MPI a, u32 *keyid )
4343 {
4344 #if BYTES_PER_MPI_LIMB == 4
4345 if( keyid ) {
4346 keyid[0] = a->nlimbs >= 2? a->d[1] : 0;
4347 keyid[1] = a->nlimbs >= 1? a->d[0] : 0;
4348 }
4349 return a->nlimbs >= 1? a->d[0] : 0;
4350 #elif BYTES_PER_MPI_LIMB == 8
4351 if( keyid ) {
4352 keyid[0] = a->nlimbs? (u32)(a->d[0] >> 32) : 0;
4353 keyid[1] = a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
4354 }
4355 return a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
4356 #else
4357 #error Make this function work with other LIMB sizes
4358 #endif
4359 }
4360 */
4361
4362
4363 /****************
- B320709B57B3CF0C00BC98277B037494C62FED93FD99BCA0412EA633F8662844D35ED62990CBE1FC02A47DEE5795D3A7B6B401440F6E80A8A00243868815C06A
+ C35F9C1DD65BD4564AC028B876D7351CD30F72780AFD03FD6A764B0FCCFE57C10AE496D64407F04953364788FA2824759239CC598A44466537A379E57E0BAD8C
mpi/mpi-div.c
(1 . 34)(1 . 29)
4368 /* mpi-div.c - MPI functions
4369 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
4370 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4371 * Modified by No Such Labs. (C) 2015. See README.
4372 *
4373 * This file is part of GnuPG.
4374 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4375 * SHA256(gnupg-1.4.10.tar.gz):
4376 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4377 * (C) 1994-2005 Free Software Foundation, Inc.
4378 *
4379 * GnuPG is free software; you can redistribute it and/or modify
4380 * This program is free software: you can redistribute it and/or modify
4381 * it under the terms of the GNU General Public License as published by
4382 * the Free Software Foundation; either version 3 of the License, or
4383 * the Free Software Foundation, either version 3 of the License, or
4384 * (at your option) any later version.
4385 *
4386 * GnuPG is distributed in the hope that it will be useful,
4387 * This program is distributed in the hope that it will be useful,
4388 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4389 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4390 * GNU General Public License for more details.
4391 *
4392 * You should have received a copy of the GNU General Public License
4393 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4394 *
4395 * Note: This code is heavily based on the GNU MP Library.
4396 * Actually it's the same code with only minor changes in the
4397 * way the data is stored; this is to support the abstraction
4398 * of an optional secure memory allocation which may be used
4399 * to avoid revealing of sensitive data due to paging etc.
4400 * The GNU MP Library itself is published under the LGPL;
4401 * however I decided to publish this code under the plain GPL.
4402 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4403 */
4404
4405 #include <config.h>
4406 #include <stdio.h>
4407 #include <stdlib.h>
4408
4409 #include "knobs.h"
4410 #include "mpi-internal.h"
4411 #include "longlong.h"
4412
- F582DE56EE9BC1D4CF2EEA35BDABDCD61E0CC93DD186950709E32FC707D2F769669BAFDCFBF2AD074596BA474BF1E7AF5E29EA81CFF2316ACBFCD27A0F93F185
+ 6DFF8D166D0D34557BBAF7E739B83AEC2F73E2383424D08CE2D10C6A1609095381A27B8C38029950548942C3D4B5FAADCBE62322BC623154FA1911B3EAA3FE38
mpi/mpi-gcd.c
(1 . 25)(1 . 29)
4417 /* mpi-gcd.c - MPI functions
4418 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4419 * Modified by No Such Labs. (C) 2015. See README.
4420 *
4421 * This file is part of GnuPG.
4422 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4423 * SHA256(gnupg-1.4.10.tar.gz):
4424 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4425 * (C) 1994-2005 Free Software Foundation, Inc.
4426 *
4427 * GnuPG is free software; you can redistribute it and/or modify
4428 * This program is free software: you can redistribute it and/or modify
4429 * it under the terms of the GNU General Public License as published by
4430 * the Free Software Foundation; either version 3 of the License, or
4431 * the Free Software Foundation, either version 3 of the License, or
4432 * (at your option) any later version.
4433 *
4434 * GnuPG is distributed in the hope that it will be useful,
4435 * This program is distributed in the hope that it will be useful,
4436 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4437 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4438 * GNU General Public License for more details.
4439 *
4440 * You should have received a copy of the GNU General Public License
4441 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4442 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4443 */
4444
4445 #include <config.h>
4446 #include <stdio.h>
4447 #include <stdlib.h>
4448
4449 #include "knobs.h"
4450 #include "mpi-internal.h"
4451
4452 /****************
- FB06EA790BD2B2C18013B3FB51F05A5C1577F45FDD67644E7745C3373FA26FA90DE8F30FD9221E978BA9676423ED1C4C27C0407F22A50E10F216AE9BBF4AC3F3
+ 15E95347519C17744E8346A37975E5B482E833625862C1E01629E07D3E80CDBDEE590F6BCBED8214092D395979E38EF50CEFE58B2DC64472A2B3860BC374EE2D
mpi/mpih-add1.c
(1 . 34)(1 . 29)
4457 /* mpihelp-add_1.c - MPI helper functions
4458 * Copyright (C) 1994, 1996, 1997, 1998,
4459 * 2000 Free Software Foundation, Inc.
4460 * Modified by No Such Labs. (C) 2015. See README.
4461 *
4462 * This file is part of GnuPG.
4463 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4464 * SHA256(gnupg-1.4.10.tar.gz):
4465 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4466 * (C) 1994-2005 Free Software Foundation, Inc.
4467 *
4468 * GnuPG is free software; you can redistribute it and/or modify
4469 * This program is free software: you can redistribute it and/or modify
4470 * it under the terms of the GNU General Public License as published by
4471 * the Free Software Foundation; either version 3 of the License, or
4472 * the Free Software Foundation, either version 3 of the License, or
4473 * (at your option) any later version.
4474 *
4475 * GnuPG is distributed in the hope that it will be useful,
4476 * This program is distributed in the hope that it will be useful,
4477 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4478 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4479 * GNU General Public License for more details.
4480 *
4481 * You should have received a copy of the GNU General Public License
4482 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4483 *
4484 * Note: This code is heavily based on the GNU MP Library.
4485 * Actually it's the same code with only minor changes in the
4486 * way the data is stored; this is to support the abstraction
4487 * of an optional secure memory allocation which may be used
4488 * to avoid revealing of sensitive data due to paging etc.
4489 * The GNU MP Library itself is published under the LGPL;
4490 * however I decided to publish this code under the plain GPL.
4491 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4492 */
4493
4494 #include <config.h>
4495 #include <stdio.h>
4496 #include <stdlib.h>
4497
4498 #include "knobs.h"
4499 #include "mpi-internal.h"
4500 #include "longlong.h"
4501
- 88A21583524C37A7FEBB2EEDAF38F0942183A201EE8DF8B9E04A8098E892DD88B7F8566E40CC8BF042D5713E2F78886526CC23DE79C61463E7763685F280C37E
+ E0F453BECB6712C9A4C33BF2969CCCEFBF5097F29992A486D12726B509D90A3F2F91E53729FEB9C2F3B8452E5C2A2348B409CEEFF253ADEFE2E5A627E1B19CC1
mpi/mpih-cmp.c
(1 . 35)(1 . 29)
4506 /* mpihelp-sub.c - MPI helper functions
4507 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
4508 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4509 * Modified by No Such Labs. (C) 2015. See README.
4510 *
4511 * This file is part of GnuPG.
4512 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4513 * SHA256(gnupg-1.4.10.tar.gz):
4514 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4515 * (C) 1994-2005 Free Software Foundation, Inc.
4516 *
4517 * GnuPG is free software; you can redistribute it and/or modify
4518 * This program is free software: you can redistribute it and/or modify
4519 * it under the terms of the GNU General Public License as published by
4520 * the Free Software Foundation; either version 3 of the License, or
4521 * the Free Software Foundation, either version 3 of the License, or
4522 * (at your option) any later version.
4523 *
4524 * GnuPG is distributed in the hope that it will be useful,
4525 * This program is distributed in the hope that it will be useful,
4526 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4527 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4528 * GNU General Public License for more details.
4529 *
4530 * You should have received a copy of the GNU General Public License
4531 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4532 *
4533 * Note: This code is heavily based on the GNU MP Library.
4534 * Actually it's the same code with only minor changes in the
4535 * way the data is stored; this is to support the abstraction
4536 * of an optional secure memory allocation which may be used
4537 * to avoid revealing of sensitive data due to paging etc.
4538 * The GNU MP Library itself is published under the LGPL;
4539 * however I decided to publish this code under the plain GPL.
4540 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4541 */
4542
4543 #include <config.h>
4544 #include <stdio.h>
4545 #include <stdlib.h>
4546
4547 #include "knobs.h"
4548 #include "mpi-internal.h"
4549
4550 /****************
- AA4E2EFA1E53416AEDF9CBF7A73A00FBDE7A8266F532002DC046B0B995CF49D060496C45C74944EC3F41CF0DD441884FF6230260978FCBF227903EB7213B074A
+ 62BDE6DDF9FEECCD5C2AFB41FB0B86B32B558CB48D58107AE9AB1ED46C3769731C0804BD460565B85E731146C8D942E082EE12B69FCFFD1B973A08F79BCAE4D0
mpi/mpih-div.c
(1 . 34)(1 . 29)
4555 /* mpihelp-div.c - MPI helper functions
4556 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
4557 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4558 * Modified by No Such Labs. (C) 2015. See README.
4559 *
4560 * This file is part of GnuPG.
4561 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4562 * SHA256(gnupg-1.4.10.tar.gz):
4563 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4564 * (C) 1994-2005 Free Software Foundation, Inc.
4565 *
4566 * GnuPG is free software; you can redistribute it and/or modify
4567 * This program is free software: you can redistribute it and/or modify
4568 * it under the terms of the GNU General Public License as published by
4569 * the Free Software Foundation; either version 3 of the License, or
4570 * the Free Software Foundation, either version 3 of the License, or
4571 * (at your option) any later version.
4572 *
4573 * GnuPG is distributed in the hope that it will be useful,
4574 * This program is distributed in the hope that it will be useful,
4575 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4576 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4577 * GNU General Public License for more details.
4578 *
4579 * You should have received a copy of the GNU General Public License
4580 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4581 *
4582 * Note: This code is heavily based on the GNU MP Library.
4583 * Actually it's the same code with only minor changes in the
4584 * way the data is stored; this is to support the abstraction
4585 * of an optional secure memory allocation which may be used
4586 * to avoid revealing of sensitive data due to paging etc.
4587 * The GNU MP Library itself is published under the LGPL;
4588 * however I decided to publish this code under the plain GPL.
4589 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4590 */
4591
4592 #include <config.h>
4593 #include <stdio.h>
4594 #include <stdlib.h>
4595
4596 #include "knobs.h"
4597 #include "mpi-internal.h"
4598 #include "longlong.h"
4599
- 3222BFC241FA6104936CC585FDA392F220D88031FA0FDF460BB201A3AA7295E6D1DC75007BF53D2E501734D9FAAA31934EED944CE7452A6AA3AFCD3A333D3C13
+ 25E8EFCBAE822D6B21202C4E4D2A1D1D0370C3676AF7518EA81C8A59D87E0DF7CAF2B81E43F307EF8910BC63D4C482CC6F94794B73EA68C19E69391613405EBA
mpi/mpih-lshift.c
(1 . 33)(1 . 29)
4604 /* mpihelp-lshift.c - MPI helper functions
4605 * Copyright (C) 1994, 1996, 1998, 2001 Free Software Foundation, Inc.
4606 * Modified by No Such Labs. (C) 2015. See README.
4607 *
4608 * This file is part of GnuPG.
4609 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4610 * SHA256(gnupg-1.4.10.tar.gz):
4611 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4612 * (C) 1994-2005 Free Software Foundation, Inc.
4613 *
4614 * GnuPG is free software; you can redistribute it and/or modify
4615 * This program is free software: you can redistribute it and/or modify
4616 * it under the terms of the GNU General Public License as published by
4617 * the Free Software Foundation; either version 3 of the License, or
4618 * the Free Software Foundation, either version 3 of the License, or
4619 * (at your option) any later version.
4620 *
4621 * GnuPG is distributed in the hope that it will be useful,
4622 * This program is distributed in the hope that it will be useful,
4623 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4624 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4625 * GNU General Public License for more details.
4626 *
4627 * You should have received a copy of the GNU General Public License
4628 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4629 *
4630 * Note: This code is heavily based on the GNU MP Library.
4631 * Actually it's the same code with only minor changes in the
4632 * way the data is stored; this is to support the abstraction
4633 * of an optional secure memory allocation which may be used
4634 * to avoid revealing of sensitive data due to paging etc.
4635 * The GNU MP Library itself is published under the LGPL;
4636 * however I decided to publish this code under the plain GPL.
4637 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4638 */
4639
4640 #include <config.h>
4641 #include <stdio.h>
4642 #include <stdlib.h>
4643
4644 #include "knobs.h"
4645 #include "mpi-internal.h"
4646
4647 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
- 86B925ACDAEDFAAF9C7F7FF783DA4A049C62C8F63929BF288FDC8E4760DC9B451440ED5ED5F8549E8B2CCBD4F00175F068DE9DC337EEDFD8FAD8348D21F3ED13
+ E8D6C90380880315A6BF877BA13B073A93159645C447B67723CC6B76ECE8499C13758759085900049695BE381076A06880C6B1721EBAE6E36263ECCBC56260C5
mpi/mpih-mul1.c
(1 . 33)(1 . 29)
4652 /* mpihelp-mul_1.c - MPI helper functions
4653 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
4654 * Modified by No Such Labs. (C) 2015. See README.
4655 *
4656 * This file is part of GnuPG.
4657 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4658 * SHA256(gnupg-1.4.10.tar.gz):
4659 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4660 * (C) 1994-2005 Free Software Foundation, Inc.
4661 *
4662 * GnuPG is free software; you can redistribute it and/or modify
4663 * This program is free software: you can redistribute it and/or modify
4664 * it under the terms of the GNU General Public License as published by
4665 * the Free Software Foundation; either version 3 of the License, or
4666 * the Free Software Foundation, either version 3 of the License, or
4667 * (at your option) any later version.
4668 *
4669 * GnuPG is distributed in the hope that it will be useful,
4670 * This program is distributed in the hope that it will be useful,
4671 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4672 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4673 * GNU General Public License for more details.
4674 *
4675 * You should have received a copy of the GNU General Public License
4676 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4677 *
4678 * Note: This code is heavily based on the GNU MP Library.
4679 * Actually it's the same code with only minor changes in the
4680 * way the data is stored; this is to support the abstraction
4681 * of an optional secure memory allocation which may be used
4682 * to avoid revealing of sensitive data due to paging etc.
4683 * The GNU MP Library itself is published under the LGPL;
4684 * however I decided to publish this code under the plain GPL.
4685 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4686 */
4687
4688 #include <config.h>
4689 #include <stdio.h>
4690 #include <stdlib.h>
4691
4692 #include "knobs.h"
4693 #include "mpi-internal.h"
4694 #include "longlong.h"
4695
- 340744F79D1466A916FCA829C66F86915B808800BF3EBE2CCADABA1D5FD89EF5C5DB486C94B0F01ACE52F13D7A74784B68214499F5AC120AC8449FC9EB5C61C3
+ 95CD771C444012E1F8E329FC4A7687D1A0F5E3B2D0635C07D7C47913AF09D55040478FEF672766F5CCBF2FBBFF74FEA0B95F57D37BC4A3D0DCF3FD8C7F3288AB
mpi/mpih-mul2.c
(1 . 33)(1 . 29)
4700 /* mpihelp-mul_2.c - MPI helper functions
4701 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
4702 * Modified by No Such Labs. (C) 2015. See README.
4703 *
4704 * This file is part of GnuPG.
4705 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4706 * SHA256(gnupg-1.4.10.tar.gz):
4707 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4708 * (C) 1994-2005 Free Software Foundation, Inc.
4709 *
4710 * GnuPG is free software; you can redistribute it and/or modify
4711 * This program is free software: you can redistribute it and/or modify
4712 * it under the terms of the GNU General Public License as published by
4713 * the Free Software Foundation; either version 3 of the License, or
4714 * the Free Software Foundation, either version 3 of the License, or
4715 * (at your option) any later version.
4716 *
4717 * GnuPG is distributed in the hope that it will be useful,
4718 * This program is distributed in the hope that it will be useful,
4719 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4720 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4721 * GNU General Public License for more details.
4722 *
4723 * You should have received a copy of the GNU General Public License
4724 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4725 *
4726 * Note: This code is heavily based on the GNU MP Library.
4727 * Actually it's the same code with only minor changes in the
4728 * way the data is stored; this is to support the abstraction
4729 * of an optional secure memory allocation which may be used
4730 * to avoid revealing of sensitive data due to paging etc.
4731 * The GNU MP Library itself is published under the LGPL;
4732 * however I decided to publish this code under the plain GPL.
4733 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4734 */
4735
4736 #include <config.h>
4737 #include <stdio.h>
4738 #include <stdlib.h>
4739
4740 #include "knobs.h"
4741 #include "mpi-internal.h"
4742 #include "longlong.h"
4743
- 683F47357B0F57E3DC50AEFC32BDCD8C20E7A9A4C3DC48D3BA9E5715E12836B6CE53B8DFF653BDB86CDD197DAAB9AF7532DEF5BB06D861BDF48F4DC705AC6AA4
+ C86699C63F32A4627023A4AD8B89138FCBEF21E066E98E73C8F652B62F521C67110CEB48121EF5F7A586745328E8777B8170699E1417D70FB54849C5DFE88811
mpi/mpih-mul3.c
(1 . 33)(1 . 29)
4748 /* mpihelp-mul_3.c - MPI helper functions
4749 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
4750 * Modified by No Such Labs. (C) 2015. See README.
4751 *
4752 * This file is part of GnuPG.
4753 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4754 * SHA256(gnupg-1.4.10.tar.gz):
4755 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4756 * (C) 1994-2005 Free Software Foundation, Inc.
4757 *
4758 * GnuPG is free software; you can redistribute it and/or modify
4759 * This program is free software: you can redistribute it and/or modify
4760 * it under the terms of the GNU General Public License as published by
4761 * the Free Software Foundation; either version 3 of the License, or
4762 * the Free Software Foundation, either version 3 of the License, or
4763 * (at your option) any later version.
4764 *
4765 * GnuPG is distributed in the hope that it will be useful,
4766 * This program is distributed in the hope that it will be useful,
4767 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4768 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4769 * GNU General Public License for more details.
4770 *
4771 * You should have received a copy of the GNU General Public License
4772 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4773 *
4774 * Note: This code is heavily based on the GNU MP Library.
4775 * Actually it's the same code with only minor changes in the
4776 * way the data is stored; this is to support the abstraction
4777 * of an optional secure memory allocation which may be used
4778 * to avoid revealing of sensitive data due to paging etc.
4779 * The GNU MP Library itself is published under the LGPL;
4780 * however I decided to publish this code under the plain GPL.
4781 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4782 */
4783
4784 #include <config.h>
4785 #include <stdio.h>
4786 #include <stdlib.h>
4787
4788 #include "knobs.h"
4789 #include "mpi-internal.h"
4790 #include "longlong.h"
4791
- 2D6F3C1ECB3331CDFB54C9EFA53246CAC6A6DFA16465D2E354C6801974964229CB173E7AFF19C4C92E896B8C65CFBC6DA79EF03C20022772F5C299F1C3CBC063
+ 8D2390541B928FC4B9E92C17766530734CE64B823A3AFF6E648C0CFEEF6367A9FC18A0DE2754378B04DBD6072D862CECB447C372CEFAAD1D39D5D619B2FF6ABD
mpi/mpih-mul.c
(1 . 40)(1 . 34)
4796 /* mpihelp-mul.c - MPI helper functions
4797 * Copyright (C) 1994, 1996, 1998, 1999,
4798 * 2000 Free Software Foundation, Inc.
4799 * Modified by No Such Labs. (C) 2015. See README.
4800 *
4801 * This file is part of GnuPG.
4802 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4803 * SHA256(gnupg-1.4.10.tar.gz):
4804 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4805 * (C) 1994-2005 Free Software Foundation, Inc.
4806 *
4807 * GnuPG is free software; you can redistribute it and/or modify
4808 * This program is free software: you can redistribute it and/or modify
4809 * it under the terms of the GNU General Public License as published by
4810 * the Free Software Foundation; either version 3 of the License, or
4811 * the Free Software Foundation, either version 3 of the License, or
4812 * (at your option) any later version.
4813 *
4814 * GnuPG is distributed in the hope that it will be useful,
4815 * This program is distributed in the hope that it will be useful,
4816 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4817 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4818 * GNU General Public License for more details.
4819 *
4820 * You should have received a copy of the GNU General Public License
4821 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4822 *
4823 * Note: This code is heavily based on the GNU MP Library.
4824 * Actually it's the same code with only minor changes in the
4825 * way the data is stored; this is to support the abstraction
4826 * of an optional secure memory allocation which may be used
4827 * to avoid revealing of sensitive data due to paging etc.
4828 * The GNU MP Library itself is published under the LGPL;
4829 * however I decided to publish this code under the plain GPL.
4830 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4831 */
4832
4833 #include <config.h>
4834 #include <stdio.h>
4835 #include <stdlib.h>
4836 #include <string.h>
4837
4838 #include "knobs.h"
4839 #include "mpi-internal.h"
4840 #include "longlong.h"
4841
4842
4843
4844 #define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
4845 do { \
4846 if( (size) < KARATSUBA_THRESHOLD ) \
(52 . 8)(46 . 6)
4848 } while (0);
4849
4850
4851
4852
4853 /* Multiply the natural numbers u (pointed to by UP) and v (pointed to by VP),
4854 * both with SIZE limbs, and store the result at PRODP. 2 * SIZE limbs are
4855 * always stored. Return the most significant limb.
- B98CF2FB49B284C7FFDA191D6E1A336E87BC9D5C302753C04E704DE455793BD9736D6318E1C314FC8CF97BAEBC830EAE998C35382AFB2810126C1CC9BD18BDCE
+ ECA25CB1840CEF7D60FA2BC6ECB32660CFAD14E3A3A8AEEB11EC5A5EB2D702C972331351DA75C5C111B7C90075B1922DB5C475C246B11D7D6097E50538B230F8
mpi/mpih-rshift.c
(1 . 34)(1 . 29)
4860 /* mpih-rshift.c - MPI helper functions
4861 * Copyright (C) 1994, 1996, 1998, 1999,
4862 * 2000, 2001 Free Software Foundation, Inc.
4863 * Modified by No Such Labs. (C) 2015. See README.
4864 *
4865 * This file is part of GNUPG
4866 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4867 * SHA256(gnupg-1.4.10.tar.gz):
4868 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4869 * (C) 1994-2005 Free Software Foundation, Inc.
4870 *
4871 * GNUPG is free software; you can redistribute it and/or modify
4872 * This program is free software: you can redistribute it and/or modify
4873 * it under the terms of the GNU General Public License as published by
4874 * the Free Software Foundation; either version 3 of the License, or
4875 * the Free Software Foundation, either version 3 of the License, or
4876 * (at your option) any later version.
4877 *
4878 * GNUPG is distributed in the hope that it will be useful,
4879 * This program is distributed in the hope that it will be useful,
4880 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4881 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4882 * GNU General Public License for more details.
4883 *
4884 * You should have received a copy of the GNU General Public License
4885 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4886 *
4887 * Note: This code is heavily based on the GNU MP Library.
4888 * Actually it's the same code with only minor changes in the
4889 * way the data is stored; this is to support the abstraction
4890 * of an optional secure memory allocation which may be used
4891 * to avoid revealing of sensitive data due to paging etc.
4892 * The GNU MP Library itself is published under the LGPL;
4893 * however I decided to publish this code under the plain GPL.
4894 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4895 */
4896
4897 #include <config.h>
4898 #include <stdio.h>
4899 #include <stdlib.h>
4900
4901 #include "knobs.h"
4902 #include "mpi-internal.h"
4903
4904
- 1F021E754F091EAC1AB7B46306B00849F7160CFA7CD0CC8A6481020B6D42CB12058CD12AC9E2B1D7F730688FBE2D876374EC9D5BB7A5F9D66A42CC9259CF2539
+ A23C0420E5786F7ED38842DC31330EC3C7F5544566A434414B7D097F237969D37D3C9390D2CC393D58F011EC991959CB059758B5E66FFCEA2002F4597AC049CF
mpi/mpih-sub1.c
(1 . 33)(1 . 29)
4909 /* mpihelp-add_2.c - MPI helper functions
4910 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
4911 * Modified by No Such Labs. (C) 2015. See README.
4912 *
4913 * This file is part of GnuPG.
4914 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4915 * SHA256(gnupg-1.4.10.tar.gz):
4916 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4917 * (C) 1994-2005 Free Software Foundation, Inc.
4918 *
4919 * GnuPG is free software; you can redistribute it and/or modify
4920 * This program is free software: you can redistribute it and/or modify
4921 * it under the terms of the GNU General Public License as published by
4922 * the Free Software Foundation; either version 3 of the License, or
4923 * the Free Software Foundation, either version 3 of the License, or
4924 * (at your option) any later version.
4925 *
4926 * GnuPG is distributed in the hope that it will be useful,
4927 * This program is distributed in the hope that it will be useful,
4928 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4929 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4930 * GNU General Public License for more details.
4931 *
4932 * You should have received a copy of the GNU General Public License
4933 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4934 *
4935 * Note: This code is heavily based on the GNU MP Library.
4936 * Actually it's the same code with only minor changes in the
4937 * way the data is stored; this is to support the abstraction
4938 * of an optional secure memory allocation which may be used
4939 * to avoid revealing of sensitive data due to paging etc.
4940 * The GNU MP Library itself is published under the LGPL;
4941 * however I decided to publish this code under the plain GPL.
4942 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4943 */
4944
4945 #include <config.h>
4946 #include <stdio.h>
4947 #include <stdlib.h>
4948
4949 #include "knobs.h"
4950 #include "mpi-internal.h"
4951 #include "longlong.h"
4952
- 22B8E75D35ABC0449E048A2B18461B17D7EF5A6A00A56FE1A16BD89B526B8F6F19DEA196A258D6E3760F84B1124D7D40FA28D1B6C5BC4932BE11B9D91C7077EC
+ 8A4A177C130B437C9ED2E935A375E693B12A57B12B241660B5F715698B9926D82F68C0C74C450BEA2DC60888920BB04F9370BEDC8737D1EC375A307EB3D4A0A1
mpi/mpi-inline.c
(1 . 26)(1 . 30)
4957 /* mpi-inline.c
4958 * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
4959 * Modified by No Such Labs. (C) 2015. See README.
4960 *
4961 * This file is part of GnuPG.
4962 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
4963 * SHA256(gnupg-1.4.10.tar.gz):
4964 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
4965 * (C) 1994-2005 Free Software Foundation, Inc.
4966 *
4967 * GnuPG is free software; you can redistribute it and/or modify
4968 * This program is free software: you can redistribute it and/or modify
4969 * it under the terms of the GNU General Public License as published by
4970 * the Free Software Foundation; either version 3 of the License, or
4971 * the Free Software Foundation, either version 3 of the License, or
4972 * (at your option) any later version.
4973 *
4974 * GnuPG is distributed in the hope that it will be useful,
4975 * This program is distributed in the hope that it will be useful,
4976 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4977 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4978 * GNU General Public License for more details.
4979 *
4980 * You should have received a copy of the GNU General Public License
4981 * along with this program; if not, see <http://www.gnu.org/licenses/>.
4982 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4983 */
4984
4985 #include <config.h>
4986 #include <stdio.h>
4987 #include <stdlib.h>
4988
4989 #include "knobs.h"
4990
4991 /* put the inline functions as real functions into the lib */
4992 #define G10_MPI_INLINE_DECL
4993
- 66EDF48A07BB672B7D9329150436A40AB2F1628F1F289B4C52B2E4BDB987B9105F36C441FB21A141346406A675D34B6265A4A0BC00D3C4DE471F461D0ACC5765
+ 89B26071AE7D00A43324B0152330B04E9981DC9F81C0482E760C629C4FD056ED3125C7432155E7A44CADB0FF26C3EB6ABEF3EBACFCAC4781F628D315C59F3539
mpi/mpi-inv.c
(1 . 25)(1 . 29)
4998 /* mpi-inv.c - MPI functions
4999 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5000 * Modified by No Such Labs. (C) 2015. See README.
5001 *
5002 * This file is part of GnuPG.
5003 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5004 * SHA256(gnupg-1.4.10.tar.gz):
5005 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5006 * (C) 1994-2005 Free Software Foundation, Inc.
5007 *
5008 * GnuPG is free software; you can redistribute it and/or modify
5009 * This program is free software: you can redistribute it and/or modify
5010 * it under the terms of the GNU General Public License as published by
5011 * the Free Software Foundation; either version 3 of the License, or
5012 * the Free Software Foundation, either version 3 of the License, or
5013 * (at your option) any later version.
5014 *
5015 * GnuPG is distributed in the hope that it will be useful,
5016 * This program is distributed in the hope that it will be useful,
5017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5019 * GNU General Public License for more details.
5020 *
5021 * You should have received a copy of the GNU General Public License
5022 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5023 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5024 */
5025
5026 #include <config.h>
5027 #include <stdio.h>
5028 #include <stdlib.h>
5029
5030 #include "knobs.h"
5031 #include "mpi-internal.h"
5032
5033
- A87EBB2E2397F5903EAA0066A9ADF8F977BF7A67866CD181D0699B6D6A029880D86F349BE9CB9E6901D35B052BD871380E18AB19EFCF319C8A3662A93691856E
+ 770F4B4229521F5F780D90EAD019BB19AC247128A768D6EEF565DA48FADE1634FF195A94E39412973B08C01C55C410DB075D2BE44E393B8F343568B2B4B85CDD
mpi/mpi-mpow.c
(1 . 28)(1 . 33)
5038 /* mpi-mpow.c - MPI functions
5039 * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
5040 * Modified by No Such Labs. (C) 2015. See README.
5041 *
5042 * This file is part of GnuPG.
5043 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5044 * SHA256(gnupg-1.4.10.tar.gz):
5045 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5046 * (C) 1994-2005 Free Software Foundation, Inc.
5047 *
5048 * GnuPG is free software; you can redistribute it and/or modify
5049 * This program is free software: you can redistribute it and/or modify
5050 * it under the terms of the GNU General Public License as published by
5051 * the Free Software Foundation; either version 3 of the License, or
5052 * the Free Software Foundation, either version 3 of the License, or
5053 * (at your option) any later version.
5054 *
5055 * GnuPG is distributed in the hope that it will be useful,
5056 * This program is distributed in the hope that it will be useful,
5057 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5058 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5059 * GNU General Public License for more details.
5060 *
5061 * You should have received a copy of the GNU General Public License
5062 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5063 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5064 */
5065
5066 #include <config.h>
5067 #include <stdio.h>
5068 #include <stdlib.h>
5069 #include <assert.h>
5070
5071 #include "knobs.h"
5072 #include "mpi-internal.h"
5073 #include "longlong.h"
5074 #include <assert.h>
5075
5076
5077 static int
5078 build_index( MPI *exparray, int k, int i, int t )
- 8A56ADB14BCAC8D72E4454562A0455C241756EDE576D2CD4E8A42CFDFF5ABE7C803A5F1523945EE81D5A149B88D969739443D00165FDAAB7041BAC9BE10DC8CF
+ E59E2D292E0E80C84BBC7526FFB1D48CF9CE718840C0B6D6FF26E1BEE1A331E7EAA4F7002050D195AF9D7E915CE49CA6B4B9A43F7D4C0D74E9C6040B6B871BF6
mpi/mpi-mul.c
(1 . 34)(1 . 29)
5083 /* mpi-mul.c - MPI functions
5084 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
5085 * Copyright (C) 1998, 2001 Free Software Foundation, Inc.
5086 * Modified by No Such Labs. (C) 2015. See README.
5087 *
5088 * This file is part of GnuPG.
5089 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5090 * SHA256(gnupg-1.4.10.tar.gz):
5091 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5092 * (C) 1994-2005 Free Software Foundation, Inc.
5093 *
5094 * GnuPG is free software; you can redistribute it and/or modify
5095 * This program is free software: you can redistribute it and/or modify
5096 * it under the terms of the GNU General Public License as published by
5097 * the Free Software Foundation; either version 3 of the License, or
5098 * the Free Software Foundation, either version 3 of the License, or
5099 * (at your option) any later version.
5100 *
5101 * GnuPG is distributed in the hope that it will be useful,
5102 * This program is distributed in the hope that it will be useful,
5103 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5104 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5105 * GNU General Public License for more details.
5106 *
5107 * You should have received a copy of the GNU General Public License
5108 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5109 *
5110 * Note: This code is heavily based on the GNU MP Library.
5111 * Actually it's the same code with only minor changes in the
5112 * way the data is stored; this is to support the abstraction
5113 * of an optional secure memory allocation which may be used
5114 * to avoid revealing of sensitive data due to paging etc.
5115 * The GNU MP Library itself is published under the LGPL;
5116 * however I decided to publish this code under the plain GPL.
5117 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5118 */
5119
5120 #include <config.h>
5121 #include <stdio.h>
5122 #include <stdlib.h>
5123
5124 #include "knobs.h"
5125 #include "mpi-internal.h"
5126
5127
- 8341923461226EC55DE5B29209CC03051587DE11885CB49433FF4C0EBA2160798B7DC27573B9BC363EE0954A8FC08CBD21AF3F655A9C0BC8AA294A74F80EB2C9
+ 054BF70520A4B8936CE1E9A3176884AE01FA796177F57FEB9676BE0197E3D87F82A7074E19144553D603861B5AFE804808A10C0E59E6F649BE4435BF6055BA88
mpi/mpi-pow.c
(1 . 37)(1 . 34)
5132 /* mpi-pow.c - MPI functions
5133 * Copyright (C) 1994, 1996, 1998, 2000 Free Software Foundation, Inc.
5134 * Modified by No Such Labs. (C) 2015. See README.
5135 *
5136 * This file is part of GnuPG.
5137 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5138 * SHA256(gnupg-1.4.10.tar.gz):
5139 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5140 * (C) 1994-2005 Free Software Foundation, Inc.
5141 *
5142 * GnuPG is free software; you can redistribute it and/or modify
5143 * This program is free software: you can redistribute it and/or modify
5144 * it under the terms of the GNU General Public License as published by
5145 * the Free Software Foundation; either version 3 of the License, or
5146 * the Free Software Foundation, either version 3 of the License, or
5147 * (at your option) any later version.
5148 *
5149 * GnuPG is distributed in the hope that it will be useful,
5150 * This program is distributed in the hope that it will be useful,
5151 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5152 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5153 * GNU General Public License for more details.
5154 *
5155 * You should have received a copy of the GNU General Public License
5156 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5157 *
5158 * Note: This code is heavily based on the GNU MP Library.
5159 * Actually it's the same code with only minor changes in the
5160 * way the data is stored; this is to support the abstraction
5161 * of an optional secure memory allocation which may be used
5162 * to avoid revealing of sensitive data due to paging etc.
5163 * The GNU MP Library itself is published under the LGPL;
5164 * however I decided to publish this code under the plain GPL.
5165 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5166 */
5167
5168 #include <config.h>
5169 #include <stdio.h>
5170 #include <stdlib.h>
5171 #include <string.h>
5172 #include <assert.h>
5173
5174 #include "knobs.h"
5175 #include "mpi-internal.h"
5176 #include "longlong.h"
5177 #include <assert.h>
5178
5179
5180
5181 /****************
- AFFA0E93E6625CAD75CD10C454B493CBEBF061AECA3185E45B6571A26AE10F03947A1EF363C0898609F95CC737053E45A73926B22F14F4EC6A800410915D3FF9
+ A5515E663FE1096BC9E9187508E493A8992770E13039758663F0B5979F49AB422F7F5847B707007A6D53190493F5250C8963C147405DEFEE82BCA6037731B869
mpi/mpi-scan.c
(1 . 25)(1 . 29)
5186 /* mpi-scan.c - MPI functions
5187 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5188 * Modified by No Such Labs. (C) 2015. See README.
5189 *
5190 * This file is part of GnuPG.
5191 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5192 * SHA256(gnupg-1.4.10.tar.gz):
5193 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5194 * (C) 1994-2005 Free Software Foundation, Inc.
5195 *
5196 * GnuPG is free software; you can redistribute it and/or modify
5197 * This program is free software: you can redistribute it and/or modify
5198 * it under the terms of the GNU General Public License as published by
5199 * the Free Software Foundation; either version 3 of the License, or
5200 * the Free Software Foundation, either version 3 of the License, or
5201 * (at your option) any later version.
5202 *
5203 * GnuPG is distributed in the hope that it will be useful,
5204 * This program is distributed in the hope that it will be useful,
5205 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5206 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5207 * GNU General Public License for more details.
5208 *
5209 * You should have received a copy of the GNU General Public License
5210 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5211 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5212 */
5213
5214 #include <config.h>
5215
5216 #include <stdio.h>
5217 #include <stdlib.h>
5218
5219 #include "knobs.h"
5220 #include "mpi-internal.h"
5221 #include "longlong.h"
5222
- 757F8A9FFA7640843ABC7A20EE7F0460FAE4CB11A2928963C85399B7EA7ABA3332F5C1574E86DAB4BBA8384E5BF3F95161C1D1E15DB7B85BB96F369F1E67F6FA
+ 38480C0221F17670A5009ECE9021655C15EAE6C5C378BA516CDDCDD1C3179A647F1862B1CD92391A57F62313A208FAA2FBE2EBDF2584C6570500626CF5B926C1
mpi/mpiutil.c
(1 . 28)(1 . 31)
5227 /* mpiutil.ac - Utility functions for MPI
5228 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
5229 * Modified by No Such Labs. (C) 2015. See README.
5230 *
5231 * This file is part of GnuPG.
5232 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5233 * SHA256(gnupg-1.4.10.tar.gz):
5234 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5235 * (C) 1994-2005 Free Software Foundation, Inc.
5236 *
5237 * GnuPG is free software; you can redistribute it and/or modify
5238 * This program is free software: you can redistribute it and/or modify
5239 * it under the terms of the GNU General Public License as published by
5240 * the Free Software Foundation; either version 3 of the License, or
5241 * the Free Software Foundation, either version 3 of the License, or
5242 * (at your option) any later version.
5243 *
5244 * GnuPG is distributed in the hope that it will be useful,
5245 * This program is distributed in the hope that it will be useful,
5246 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5247 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5248 * GNU General Public License for more details.
5249 *
5250 * You should have received a copy of the GNU General Public License
5251 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5252 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5253 */
5254
5255 #include <config.h>
5256 #include <stdio.h>
5257 #include <stdlib.h>
5258 #include <string.h>
5259 #include <assert.h>
5260
5261 #include "knobs.h"
5262 #include "mpi.h"
5263 #include "mpi-internal.h"
5264 #include "memory.h"
- 6BE57F08EC92D8BB7FBA6E14DE060CA60D0655B3DAD55CCC31B8387B9A305361F208E05589F091F8A0F774D9830E43B015E81E5DDC16EC41C16B00A04A13F69F
+ 812488321DD4DD4E83CFC49F1FFD543231BFD8099880BF8106D7C5DEBF7E7FEC8B6E17F9B91EBC7CC7C772B06C03C6FFC176438BC3204953BDA7842F06EF43AE
mpi/README
(6 . 6)(6 . 18)
5269 SHA512(gnupg-1.4.10.tar.gz) :
5270 d037041d2e6882fd3b999500b5a7b42be2c224836afc358e1f8a2465c1b74473d518f185b7c324b2c8dec4ffb70e9e34a03c94d1a54cc55d297f40c9745f6e1b
5271
5272 DEMO:
5273
5274 1) make
5275 2) cd tests
5276 3) make
5277 4) ./test_mpi
5278 5) output is:
5279 37A063D056817668C7AA3418F29
5280 6) q: 'Waaaaaa, it barfed!'
5281 a: You are probably using GCC 5 or LLVM. Stop.
5282
5283
5284 CHANGES FROM ORIGINAL:
5285
5286 1) Everything pertaining to Automake was nuked, and the earth where it stood -
(16 . 7)(28 . 7)
5288 another project. This will turn up in 'bin'.
5289
5290 Among other things, this now means that all KNOBS now reside in a
5291 MANUALLY-controlled 'config.h' found in 'include'. If you are building
5292 MANUALLY-controlled 'knobs.h' found in 'include'. If you are building
5293 on some very peculiar unix, please read it and adjust as appropriate.
5294 It contains ONLY those knobs which actually pertain to the code.
5295
(41 . 7)(53 . 7)
5297 don't need'em in their source code.
5298
5299 4) Other code has been altered solely to the extent required by items
5300 (1) and (2).
5301 (1), (2), and (3).
5302
5303 Cruft which appears in dead #ifdefs may be removed in the future.
5304 Don't get comfortable with it being there.
(55 . 3)(67 . 20)
5306
5307 7) The original code was distributed under GPL 3, which may apply on
5308 your planet and is therefore included. (See COPYING.)
5309
5310 ----------
5311 UPDATE #1:
5312 ----------
5313
5314 1) Abolished the logging subsystem inherited from GPG.
5315
5316 2) Abolished the I/O buffering subsystem, from same.
5317
5318 3) Eliminated all #ifdef blocks pertaining to RiscOS.
5319
5320 4) config.h is now knobs.h and is considerably shorter
5321 on account of there now being a great many fewer knobs.
5322
5323 5) Eliminated certain blocks of dead code.
5324
5325 6) Inserted notice of modifications as specified in GPL-3
- A0B28117315BD9560BE404C97E44252316FD19FF9CBC762BF5D46235034846155D5058E22A73D7010F78CF7442BA6624E2417A719FFCBE2F8A163090706E069C
+ 914398E87EDAF3B4ED8010EC6795C55F1A46B7C112D8DF2A28B9B73C4A786AB7335A662B097522FCF79695B5DBEE04C7AD8F2C8E70CAECA39C40430B7BC2FEB8
mpi/secmem.c
(1 . 24)(1 . 27)
5330 /* secmem.c - memory allocation from a secure heap
5331 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5332 * 2007 Free Software Foundation, Inc.
5333 * Modified by No Such Labs. (C) 2015. See README.
5334 *
5335 * This file is part of GnuPG.
5336 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5337 * SHA256(gnupg-1.4.10.tar.gz):
5338 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5339 * (C) 1994-2005 Free Software Foundation, Inc.
5340 *
5341 * GnuPG is free software; you can redistribute it and/or modify
5342 * This program is free software: you can redistribute it and/or modify
5343 * it under the terms of the GNU General Public License as published by
5344 * the Free Software Foundation; either version 3 of the License, or
5345 * the Free Software Foundation, either version 3 of the License, or
5346 * (at your option) any later version.
5347 *
5348 * GnuPG is distributed in the hope that it will be useful,
5349 * This program is distributed in the hope that it will be useful,
5350 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5351 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5352 * GNU General Public License for more details.
5353 *
5354 * You should have received a copy of the GNU General Public License
5355 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5356 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5357 */
5358
5359 #include <config.h>
5360 #include "knobs.h"
5361
5362 #include <stdio.h>
5363 #include <stdlib.h>
5364 #include <string.h>
(92 . 9)(95 . 7)
5366 {
5367 if (!no_warning)
5368 {
5369 log_info(_("WARNING: using insecure memory!\n"));
5370 log_info(_("please see http://www.gnupg.org/faq.html"
5371 " for more information\n"));
5372 log_info("WARNING: using insecure memory!\n");
5373 }
5374 }
5375
(202 . 11)(203 . 6)
5377 /* It does not make sense to print such a warning, given the fact that
5378 * this whole Windows !@#$% and their user base are inherently insecure
5379 */
5380 #elif defined (__riscos__)
5381 /* no virtual memory on RISC OS, so no pages are swapped to disc,
5382 * besides we don't have mmap, so we don't use it! ;-)
5383 * But don't complain, as explained above.
5384 */
5385 #else
5386 log_info("Please note that you don't have secure memory on this system\n");
5387 #endif
(313 . 14)(309 . 11)
5389 secmem_init( size_t n )
5390 {
5391 if( !n ) {
5392 #ifndef __riscos__
5393 #ifdef USE_CAPABILITIES
5394 /* drop all capabilities */
5395 cap_set_proc( cap_from_text("all-eip") );
5396
5397 #elif !defined(HAVE_DOSISH_SYSTEM)
5398 uid_t uid;
5399
5400 disable_secmem=1;
5401 uid = getuid();
5402 if( uid != geteuid() ) {
(328 . 7)(321 . 6)
5404 log_fatal("failed to drop setuid\n" );
5405 }
5406 #endif
5407 #endif /* !__riscos__ */
5408 }
5409 else {
5410 if( n < DEFAULT_POOLSIZE )
(351 . 8)(343 . 8)
5412
5413 if( !pool_okay ) {
5414 log_info(
5415 _("operation is not possible without initialized secure memory\n"));
5416 log_info(_("(you may have used the wrong program for this task)\n"));
5417 "operation is not possible without initialized secure memory\n");
5418 log_info("(you may have used the wrong program for this task)\n");
5419 exit(2);
5420 }
5421 if( show_warning && !suspend_warning ) {
-
+ B063BF6E022989224FA35D648E8FC1CEF134C07C8602D502F83A2FDBA824707919FC09460552C52E6EE533625E949A4F83E733182050B728CE64E92EF8C26AD8
mpi/tests/Makefile
(0 . 0)(1 . 24)
5426 PROGRAM = test_mpi
5427
5428 CXX = gcc
5429 OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
5430 FLAGS = -g -Wall
5431 INCLUDE = -I ../include
5432 MPI = ../bin/mpi.a
5433 LIBS := $(MPI)
5434
5435 .SUFFIXES: .o .c
5436
5437 .c.o:
5438 $(CXX) $(FLAGS) $(INCLUDE) -c $< -o $@
5439
5440 all: $(PROGRAM)
5441
5442 $(PROGRAM): $(OBJECTS)
5443 $(CXX) $(FLAGS) $(INCLUDE) -o $(PROGRAM) $(OBJECTS) $(LIBS)
5444
5445 clean :
5446 rm -rf nul core *flymake* *.o $(PROGRAM) *~ bin obj
5447
5448 check-syntax:
5449 $(CXX) -c $(FLAGS) $(INCLUDE) -o nul -Wall -S $(CHK_SOURCES)
-
+ 5F400376F8290AE83062C457BEDFDE1FB7A2C2E31EFE956ADA2E4DC4EAAF6871428B74BE1193D9268EE74CF454BDC3DF5C4C4A88E6942D216DDB5A0395F48099
mpi/tests/test_mpi.c
(0 . 0)(1 . 39)
5454 #include "mpi.h"
5455 #include <stdlib.h>
5456
5457 void err(char *msg)
5458 {
5459 fprintf(stderr, "%s\n", msg);
5460 exit(1);
5461 }
5462
5463 void terpri(FILE *fp)
5464 {
5465 fprintf(fp, "\n");
5466 }
5467
5468 int main(int ac, char **av)
5469 {
5470 MPI a, b, y;
5471 int r;
5472
5473 r = secmem_init(1000);
5474 if (r==0) err("secmem init");
5475
5476 a = mpi_alloc_secure(0);
5477 b = mpi_alloc_secure(0);
5478 y = mpi_alloc_secure(0);
5479 mpi_fromstr(a, "0x1B0B206C488601");
5480 mpi_fromstr(b, "0x20E92FE28E1929");
5481 mpi_mul(y, a, b);
5482 mpi_free(a);
5483 mpi_free(b);
5484
5485 mpi_print(stdout, y, 1);
5486 mpi_free(y);
5487
5488 terpri(stdout);
5489 secmem_term();
5490
5491 return 0;
5492 }
- FB984A326A9BCDA1A4CBC05EE279E55CFEFCF157393D2F66405760B256395C3A73F1F41EBFC335722022EA04C79F6E02AB3179ECC9A66E037DD7A106572B4924
+
mpi/udiv-w-sdiv.c
(1 . 132)(0 . 0)
5497 /* mpihelp_udiv_w_sdiv -- implement udiv_qrnnd on machines with only signed
5498 * division.
5499 * Copyright (C) 1992, 1994, 1996, 1998 Free Software Foundation, Inc.
5500 * Contributed by Peter L. Montgomery.
5501 *
5502 * This file is part of GnuPG.
5503 *
5504 * GnuPG is free software; you can redistribute it and/or modify
5505 * it under the terms of the GNU General Public License as published by
5506 * the Free Software Foundation; either version 3 of the License, or
5507 * (at your option) any later version.
5508 *
5509 * GnuPG is distributed in the hope that it will be useful,
5510 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5511 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5512 * GNU General Public License for more details.
5513 *
5514 * You should have received a copy of the GNU General Public License
5515 * along with this program; if not, see <http://www.gnu.org/licenses/>.
5516 */
5517
5518 #include <config.h>
5519 #include <stdio.h>
5520 #include <stdlib.h>
5521 #include "mpi-internal.h"
5522 #include "longlong.h"
5523
5524
5525 #if 0 /* not yet ported to MPI */
5526
5527 mpi_limb_t
5528 mpihelp_udiv_w_sdiv( mpi_limp_t *rp,
5529 mpi_limp_t *a1,
5530 mpi_limp_t *a0,
5531 mpi_limp_t *d )
5532 {
5533 mp_limb_t q, r;
5534 mp_limb_t c0, c1, b1;
5535
5536 if ((mpi_limb_signed_t) d >= 0)
5537 {
5538 if (a1 < d - a1 - (a0 >> (BITS_PER_MP_LIMB - 1)))
5539 {
5540 /* dividend, divisor, and quotient are nonnegative */
5541 sdiv_qrnnd (q, r, a1, a0, d);
5542 }
5543 else
5544 {
5545 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
5546 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (BITS_PER_MP_LIMB - 1));
5547 /* Divide (c1*2^32 + c0) by d */
5548 sdiv_qrnnd (q, r, c1, c0, d);
5549 /* Add 2^31 to quotient */
5550 q += (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1);
5551 }
5552 }
5553 else
5554 {
5555 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
5556 c1 = a1 >> 1; /* A/2 */
5557 c0 = (a1 << (BITS_PER_MP_LIMB - 1)) + (a0 >> 1);
5558
5559 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
5560 {
5561 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
5562
5563 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
5564 if ((d & 1) != 0)
5565 {
5566 if (r >= q)
5567 r = r - q;
5568 else if (q - r <= d)
5569 {
5570 r = r - q + d;
5571 q--;
5572 }
5573 else
5574 {
5575 r = r - q + 2*d;
5576 q -= 2;
5577 }
5578 }
5579 }
5580 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
5581 {
5582 c1 = (b1 - 1) - c1;
5583 c0 = ~c0; /* logical NOT */
5584
5585 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
5586
5587 q = ~q; /* (A/2)/b1 */
5588 r = (b1 - 1) - r;
5589
5590 r = 2*r + (a0 & 1); /* A/(2*b1) */
5591
5592 if ((d & 1) != 0)
5593 {
5594 if (r >= q)
5595 r = r - q;
5596 else if (q - r <= d)
5597 {
5598 r = r - q + d;
5599 q--;
5600 }
5601 else
5602 {
5603 r = r - q + 2*d;
5604 q -= 2;
5605 }
5606 }
5607 }
5608 else /* Implies c1 = b1 */
5609 { /* Hence a1 = d - 1 = 2*b1 - 1 */
5610 if (a0 >= -d)
5611 {
5612 q = -1;
5613 r = a0 + d;
5614 }
5615 else
5616 {
5617 q = -2;
5618 r = a0 + 2*d;
5619 }
5620 }
5621 }
5622
5623 *rp = r;
5624 return q;
5625 }
5626
5627 #endif
5628