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