xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/readerwriter.h (revision fc1f8641b753c32aee31843517cf9b2c946d7bee)
12232f800Sagc /*-
22232f800Sagc  * Copyright (c) 2009 The NetBSD Foundation, Inc.
32232f800Sagc  * All rights reserved.
42232f800Sagc  *
52232f800Sagc  * This code is derived from software contributed to The NetBSD Foundation
62232f800Sagc  * by Alistair Crooks (agc@NetBSD.org)
72232f800Sagc  *
82232f800Sagc  * Redistribution and use in source and binary forms, with or without
92232f800Sagc  * modification, are permitted provided that the following conditions
102232f800Sagc  * are met:
112232f800Sagc  * 1. Redistributions of source code must retain the above copyright
122232f800Sagc  *    notice, this list of conditions and the following disclaimer.
132232f800Sagc  * 2. Redistributions in binary form must reproduce the above copyright
142232f800Sagc  *    notice, this list of conditions and the following disclaimer in the
152232f800Sagc  *    documentation and/or other materials provided with the distribution.
162232f800Sagc  *
172232f800Sagc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
182232f800Sagc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
192232f800Sagc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
202232f800Sagc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
212232f800Sagc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
222232f800Sagc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
232232f800Sagc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
242232f800Sagc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
252232f800Sagc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
262232f800Sagc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
272232f800Sagc  * POSSIBILITY OF SUCH DAMAGE.
282232f800Sagc  */
2993bf6008Sagc /*
3093bf6008Sagc  * Copyright (c) 2005-2008 Nominet UK (www.nic.uk)
3193bf6008Sagc  * All rights reserved.
3293bf6008Sagc  * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted
3393bf6008Sagc  * their moral rights under the UK Copyright Design and Patents Act 1988 to
3493bf6008Sagc  * be recorded as the authors of this copyright work.
3593bf6008Sagc  *
3693bf6008Sagc  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
3793bf6008Sagc  * use this file except in compliance with the License.
3893bf6008Sagc  *
3993bf6008Sagc  * You may obtain a copy of the License at
4093bf6008Sagc  *     http://www.apache.org/licenses/LICENSE-2.0
4193bf6008Sagc  *
4293bf6008Sagc  * Unless required by applicable law or agreed to in writing, software
4393bf6008Sagc  * distributed under the License is distributed on an "AS IS" BASIS,
4493bf6008Sagc  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4593bf6008Sagc  *
4693bf6008Sagc  * See the License for the specific language governing permissions and
4793bf6008Sagc  * limitations under the License.
4893bf6008Sagc  */
4993bf6008Sagc 
504b3a3e18Sagc #ifndef READERWRITER_H_
514b3a3e18Sagc #define READERWRITER_H_
5293bf6008Sagc 
5393bf6008Sagc #include "create.h"
5493bf6008Sagc 
5593bf6008Sagc #include "memory.h"
5693bf6008Sagc 
5757324b9fSagc /* if this is defined, we'll use mmap in preference to file ops */
5893bf6008Sagc #define USE_MMAP_FOR_FILES      1
5993bf6008Sagc 
60*fc1f8641Sagc void pgp_reader_set_fd(pgp_stream_t *, int);
61*fc1f8641Sagc void pgp_reader_set_mmap(pgp_stream_t *, int);
62*fc1f8641Sagc void pgp_reader_set_memory(pgp_stream_t *, const void *, size_t);
6393bf6008Sagc 
6493bf6008Sagc /* Do a sum mod 65536 of all bytes read (as needed for secret keys) */
65*fc1f8641Sagc void pgp_reader_push_sum16(pgp_stream_t *);
66*fc1f8641Sagc uint16_t pgp_reader_pop_sum16(pgp_stream_t *);
6793bf6008Sagc 
68*fc1f8641Sagc void pgp_reader_push_se_ip_data(pgp_stream_t *, pgp_crypt_t *,
69*fc1f8641Sagc 				pgp_region_t *);
70*fc1f8641Sagc void pgp_reader_pop_se_ip_data(pgp_stream_t *);
7193bf6008Sagc 
7293bf6008Sagc /* */
73*fc1f8641Sagc unsigned pgp_write_mdc(pgp_output_t *, const uint8_t *);
74*fc1f8641Sagc unsigned pgp_write_se_ip_pktset(pgp_output_t *, const uint8_t *,
75b15ec256Sagc 		       const unsigned,
76*fc1f8641Sagc 		       pgp_crypt_t *);
77*fc1f8641Sagc void pgp_push_enc_crypt(pgp_output_t *, pgp_crypt_t *);
78*fc1f8641Sagc int pgp_push_enc_se_ip(pgp_output_t *, const pgp_key_t *, const char *);
7993bf6008Sagc 
804b3a3e18Sagc /* Secret Key checksum */
81*fc1f8641Sagc void pgp_push_checksum_writer(pgp_output_t *, pgp_seckey_t *);
82*fc1f8641Sagc unsigned pgp_pop_skey_checksum_writer(pgp_output_t *);
8393bf6008Sagc 
8493bf6008Sagc 
8593bf6008Sagc /* memory writing */
86*fc1f8641Sagc void pgp_setup_memory_write(pgp_output_t **, pgp_memory_t **, size_t);
87*fc1f8641Sagc void pgp_teardown_memory_write(pgp_output_t *, pgp_memory_t *);
8893bf6008Sagc 
8993bf6008Sagc /* memory reading */
90*fc1f8641Sagc void pgp_setup_memory_read(pgp_io_t *,
91*fc1f8641Sagc 				pgp_stream_t **,
92*fc1f8641Sagc 				pgp_memory_t *,
9393bf6008Sagc 				void *,
94*fc1f8641Sagc 				pgp_cb_ret_t callback(const pgp_packet_t *,
95*fc1f8641Sagc 					pgp_cbdata_t *),
96d21b929eSagc 				unsigned);
97*fc1f8641Sagc void pgp_teardown_memory_read(pgp_stream_t *, pgp_memory_t *);
9893bf6008Sagc 
9993bf6008Sagc /* file writing */
100*fc1f8641Sagc int pgp_setup_file_write(pgp_output_t **, const char *, unsigned);
101*fc1f8641Sagc void pgp_teardown_file_write(pgp_output_t *, int);
10293bf6008Sagc 
10393bf6008Sagc /* file appending */
104*fc1f8641Sagc int pgp_setup_file_append(pgp_output_t **, const char *);
105*fc1f8641Sagc void pgp_teardown_file_append(pgp_output_t *, int);
10693bf6008Sagc 
10793bf6008Sagc /* file reading */
108*fc1f8641Sagc int pgp_setup_file_read(pgp_io_t *,
109*fc1f8641Sagc 			pgp_stream_t **,
110d21b929eSagc 			const char *,
111d21b929eSagc 			void *,
112*fc1f8641Sagc 			pgp_cb_ret_t callback(const pgp_packet_t *,
113*fc1f8641Sagc 		    			pgp_cbdata_t *),
1144b3a3e18Sagc 			unsigned);
115*fc1f8641Sagc void pgp_teardown_file_read(pgp_stream_t *, int);
11693bf6008Sagc 
117*fc1f8641Sagc unsigned pgp_reader_set_accumulate(pgp_stream_t *, unsigned);
11893bf6008Sagc 
11993bf6008Sagc /* useful callbacks */
120*fc1f8641Sagc pgp_cb_ret_t pgp_litdata_cb(const pgp_packet_t *, pgp_cbdata_t *);
121*fc1f8641Sagc pgp_cb_ret_t pgp_pk_sesskey_cb(const pgp_packet_t *, pgp_cbdata_t *);
122*fc1f8641Sagc pgp_cb_ret_t pgp_get_seckey_cb(const pgp_packet_t *, pgp_cbdata_t *);
12393bf6008Sagc 
124*fc1f8641Sagc int pgp_getpassphrase(void *, char *, size_t);
12593bf6008Sagc 
1264b3a3e18Sagc #endif /* READERWRITER_H_ */
127