~ubuntu-branches/ubuntu/dapper/nettle/dapper

« back to all changes in this revision

Viewing changes to bignum.h

  • Committer: Bazaar Package Importer
  • Author(s): Marek Habersack
  • Date: 2004-05-04 15:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040504155602-7jbhw5mabvwksl3j
Tags: upstream-1.10
Import upstream version 1.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* bignum.h
 
2
 *
 
3
 * bignum operations that are missing from gmp.
 
4
 */
 
5
 
 
6
/* nettle, low-level cryptographics library
 
7
 *
 
8
 * Copyright (C) 2001 Niels M�ller
 
9
 *  
 
10
 * The nettle library is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU Lesser General Public License as published by
 
12
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
13
 * option) any later version.
 
14
 * 
 
15
 * The nettle library is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
17
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
18
 * License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU Lesser General Public License
 
21
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 
22
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
23
 * MA 02111-1307, USA.
 
24
 */
 
25
 
 
26
#ifndef NETTLE_BIGNUM_H_INCLUDED
 
27
#define NETTLE_BIGNUM_H_INCLUDED
 
28
 
 
29
#include "nettle-meta.h"
 
30
 
 
31
#include <gmp.h>
 
32
#include "nettle-types.h"
 
33
 
 
34
/* Size needed for signed encoding, including extra sign byte if
 
35
 * necessary. */
 
36
unsigned
 
37
nettle_mpz_sizeinbase_256_s(const mpz_t x);
 
38
 
 
39
/* Size needed for unsigned encoding */
 
40
unsigned
 
41
nettle_mpz_sizeinbase_256_u(const mpz_t x);
 
42
 
 
43
/* Writes an integer as length octets, using big endian byte order,
 
44
 * and two's complement for negative numbers. */
 
45
/* FIXME: Change order of arguments, putting the mpz_t first? */
 
46
void
 
47
nettle_mpz_get_str_256(unsigned length, uint8_t *s, const mpz_t x);
 
48
 
 
49
/* Reads a big endian, two's complement, integer. */
 
50
void
 
51
nettle_mpz_set_str_256_s(mpz_t x,
 
52
                         unsigned length, const uint8_t *s);
 
53
 
 
54
void
 
55
nettle_mpz_init_set_str_256_s(mpz_t x,
 
56
                              unsigned length, const uint8_t *s);
 
57
 
 
58
/* Similar, but for unsigned format. These function don't interpret
 
59
 * the most significant bit as the sign. */
 
60
void
 
61
nettle_mpz_set_str_256_u(mpz_t x,
 
62
                         unsigned length, const uint8_t *s);
 
63
 
 
64
void
 
65
nettle_mpz_init_set_str_256_u(mpz_t x,
 
66
                              unsigned length, const uint8_t *s);
 
67
 
 
68
/* Returns a uniformly distributed random number 0 <= x < 2^n */
 
69
void
 
70
nettle_mpz_random_size(mpz_t x,
 
71
                       void *ctx, nettle_random_func random,
 
72
                       unsigned bits);
 
73
 
 
74
/* Returns a number x, almost uniformly random in the range
 
75
 * 0 <= x < n. */
 
76
void
 
77
nettle_mpz_random(mpz_t x, 
 
78
                  void *ctx, nettle_random_func random,
 
79
                  const mpz_t n);
 
80
 
 
81
struct sexp_iterator;
 
82
 
 
83
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
 
84
 * Implies sexp_iterator_next. */
 
85
int
 
86
nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
 
87
 
 
88
#endif /* NETTLE_BIGNUM_H_INCLUDED */