1*ebfedea0SLionel Sambuc /*- 2*ebfedea0SLionel Sambuc * Copyright (c) 2009 The NetBSD Foundation, Inc. 3*ebfedea0SLionel Sambuc * All rights reserved. 4*ebfedea0SLionel Sambuc * 5*ebfedea0SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation 6*ebfedea0SLionel Sambuc * by Alistair Crooks (agc@NetBSD.org) 7*ebfedea0SLionel Sambuc * 8*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without 9*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions 10*ebfedea0SLionel Sambuc * are met: 11*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 12*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer. 13*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 14*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 15*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution. 16*ebfedea0SLionel Sambuc * 17*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18*ebfedea0SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19*ebfedea0SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20*ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21*ebfedea0SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*ebfedea0SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*ebfedea0SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*ebfedea0SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*ebfedea0SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*ebfedea0SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*ebfedea0SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE. 28*ebfedea0SLionel Sambuc */ 29*ebfedea0SLionel Sambuc /* 30*ebfedea0SLionel Sambuc * Copyright (c) 2005-2008 Nominet UK (www.nic.uk) 31*ebfedea0SLionel Sambuc * All rights reserved. 32*ebfedea0SLionel Sambuc * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted 33*ebfedea0SLionel Sambuc * their moral rights under the UK Copyright Design and Patents Act 1988 to 34*ebfedea0SLionel Sambuc * be recorded as the authors of this copyright work. 35*ebfedea0SLionel Sambuc * 36*ebfedea0SLionel Sambuc * Licensed under the Apache License, Version 2.0 (the "License"); you may not 37*ebfedea0SLionel Sambuc * use this file except in compliance with the License. 38*ebfedea0SLionel Sambuc * 39*ebfedea0SLionel Sambuc * You may obtain a copy of the License at 40*ebfedea0SLionel Sambuc * http://www.apache.org/licenses/LICENSE-2.0 41*ebfedea0SLionel Sambuc * 42*ebfedea0SLionel Sambuc * Unless required by applicable law or agreed to in writing, software 43*ebfedea0SLionel Sambuc * distributed under the License is distributed on an "AS IS" BASIS, 44*ebfedea0SLionel Sambuc * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 45*ebfedea0SLionel Sambuc * 46*ebfedea0SLionel Sambuc * See the License for the specific language governing permissions and 47*ebfedea0SLionel Sambuc * limitations under the License. 48*ebfedea0SLionel Sambuc */ 49*ebfedea0SLionel Sambuc 50*ebfedea0SLionel Sambuc #ifndef READERWRITER_H_ 51*ebfedea0SLionel Sambuc #define READERWRITER_H_ 52*ebfedea0SLionel Sambuc 53*ebfedea0SLionel Sambuc #include "create.h" 54*ebfedea0SLionel Sambuc 55*ebfedea0SLionel Sambuc #include "memory.h" 56*ebfedea0SLionel Sambuc 57*ebfedea0SLionel Sambuc /* if this is defined, we'll use mmap in preference to file ops */ 58*ebfedea0SLionel Sambuc #define USE_MMAP_FOR_FILES 1 59*ebfedea0SLionel Sambuc 60*ebfedea0SLionel Sambuc void pgp_reader_set_fd(pgp_stream_t *, int); 61*ebfedea0SLionel Sambuc void pgp_reader_set_mmap(pgp_stream_t *, int); 62*ebfedea0SLionel Sambuc void pgp_reader_set_memory(pgp_stream_t *, const void *, size_t); 63*ebfedea0SLionel Sambuc 64*ebfedea0SLionel Sambuc /* Do a sum mod 65536 of all bytes read (as needed for secret keys) */ 65*ebfedea0SLionel Sambuc void pgp_reader_push_sum16(pgp_stream_t *); 66*ebfedea0SLionel Sambuc uint16_t pgp_reader_pop_sum16(pgp_stream_t *); 67*ebfedea0SLionel Sambuc 68*ebfedea0SLionel Sambuc void pgp_reader_push_se_ip_data(pgp_stream_t *, pgp_crypt_t *, 69*ebfedea0SLionel Sambuc pgp_region_t *); 70*ebfedea0SLionel Sambuc void pgp_reader_pop_se_ip_data(pgp_stream_t *); 71*ebfedea0SLionel Sambuc 72*ebfedea0SLionel Sambuc /* */ 73*ebfedea0SLionel Sambuc unsigned pgp_write_mdc(pgp_output_t *, const uint8_t *); 74*ebfedea0SLionel Sambuc unsigned pgp_write_se_ip_pktset(pgp_output_t *, const uint8_t *, 75*ebfedea0SLionel Sambuc const unsigned, 76*ebfedea0SLionel Sambuc pgp_crypt_t *); 77*ebfedea0SLionel Sambuc void pgp_push_enc_crypt(pgp_output_t *, pgp_crypt_t *); 78*ebfedea0SLionel Sambuc int pgp_push_enc_se_ip(pgp_output_t *, const pgp_key_t *, const char *); 79*ebfedea0SLionel Sambuc 80*ebfedea0SLionel Sambuc /* Secret Key checksum */ 81*ebfedea0SLionel Sambuc void pgp_push_checksum_writer(pgp_output_t *, pgp_seckey_t *); 82*ebfedea0SLionel Sambuc unsigned pgp_pop_skey_checksum_writer(pgp_output_t *); 83*ebfedea0SLionel Sambuc 84*ebfedea0SLionel Sambuc 85*ebfedea0SLionel Sambuc /* memory writing */ 86*ebfedea0SLionel Sambuc void pgp_setup_memory_write(pgp_output_t **, pgp_memory_t **, size_t); 87*ebfedea0SLionel Sambuc void pgp_teardown_memory_write(pgp_output_t *, pgp_memory_t *); 88*ebfedea0SLionel Sambuc 89*ebfedea0SLionel Sambuc /* memory reading */ 90*ebfedea0SLionel Sambuc void pgp_setup_memory_read(pgp_io_t *, 91*ebfedea0SLionel Sambuc pgp_stream_t **, 92*ebfedea0SLionel Sambuc pgp_memory_t *, 93*ebfedea0SLionel Sambuc void *, 94*ebfedea0SLionel Sambuc pgp_cb_ret_t callback(const pgp_packet_t *, 95*ebfedea0SLionel Sambuc pgp_cbdata_t *), 96*ebfedea0SLionel Sambuc unsigned); 97*ebfedea0SLionel Sambuc void pgp_teardown_memory_read(pgp_stream_t *, pgp_memory_t *); 98*ebfedea0SLionel Sambuc 99*ebfedea0SLionel Sambuc /* file writing */ 100*ebfedea0SLionel Sambuc int pgp_setup_file_write(pgp_output_t **, const char *, unsigned); 101*ebfedea0SLionel Sambuc void pgp_teardown_file_write(pgp_output_t *, int); 102*ebfedea0SLionel Sambuc 103*ebfedea0SLionel Sambuc /* file appending */ 104*ebfedea0SLionel Sambuc int pgp_setup_file_append(pgp_output_t **, const char *); 105*ebfedea0SLionel Sambuc void pgp_teardown_file_append(pgp_output_t *, int); 106*ebfedea0SLionel Sambuc 107*ebfedea0SLionel Sambuc /* file reading */ 108*ebfedea0SLionel Sambuc int pgp_setup_file_read(pgp_io_t *, 109*ebfedea0SLionel Sambuc pgp_stream_t **, 110*ebfedea0SLionel Sambuc const char *, 111*ebfedea0SLionel Sambuc void *, 112*ebfedea0SLionel Sambuc pgp_cb_ret_t callback(const pgp_packet_t *, 113*ebfedea0SLionel Sambuc pgp_cbdata_t *), 114*ebfedea0SLionel Sambuc unsigned); 115*ebfedea0SLionel Sambuc void pgp_teardown_file_read(pgp_stream_t *, int); 116*ebfedea0SLionel Sambuc 117*ebfedea0SLionel Sambuc unsigned pgp_reader_set_accumulate(pgp_stream_t *, unsigned); 118*ebfedea0SLionel Sambuc 119*ebfedea0SLionel Sambuc /* useful callbacks */ 120*ebfedea0SLionel Sambuc pgp_cb_ret_t pgp_litdata_cb(const pgp_packet_t *, pgp_cbdata_t *); 121*ebfedea0SLionel Sambuc pgp_cb_ret_t pgp_pk_sesskey_cb(const pgp_packet_t *, pgp_cbdata_t *); 122*ebfedea0SLionel Sambuc pgp_cb_ret_t pgp_get_seckey_cb(const pgp_packet_t *, pgp_cbdata_t *); 123*ebfedea0SLionel Sambuc 124*ebfedea0SLionel Sambuc int pgp_getpassphrase(void *, char *, size_t); 125*ebfedea0SLionel Sambuc 126*ebfedea0SLionel Sambuc #endif /* READERWRITER_H_ */ 127