blob: 378c58dd4713816d0b476dd3fc95fde90aa0049a [file] [log] [blame]
Gabor Mezeif049dbf2022-07-18 23:02:33 +02001/**
2 * Internal bignum functions
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#ifndef MBEDTLS_BIGNUM_MOD_H
21#define MBEDTLS_BIGNUM_MOD_H
22
23#include "common.h"
24
25#if defined(MBEDTLS_BIGNUM_C)
26#include "mbedtls/bignum.h"
27#endif
28
29
30typedef struct
31{
32 size_t n;
33 mbedtls_mpi_uint *p;
34} mbedtls_mpi_mod_residue;
35
36typedef void* mbedtls_mpi_mont_struct;
37typedef void* mbedtls_mpi_opt_red_struct;
38
39typedef struct {
40 mbedtls_mpi_uint *p;
41 size_t n; // number of limbs
42 size_t plen; // bitlen of p
43 int ext_rep; // signals external representation (eg. byte order)
44 int int_rep; // selector to signal the active member of the union
45 union rep
46 {
47 mbedtls_mpi_mont_struct mont;
48 mbedtls_mpi_opt_red_struct ored;
49 } rep;
50} mbedtls_mpi_mod_modulus;
51
52void mbedtls_mpi_mod_residue_release( mbedtls_mpi_mod_residue *r );
53
54int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
55 mbedtls_mpi_mod_modulus *m,
56 mbedtls_mpi_uint *p );
57
58void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m );
59
60void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m );
61
62int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m,
63 mbedtls_mpi_uint *p,
64 size_t n,
65 int ext_rep,
66 int int_rep );
67
68#endif /* MBEDTLS_BIGNUM_MOD_H */