source: bootcd/isolinux/syslinux-6.03/gpxe/src/crypto/axtls/bigint.h @ e16e8f2

Last change on this file since e16e8f2 was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Copyright(C) 2006 Cameron Rich
3 *
4 *  This library is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU Lesser General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This library is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *  GNU Lesser General Public License for more details.
13 *
14 *  You should have received a copy of the GNU Lesser General Public License
15 *  along with this library; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#ifndef BIGINT_HEADER
20#define BIGINT_HEADER
21
22/* enable features based on a 'super-set' capbaility. */
23#if defined(CONFIG_SSL_FULL_MODE)
24#define CONFIG_SSL_ENABLE_CLIENT
25#define CONFIG_SSL_CERT_VERIFICATION
26#elif defined(CONFIG_SSL_ENABLE_CLIENT)
27#define CONFIG_SSL_CERT_VERIFICATION
28#endif
29
30#include "os_port.h"
31#include "bigint_impl.h"
32
33#ifndef CONFIG_BIGINT_CHECK_ON
34#define check(A)                /**< disappears in normal production mode */
35#endif
36BI_CTX *bi_initialize(void);
37void bi_terminate(BI_CTX *ctx);
38void bi_permanent(bigint *bi);
39void bi_depermanent(bigint *bi);
40void bi_free(BI_CTX *ctx, bigint *bi);
41bigint *bi_copy(bigint *bi);
42bigint *bi_clone(BI_CTX *ctx, const bigint *bi);
43void bi_export(BI_CTX *ctx, bigint *bi, uint8_t *data, int size);
44bigint *bi_import(BI_CTX *ctx, const uint8_t *data, int len);
45bigint *int_to_bi(BI_CTX *ctx, comp i);
46
47/* the functions that actually do something interesting */
48bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib);
49bigint *bi_subtract(BI_CTX *ctx, bigint *bia,
50        bigint *bib, int *is_negative);
51bigint *bi_divide(BI_CTX *ctx, bigint *bia, bigint *bim, int is_mod);
52bigint *bi_multiply(BI_CTX *ctx, bigint *bia, bigint *bib);
53bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp);
54bigint *bi_mod_power2(BI_CTX *ctx, bigint *bi, bigint *bim, bigint *biexp);
55int bi_compare(bigint *bia, bigint *bib);
56void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset);
57void bi_free_mod(BI_CTX *ctx, int mod_offset);
58
59#ifdef CONFIG_SSL_FULL_MODE
60void bi_print(const char *label, bigint *bi);
61bigint *bi_str_import(BI_CTX *ctx, const char *data);
62#endif
63
64/**
65 * @def bi_mod
66 * Find the residue of B. bi_set_mod() must be called before hand.
67 */
68#define bi_mod(A, B)      bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1)
69
70/**
71 * bi_residue() is technically the same as bi_mod(), but it uses the
72 * appropriate reduction technique (which is bi_mod() when doing classical
73 * reduction).
74 */
75#if defined(CONFIG_BIGINT_MONTGOMERY)
76#define bi_residue(A, B)         bi_mont(A, B)
77bigint *bi_mont(BI_CTX *ctx, bigint *bixy);
78#elif defined(CONFIG_BIGINT_BARRETT)
79#define bi_residue(A, B)         bi_barrett(A, B)
80bigint *bi_barrett(BI_CTX *ctx, bigint *bi);
81#else /* if defined(CONFIG_BIGINT_CLASSICAL) */
82#define bi_residue(A, B)         bi_mod(A, B)
83#endif
84
85#ifdef CONFIG_BIGINT_SQUARE
86bigint *bi_square(BI_CTX *ctx, bigint *bi);
87#else
88#define bi_square(A, B)     bi_multiply(A, bi_copy(B), B)
89#endif
90
91#endif
Note: See TracBrowser for help on using the repository browser.