3 * OpenPGP MPI helper functions.
5 * Copyright (c) 2005 Marko Kreen
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * contrib/pgcrypto/pgp-mpi.c
40 int len = (bits + 7) / 8;
42 if (bits < 0 || bits > 0xFFFF)
44 px_debug(
"pgp_mpi_alloc: unreasonable request: bits=%d", bits);
90 bits = ((unsigned) hdr[0] << 8) + hdr[1];
136 cksum += n->
bits >> 8;
137 cksum += n->
bits & 0xFF;
141 return cksum & 0xFFFF;
int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
int pushf_write(PushFilter *mp, const uint8 *data, int len)
void pfree(void *pointer)
int pgp_mpi_create(uint8 *data, int bits, PGP_MPI **mpi)
int pgp_mpi_alloc(int bits, PGP_MPI **mpi)
int pgp_mpi_free(PGP_MPI *mpi)
int pgp_mpi_write(PushFilter *dst, PGP_MPI *n)
int pgp_mpi_hash(PX_MD *md, PGP_MPI *n)
int pgp_mpi_read(PullFilter *src, PGP_MPI **mpi)
unsigned pgp_mpi_cksum(unsigned cksum, PGP_MPI *n)
void px_debug(const char *fmt,...)
void px_memset(void *ptr, int c, size_t len)
#define PXE_PGP_CORRUPT_DATA
#define px_md_update(md, data, dlen)