Major memory management overhaul. Added arena support. Use the secure
[u/mdw/catacomb] / mpx-kmac.h
CommitLineData
7d5fa32a 1/* -*-c-*-
2 *
3 * $Id: mpx-kmac.h,v 1.1 2000/06/17 11:42:11 mdw Exp $
4 *
5 * Macros for Karatsuba functions
6 *
7 * (c) 2000 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: mpx-kmac.h,v $
33 * Revision 1.1 2000/06/17 11:42:11 mdw
34 * Moved the Karatsuba macros into a separate file for better sharing.
35 * Fixed some comments.
36 *
37 */
38
39#ifndef CATACOMB_MPX_KMAC_H
40#define CATACOMB_MPX_KMAC_H
41
42#ifdef __cplusplus
43 extern "C" {
44#endif
45
46/*----- Header files ------------------------------------------------------*/
47
48#ifndef CATACOMB_MPW_H
49# include "mpw.h"
50#endif
51
52/*----- Macros provided ---------------------------------------------------*/
53
54#define UADD(dv, av, avl) do { \
55 mpw *_dv = (dv); \
56 const mpw *_av = (av), *_avl = (avl); \
57 mpw _c = 0; \
58 \
59 while (_av < _avl) { \
60 mpw _a, _b; \
61 mpd _x; \
62 _a = *_av++; \
63 _b = *_dv; \
64 _x = (mpd)_a + (mpd)_b + _c; \
65 *_dv++ = MPW(_x); \
66 _c = _x >> MPW_BITS; \
67 } \
68 while (_c) { \
69 mpd _x = (mpd)*_dv + (mpd)_c; \
70 *_dv++ = MPW(_x); \
71 _c = _x >> MPW_BITS; \
72 } \
73} while (0)
74
75#define UADD2(dv, dvl, av, avl, bv, bvl) do { \
76 mpw *_dv = (dv), *_dvl = (dvl); \
77 const mpw *_av = (av), *_avl = (avl); \
78 const mpw *_bv = (bv), *_bvl = (bvl); \
79 mpw _c = 0; \
80 \
81 while (_av < _avl || _bv < _bvl) { \
82 mpw _a, _b; \
83 mpd _x; \
84 _a = (_av < _avl) ? *_av++ : 0; \
85 _b = (_bv < _bvl) ? *_bv++ : 0; \
86 _x = (mpd)_a + (mpd)_b + _c; \
87 *_dv++ = MPW(_x); \
88 _c = _x >> MPW_BITS; \
89 } \
90 *_dv++ = _c; \
91 while (_dv < _dvl) \
92 *_dv++ = 0; \
93} while (0)
94
95#define USUB(dv, av, avl) do { \
96 mpw *_dv = (dv); \
97 const mpw *_av = (av), *_avl = (avl); \
98 mpw _c = 0; \
99 \
100 while (_av < _avl) { \
101 mpw _a, _b; \
102 mpd _x; \
103 _a = *_av++; \
104 _b = *_dv; \
105 _x = (mpd)_b - (mpd)_a - _c; \
106 *_dv++ = MPW(_x); \
107 if (_x >> MPW_BITS) \
108 _c = 1; \
109 else \
110 _c = 0; \
111 } \
112 while (_c) { \
113 mpd _x = (mpd)*_dv - (mpd)_c; \
114 *_dv++ = MPW(_x); \
115 if (_x >> MPW_BITS) \
116 _c = 1; \
117 else \
118 _c = 0; \
119 } \
120} while (0)
121
122/*----- That's all, folks -------------------------------------------------*/
123
124#ifdef __cplusplus
125 }
126#endif
127
128#endif