| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#ifndef BIGINT_HEADER |
| 32 |
#define BIGINT_HEADER |
| 33 |
|
| 34 |
#include "crypto.h" |
| 35 |
|
| 36 |
BI_CTX *bi_initialize(void); |
| 37 |
void bi_terminate(BI_CTX *ctx); |
| 38 |
void bi_permanent(bigint *bi); |
| 39 |
void bi_depermanent(bigint *bi); |
| 40 |
void bi_clear_cache(BI_CTX *ctx); |
| 41 |
void bi_free(BI_CTX *ctx, bigint *bi); |
| 42 |
bigint *bi_copy(bigint *bi); |
| 43 |
bigint *bi_clone(BI_CTX *ctx, const bigint *bi); |
| 44 |
void bi_export(BI_CTX *ctx, bigint *bi, uint8_t *data, int size); |
| 45 |
bigint *bi_import(BI_CTX *ctx, const uint8_t *data, int len); |
| 46 |
bigint *int_to_bi(BI_CTX *ctx, comp i); |
| 47 |
|
| 48 |
|
| 49 |
bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib); |
| 50 |
bigint *bi_subtract(BI_CTX *ctx, bigint *bia, |
| 51 |
bigint *bib, int *is_negative); |
| 52 |
bigint *bi_divide(BI_CTX *ctx, bigint *bia, bigint *bim, int is_mod); |
| 53 |
bigint *bi_multiply(BI_CTX *ctx, bigint *bia, bigint *bib); |
| 54 |
bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp); |
| 55 |
bigint *bi_mod_power2(BI_CTX *ctx, bigint *bi, bigint *bim, bigint *biexp); |
| 56 |
int bi_compare(bigint *bia, bigint *bib); |
| 57 |
void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset); |
| 58 |
void bi_free_mod(BI_CTX *ctx, int mod_offset); |
| 59 |
|
| 60 |
#ifdef CONFIG_DEBUG |
| 61 |
void bi_print(const char *label, bigint *bi); |
| 62 |
bigint *bi_str_import(BI_CTX *ctx, const char *data); |
| 63 |
#endif |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
#define bi_mod(A, B) bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
#if defined(CONFIG_BIGINT_MONTGOMERY) |
| 77 |
#define bi_residue(A, B) bi_mont(A, B) |
| 78 |
bigint *bi_mont(BI_CTX *ctx, bigint *bixy); |
| 79 |
#elif defined(CONFIG_BIGINT_BARRETT) |
| 80 |
#define bi_residue(A, B) bi_barrett(A, B) |
| 81 |
bigint *bi_barrett(BI_CTX *ctx, bigint *bi); |
| 82 |
#else |
| 83 |
#define bi_residue(A, B) bi_mod(A, B) |
| 84 |
#endif |
| 85 |
|
| 86 |
#ifdef CONFIG_BIGINT_SQUARE |
| 87 |
bigint *bi_square(BI_CTX *ctx, bigint *bi); |
| 88 |
#else |
| 89 |
#define bi_square(A, B) bi_multiply(A, bi_copy(B), B) |
| 90 |
#endif |
| 91 |
|
| 92 |
#ifdef CONFIG_BIGINT_CRT |
| 93 |
bigint *bi_crt(BI_CTX *ctx, bigint *bi, |
| 94 |
bigint *dP, bigint *dQ, |
| 95 |
bigint *p, bigint *q, |
| 96 |
bigint *qInv); |
| 97 |
#endif |
| 98 |
|
| 99 |
#endif |