15fff9558SSimon J. Gerraty /*- 25fff9558SSimon J. Gerraty * Copyright (c) 2018, Juniper Networks, Inc. 35fff9558SSimon J. Gerraty * 45fff9558SSimon J. Gerraty * Redistribution and use in source and binary forms, with or without 55fff9558SSimon J. Gerraty * modification, are permitted provided that the following conditions 65fff9558SSimon J. Gerraty * are met: 75fff9558SSimon J. Gerraty * 1. Redistributions of source code must retain the above copyright 85fff9558SSimon J. Gerraty * notice, this list of conditions and the following disclaimer. 95fff9558SSimon J. Gerraty * 2. Redistributions in binary form must reproduce the above copyright 105fff9558SSimon J. Gerraty * notice, this list of conditions and the following disclaimer in the 115fff9558SSimon J. Gerraty * documentation and/or other materials provided with the distribution. 125fff9558SSimon J. Gerraty * 135fff9558SSimon J. Gerraty * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 145fff9558SSimon J. Gerraty * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 155fff9558SSimon J. Gerraty * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 165fff9558SSimon J. Gerraty * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 175fff9558SSimon J. Gerraty * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 185fff9558SSimon J. Gerraty * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 195fff9558SSimon J. Gerraty * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 205fff9558SSimon J. Gerraty * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 215fff9558SSimon J. Gerraty * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225fff9558SSimon J. Gerraty * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 235fff9558SSimon J. Gerraty * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245fff9558SSimon J. Gerraty */ 255fff9558SSimon J. Gerraty /* 265fff9558SSimon J. Gerraty */ 275fff9558SSimon J. Gerraty 285fff9558SSimon J. Gerraty #ifdef USE_BEARSSL 295fff9558SSimon J. Gerraty unsigned char * mpi2bn(unsigned char **pptr, size_t *sz); 305fff9558SSimon J. Gerraty #else 315fff9558SSimon J. Gerraty # include <openssl/bn.h> 325fff9558SSimon J. Gerraty # include <openssl/rsa.h> 335fff9558SSimon J. Gerraty # include <openssl/evp.h> 345fff9558SSimon J. Gerraty 355fff9558SSimon J. Gerraty BIGNUM * mpi2bn(unsigned char **pptr); 365fff9558SSimon J. Gerraty #endif 375fff9558SSimon J. Gerraty 385fff9558SSimon J. Gerraty #define NEW(x) calloc(1,sizeof(x)) 395fff9558SSimon J. Gerraty 405fff9558SSimon J. Gerraty #define OPENPGP_TAG_ISTAG 0200 415fff9558SSimon J. Gerraty #define OPENPGP_TAG_ISNEW 0100 425fff9558SSimon J. Gerraty #define OPENPGP_TAG_NEW_MASK 0077 435fff9558SSimon J. Gerraty #define OPENPGP_TAG_OLD_MASK 0074 445fff9558SSimon J. Gerraty #define OPENPGP_TAG_OLD_TYPE 0003 455fff9558SSimon J. Gerraty 465fff9558SSimon J. Gerraty typedef int (*decoder_t)(int, unsigned char **, int, void *); 475fff9558SSimon J. Gerraty 485fff9558SSimon J. Gerraty unsigned char * i2octets(int n, size_t i); 495fff9558SSimon J. Gerraty int octets2i(unsigned char *ptr, size_t n); 505fff9558SSimon J. Gerraty char * octets2hex(unsigned char *ptr, size_t n); 515fff9558SSimon J. Gerraty int decode_tag(unsigned char *ptr, int *isnew, int *ltype); 525fff9558SSimon J. Gerraty unsigned char * decode_mpi(unsigned char **pptr, size_t *sz); 535fff9558SSimon J. Gerraty unsigned char * dearmor(char *pem, size_t nbytes, size_t *len); 545fff9558SSimon J. Gerraty int decode_packet(int want, unsigned char **pptr, size_t nbytes, 555fff9558SSimon J. Gerraty decoder_t decoder, void *decoder_arg); 565fff9558SSimon J. Gerraty unsigned char * decode_subpacket(unsigned char **pptr, int *stag, int *sz); 57