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