xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/signature.h (revision c8da0e5fefd3800856b306200a18b2315c7fbb9f)
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 /** \file
51  */
52 
53 #ifndef OPS_SIGNATURE_H
54 #define OPS_SIGNATURE_H
55 
56 #include "packet.h"
57 #include "create.h"
58 
59 typedef struct __ops_create_sig __ops_create_sig_t;
60 
61 __ops_create_sig_t *__ops_create_sig_new(void);
62 void            __ops_create_sig_delete(__ops_create_sig_t *);
63 
64 bool
65 __ops_check_useridcert_sig(const __ops_pubkey_t *,
66 			  const __ops_user_id_t *,
67 			  const __ops_sig_t *,
68 			  const __ops_pubkey_t *,
69 			  const unsigned char *);
70 bool
71 __ops_check_userattrcert_sig(const __ops_pubkey_t *,
72 			  const __ops_user_attribute_t *,
73 			  const __ops_sig_t *,
74 			  const __ops_pubkey_t *,
75 			  const unsigned char *);
76 bool
77 __ops_check_subkey_sig(const __ops_pubkey_t *,
78 			   const __ops_pubkey_t *,
79 			   const __ops_sig_t *,
80 			   const __ops_pubkey_t *,
81 			   const unsigned char *);
82 bool
83 __ops_check_direct_sig(const __ops_pubkey_t *,
84 			   const __ops_sig_t *,
85 			   const __ops_pubkey_t *,
86 			   const unsigned char *);
87 bool
88 __ops_check_hash_sig(__ops_hash_t *,
89 			 const __ops_sig_t *,
90 			 const __ops_pubkey_t *);
91 void
92 __ops_sig_start_key_sig(__ops_create_sig_t *,
93 				  const __ops_pubkey_t *,
94 				  const __ops_user_id_t *,
95 				  __ops_sig_type_t);
96 void
97 __ops_start_sig(__ops_create_sig_t *,
98 			const __ops_seckey_t *,
99 			const __ops_hash_alg_t,
100 			const __ops_sig_type_t);
101 
102 void __ops_sig_add_data(__ops_create_sig_t *, const void *, size_t);
103 __ops_hash_t *__ops_sig_get_hash(__ops_create_sig_t *);
104 bool   __ops_sig_hashed_subpackets_end(__ops_create_sig_t *);
105 bool __ops_write_sig(__ops_create_sig_t *, const __ops_pubkey_t *,
106 		    const __ops_seckey_t *, __ops_createinfo_t *);
107 bool   __ops_sig_add_birthtime(__ops_create_sig_t *, time_t);
108 bool __ops_sig_add_issuer_key_id(__ops_create_sig_t *, const unsigned char *);
109 void __ops_sig_add_primary_user_id(__ops_create_sig_t *, bool);
110 
111 /* Standard Interface */
112 bool   __ops_sign_file_as_cleartext(const char *,
113 			const char *,
114 			const __ops_seckey_t *,
115 			const char *,
116 			const bool);
117 bool   __ops_sign_file(const char *,
118 			const char *,
119 			const __ops_seckey_t *,
120 			const char *,
121 			const bool,
122 			const bool);
123 
124 /* armoured stuff */
125 unsigned        __ops_crc24(unsigned, unsigned char);
126 
127 void            __ops_reader_push_dearmour(__ops_parseinfo_t *);
128 
129 void            __ops_reader_pop_dearmour(__ops_parseinfo_t *);
130 bool __ops_writer_push_clearsigned(__ops_createinfo_t *, __ops_create_sig_t *);
131 void            __ops_writer_push_armoured_message(__ops_createinfo_t *);
132 
133 typedef enum {
134 	OPS_PGP_MESSAGE = 1,
135 	OPS_PGP_PUBLIC_KEY_BLOCK,
136 	OPS_PGP_PRIVATE_KEY_BLOCK,
137 	OPS_PGP_MULTIPART_MESSAGE_PART_X_OF_Y,
138 	OPS_PGP_MULTIPART_MESSAGE_PART_X,
139 	OPS_PGP_SIGNATURE
140 } __ops_armor_type_t;
141 
142 #define CRC24_INIT 0xb704ceL
143 
144 bool
145 __ops_writer_push_clearsigned(__ops_createinfo_t *, __ops_create_sig_t *);
146 void   __ops_writer_push_armoured_message(__ops_createinfo_t *);
147 bool   __ops_writer_use_armored_sig(__ops_createinfo_t *);
148 
149 void   __ops_writer_push_armoured(__ops_createinfo_t *, __ops_armor_type_t);
150 
151 #endif
152