xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/signature.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 
5093bf6008Sagc /** \file
5193bf6008Sagc  */
5293bf6008Sagc 
534b3a3e18Sagc #ifndef SIGNATURE_H_
544b3a3e18Sagc #define SIGNATURE_H_
5593bf6008Sagc 
56de7c94ffSagc #include <sys/types.h>
57de7c94ffSagc 
58de7c94ffSagc #include <inttypes.h>
59de7c94ffSagc 
6093bf6008Sagc #include "packet.h"
6193bf6008Sagc #include "create.h"
624b3a3e18Sagc #include "memory.h"
6393bf6008Sagc 
64*fc1f8641Sagc typedef struct pgp_create_sig_t	 pgp_create_sig_t;
6593bf6008Sagc 
66*fc1f8641Sagc pgp_create_sig_t *pgp_create_sig_new(void);
67*fc1f8641Sagc void pgp_create_sig_delete(pgp_create_sig_t *);
6893bf6008Sagc 
69*fc1f8641Sagc unsigned pgp_check_useridcert_sig(const pgp_pubkey_t *,
70d427c17dSagc 			  const uint8_t *,
71*fc1f8641Sagc 			  const pgp_sig_t *,
72*fc1f8641Sagc 			  const pgp_pubkey_t *,
73b15ec256Sagc 			  const uint8_t *);
74*fc1f8641Sagc unsigned pgp_check_userattrcert_sig(const pgp_pubkey_t *,
75*fc1f8641Sagc 			  const pgp_data_t *,
76*fc1f8641Sagc 			  const pgp_sig_t *,
77*fc1f8641Sagc 			  const pgp_pubkey_t *,
78b15ec256Sagc 			  const uint8_t *);
79*fc1f8641Sagc unsigned pgp_check_subkey_sig(const pgp_pubkey_t *,
80*fc1f8641Sagc 			   const pgp_pubkey_t *,
81*fc1f8641Sagc 			   const pgp_sig_t *,
82*fc1f8641Sagc 			   const pgp_pubkey_t *,
83b15ec256Sagc 			   const uint8_t *);
84*fc1f8641Sagc unsigned pgp_check_direct_sig(const pgp_pubkey_t *,
85*fc1f8641Sagc 			   const pgp_sig_t *,
86*fc1f8641Sagc 			   const pgp_pubkey_t *,
87b15ec256Sagc 			   const uint8_t *);
88*fc1f8641Sagc unsigned pgp_check_hash_sig(pgp_hash_t *,
89*fc1f8641Sagc 			 const pgp_sig_t *,
90*fc1f8641Sagc 			 const pgp_pubkey_t *);
91*fc1f8641Sagc void pgp_sig_start_key_sig(pgp_create_sig_t *,
92*fc1f8641Sagc 				  const pgp_pubkey_t *,
93d427c17dSagc 				  const uint8_t *,
94*fc1f8641Sagc 				  pgp_sig_type_t);
95*fc1f8641Sagc void pgp_start_sig(pgp_create_sig_t *,
96*fc1f8641Sagc 			const pgp_seckey_t *,
97*fc1f8641Sagc 			const pgp_hash_alg_t,
98*fc1f8641Sagc 			const pgp_sig_type_t);
9993bf6008Sagc 
100*fc1f8641Sagc void pgp_sig_add_data(pgp_create_sig_t *, const void *, size_t);
101*fc1f8641Sagc pgp_hash_t *pgp_sig_get_hash(pgp_create_sig_t *);
102*fc1f8641Sagc unsigned   pgp_end_hashed_subpkts(pgp_create_sig_t *);
103*fc1f8641Sagc unsigned pgp_write_sig(pgp_output_t *, pgp_create_sig_t *,
104*fc1f8641Sagc 			const pgp_pubkey_t *, const pgp_seckey_t *);
105*fc1f8641Sagc unsigned   pgp_add_time(pgp_create_sig_t *, int64_t, const char *);
106*fc1f8641Sagc unsigned pgp_add_issuer_keyid(pgp_create_sig_t *,
107b15ec256Sagc 			const uint8_t *);
108*fc1f8641Sagc void pgp_add_primary_userid(pgp_create_sig_t *, unsigned);
10993bf6008Sagc 
11093bf6008Sagc /* Standard Interface */
111*fc1f8641Sagc unsigned   pgp_sign_file(pgp_io_t *,
112d21b929eSagc 			const char *,
1132232f800Sagc 			const char *,
114*fc1f8641Sagc 			const pgp_seckey_t *,
1152232f800Sagc 			const char *,
116600b302bSagc 			const int64_t,
117600b302bSagc 			const uint64_t,
1184b3a3e18Sagc 			const unsigned,
119ad7bc21dSagc 			const unsigned,
1204b3a3e18Sagc 			const unsigned);
12193bf6008Sagc 
122*fc1f8641Sagc int pgp_sign_detached(pgp_io_t *,
123d21b929eSagc 			const char *,
124d21b929eSagc 			char *,
125*fc1f8641Sagc 			pgp_seckey_t *,
126600b302bSagc 			const char *,
127600b302bSagc 			const int64_t,
128afcc02d5Sagc 			const uint64_t,
129afcc02d5Sagc 			const unsigned,
130afcc02d5Sagc 			const unsigned);
1310df5e957Sagc 
13293bf6008Sagc /* armoured stuff */
133*fc1f8641Sagc unsigned pgp_crc24(unsigned, uint8_t);
13493bf6008Sagc 
135*fc1f8641Sagc void pgp_reader_push_dearmour(pgp_stream_t *);
13693bf6008Sagc 
137*fc1f8641Sagc void pgp_reader_pop_dearmour(pgp_stream_t *);
138*fc1f8641Sagc unsigned pgp_writer_push_clearsigned(pgp_output_t *, pgp_create_sig_t *);
139*fc1f8641Sagc void pgp_writer_push_armor_msg(pgp_output_t *);
14093bf6008Sagc 
14193bf6008Sagc typedef enum {
142*fc1f8641Sagc 	PGP_PGP_MESSAGE = 1,
143*fc1f8641Sagc 	PGP_PGP_PUBLIC_KEY_BLOCK,
144*fc1f8641Sagc 	PGP_PGP_PRIVATE_KEY_BLOCK,
145*fc1f8641Sagc 	PGP_PGP_MULTIPART_MESSAGE_PART_X_OF_Y,
146*fc1f8641Sagc 	PGP_PGP_MULTIPART_MESSAGE_PART_X,
147*fc1f8641Sagc 	PGP_PGP_SIGNATURE
148*fc1f8641Sagc } pgp_armor_type_t;
14993bf6008Sagc 
15093bf6008Sagc #define CRC24_INIT 0xb704ceL
15193bf6008Sagc 
152*fc1f8641Sagc unsigned pgp_writer_use_armored_sig(pgp_output_t *);
15393bf6008Sagc 
154*fc1f8641Sagc void pgp_writer_push_armoured(pgp_output_t *, pgp_armor_type_t);
15593bf6008Sagc 
156*fc1f8641Sagc pgp_memory_t   *pgp_sign_buf(pgp_io_t *,
157ad7bc21dSagc 				const void *,
1584b3a3e18Sagc 				const size_t,
159*fc1f8641Sagc 				const pgp_seckey_t *,
160600b302bSagc 				const int64_t,
161600b302bSagc 				const uint64_t,
162ad7bc21dSagc 				const char *,
163ad7bc21dSagc 				const unsigned,
16457324b9fSagc 				const unsigned);
16557324b9fSagc 
166*fc1f8641Sagc unsigned pgp_keyring_read_from_mem(pgp_io_t *,
167*fc1f8641Sagc 				pgp_keyring_t *,
16857324b9fSagc 				const unsigned,
169*fc1f8641Sagc 				pgp_memory_t *);
17057324b9fSagc 
1714b3a3e18Sagc #endif /* SIGNATURE_H_ */
172