Pollard's rho algorithm for computing discrete logs.
[u/mdw/catacomb] / mparena.h
CommitLineData
d3409d5e 1/* -*-c-*-
2 *
d4745354 3 * $Id: mparena.h,v 1.3 2000/06/17 11:35:48 mdw Exp $
d3409d5e 4 *
5 * Allocation and freeing of MP buffers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: mparena.h,v $
d4745354 33 * Revision 1.3 2000/06/17 11:35:48 mdw
34 * Overhaul to use mLib's arena system underneath.
35 *
97d21728 36 * Revision 1.2 1999/12/10 23:28:59 mdw
37 * Memory allocation counting.
38 *
d3409d5e 39 * Revision 1.1 1999/11/17 18:02:16 mdw
40 * New multiprecision integer arithmetic suite.
41 *
42 */
43
97d21728 44#ifndef CATACOMB_MPARENA_H
45#define CATACOMB_MPARENA_H
d3409d5e 46
47#ifdef __cplusplus
48 extern "C" {
49#endif
50
51/*----- Header files ------------------------------------------------------*/
52
d4745354 53#include <mLib/arena.h>
54
97d21728 55#ifndef CATACOMB_MPW_H
d3409d5e 56# include "mpw.h"
57#endif
58
59/*----- Data structures ---------------------------------------------------*/
60
61/* --- @mparena_node@ --- *
62 *
63 * For internal use by the MP arena manager. The free blocks are held in a
64 * binary tree by size, held in the first digit of each vector.
65 */
66
67typedef struct mparena_node {
68 struct mparena_node *left, *right;
69 mpw *v;
70} mparena_node;
71
72/* --- @mparena@ --- *
73 *
74 * The actual arena.
75 */
76
77typedef struct mparena {
78 mparena_node *root;
97d21728 79 unsigned n;
d4745354 80 arena *a;
d3409d5e 81} mparena;
82
d4745354 83/*----- Standard arenas ---------------------------------------------------*/
d3409d5e 84
d4745354 85extern mparena mparena_global;
86#define MPARENA_GLOBAL (&mparena_global)
d3409d5e 87
d4745354 88extern mparena mparena_secure;
89#define MPARENA_SECURE (&mparena_secure)
d3409d5e 90
91/*----- Functions provided ------------------------------------------------*/
92
93/* --- @mparena_create@ --- *
94 *
95 * Arguments: @mparena *a@ = pointer to arena block
96 *
97 * Returns: ---
98 *
99 * Use: Initializes an MP arena so that blocks can be allocated from
100 * it.
101 */
102
103extern void mparena_create(mparena */*a*/);
104
d4745354 105#define MPARENA_INIT { 0, 0, &arena_stdlib }
d3409d5e 106
d4745354 107/* --- @mparena_setarena@ --- *
d3409d5e 108 *
d4745354 109 * Arguments: @mparena *a@ = pointer to MP arena block
110 * @arena *aa@ = pointer to arena
d3409d5e 111 *
d4745354 112 * Returns: ---
d3409d5e 113 *
d4745354 114 * Use: Sets the underlying arena for an MP arena.
d3409d5e 115 */
116
d4745354 117extern void mparena_setarena(mparena */*a*/, arena */*aa*/);
d3409d5e 118
119/* --- @mparena_destroy@ --- *
120 *
121 * Arguments: @mparena *a@ = pointer to arena block
122 *
123 * Returns: ---
124 *
125 * Use: Frees an MP arena, and all the vectors held within it. The
126 * blocks which are currently allocated can be freed into some
d4745354 127 * other MP arena, as long as the underlying arenas are the
128 * same.
d3409d5e 129 */
130
131extern void mparena_destroy(mparena */*a*/);
132
97d21728 133/* --- @mparena_count@ --- *
134 *
135 * Arguments: @mparena *a@ = pointer to arena block
136 *
137 * Returns: Number of allocated blocks from this arena.
138 *
139 * Use: Reports the number of blocks allocated from the arena and not
140 * yet freed.
141 */
142
143extern unsigned mparena_count(mparena */*a*/);
144
d3409d5e 145/* --- @mpalloc@ --- *
146 *
147 * Arguments: @mparena *a@ = pointer to arena block
148 * @size_t sz@ = number of digits required
149 *
150 * Returns: Pointer to a suitably sized block.
151 *
152 * Use: Allocates a lump of data suitable for use as an array of MP
153 * digits.
154 */
155
156extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
157
158/* --- @mpfree@ --- *
159 *
160 * Arguments: @mparena *a@ = pointer to arena block
161 * @mpw *v@ = pointer to allocated vector
162 *
163 * Returns: ---
164 *
97d21728 165 * Use: Returns an MP vector to an arena.
d3409d5e 166 */
167
168extern void mpfree(mparena */*a*/, mpw */*v*/);
169
170/*----- That's all, folks -------------------------------------------------*/
171
172#ifdef __cplusplus
173 }
174#endif
175
176#endif