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 SIGNATURE_H_ 54 #define SIGNATURE_H_ 55 56 #include <sys/types.h> 57 58 #include <inttypes.h> 59 60 #include "packet.h" 61 #include "create.h" 62 #include "memory.h" 63 64 typedef struct pgp_create_sig_t pgp_create_sig_t; 65 66 pgp_create_sig_t *pgp_create_sig_new(void); 67 void pgp_create_sig_delete(pgp_create_sig_t *); 68 69 unsigned pgp_check_useridcert_sig(const pgp_pubkey_t *, 70 const uint8_t *, 71 const pgp_sig_t *, 72 const pgp_pubkey_t *, 73 const uint8_t *); 74 unsigned pgp_check_userattrcert_sig(const pgp_pubkey_t *, 75 const pgp_data_t *, 76 const pgp_sig_t *, 77 const pgp_pubkey_t *, 78 const uint8_t *); 79 unsigned pgp_check_subkey_sig(const pgp_pubkey_t *, 80 const pgp_pubkey_t *, 81 const pgp_sig_t *, 82 const pgp_pubkey_t *, 83 const uint8_t *); 84 unsigned pgp_check_direct_sig(const pgp_pubkey_t *, 85 const pgp_sig_t *, 86 const pgp_pubkey_t *, 87 const uint8_t *); 88 unsigned pgp_check_hash_sig(pgp_hash_t *, 89 const pgp_sig_t *, 90 const pgp_pubkey_t *); 91 void pgp_sig_start_key_sig(pgp_create_sig_t *, 92 const pgp_pubkey_t *, 93 const uint8_t *, 94 pgp_sig_type_t); 95 void pgp_start_sig(pgp_create_sig_t *, 96 const pgp_seckey_t *, 97 const pgp_hash_alg_t, 98 const pgp_sig_type_t); 99 100 void pgp_sig_add_data(pgp_create_sig_t *, const void *, size_t); 101 pgp_hash_t *pgp_sig_get_hash(pgp_create_sig_t *); 102 unsigned pgp_end_hashed_subpkts(pgp_create_sig_t *); 103 unsigned pgp_write_sig(pgp_output_t *, pgp_create_sig_t *, 104 const pgp_pubkey_t *, const pgp_seckey_t *); 105 unsigned pgp_add_time(pgp_create_sig_t *, int64_t, const char *); 106 unsigned pgp_add_issuer_keyid(pgp_create_sig_t *, 107 const uint8_t *); 108 void pgp_add_primary_userid(pgp_create_sig_t *, unsigned); 109 110 /* Standard Interface */ 111 unsigned pgp_sign_file(pgp_io_t *, 112 const char *, 113 const char *, 114 const pgp_seckey_t *, 115 const char *, 116 const int64_t, 117 const uint64_t, 118 const unsigned, 119 const unsigned, 120 const unsigned); 121 122 int pgp_sign_detached(pgp_io_t *, 123 const char *, 124 char *, 125 pgp_seckey_t *, 126 const char *, 127 const int64_t, 128 const uint64_t, 129 const unsigned, 130 const unsigned); 131 132 /* armoured stuff */ 133 unsigned pgp_crc24(unsigned, uint8_t); 134 135 void pgp_reader_push_dearmour(pgp_stream_t *); 136 137 void pgp_reader_pop_dearmour(pgp_stream_t *); 138 unsigned pgp_writer_push_clearsigned(pgp_output_t *, pgp_create_sig_t *); 139 void pgp_writer_push_armor_msg(pgp_output_t *); 140 141 typedef enum { 142 PGP_PGP_MESSAGE = 1, 143 PGP_PGP_PUBLIC_KEY_BLOCK, 144 PGP_PGP_PRIVATE_KEY_BLOCK, 145 PGP_PGP_MULTIPART_MESSAGE_PART_X_OF_Y, 146 PGP_PGP_MULTIPART_MESSAGE_PART_X, 147 PGP_PGP_SIGNATURE 148 } pgp_armor_type_t; 149 150 #define CRC24_INIT 0xb704ceL 151 152 unsigned pgp_writer_use_armored_sig(pgp_output_t *); 153 154 void pgp_writer_push_armoured(pgp_output_t *, pgp_armor_type_t); 155 156 pgp_memory_t *pgp_sign_buf(pgp_io_t *, 157 const void *, 158 const size_t, 159 const pgp_seckey_t *, 160 const int64_t, 161 const uint64_t, 162 const char *, 163 const unsigned, 164 const unsigned); 165 166 unsigned pgp_keyring_read_from_mem(pgp_io_t *, 167 pgp_keyring_t *, 168 const unsigned, 169 pgp_memory_t *); 170 171 #endif /* SIGNATURE_H_ */ 172