• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Framework classes for generation of bignum mod_raw test cases."""
2# Copyright The Mbed TLS Contributors
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from typing import Dict, List
18
19from . import test_data_generation
20from . import bignum_common
21
22class BignumModRawTarget(test_data_generation.BaseTarget):
23    #pylint: disable=abstract-method, too-few-public-methods
24    """Target for bignum mod_raw test case generation."""
25    target_basename = 'test_suite_bignum_mod_raw.generated'
26
27# BEGIN MERGE SLOT 1
28
29# END MERGE SLOT 1
30
31# BEGIN MERGE SLOT 2
32
33class BignumModRawSub(bignum_common.ModOperationCommon,
34                      BignumModRawTarget):
35    """Test cases for bignum mpi_mod_raw_sub()."""
36    symbol = "-"
37    test_function = "mpi_mod_raw_sub"
38    test_name = "mbedtls_mpi_mod_raw_sub"
39    input_style = "fixed"
40    arity = 2
41
42    def arguments(self) -> List[str]:
43        return [bignum_common.quote_str(n) for n in [self.arg_a,
44                                                     self.arg_b,
45                                                     self.arg_n]
46               ] + self.result()
47
48    def result(self) -> List[str]:
49        result = (self.int_a - self.int_b) % self.int_n
50        return [self.format_result(result)]
51
52# END MERGE SLOT 2
53
54# BEGIN MERGE SLOT 3
55
56# END MERGE SLOT 3
57
58# BEGIN MERGE SLOT 4
59
60# END MERGE SLOT 4
61
62# BEGIN MERGE SLOT 5
63
64class BignumModRawAdd(bignum_common.ModOperationCommon,
65                      BignumModRawTarget):
66    """Test cases for bignum mpi_mod_raw_add()."""
67    symbol = "+"
68    test_function = "mpi_mod_raw_add"
69    test_name = "mbedtls_mpi_mod_raw_add"
70    input_style = "fixed"
71    arity = 2
72
73    def result(self) -> List[str]:
74        result = (self.int_a + self.int_b) % self.int_n
75        return [self.format_result(result)]
76
77# END MERGE SLOT 5
78
79# BEGIN MERGE SLOT 6
80
81# END MERGE SLOT 6
82
83# BEGIN MERGE SLOT 7
84
85class BignumModRawConvertToMont(bignum_common.ModOperationCommon,
86                                BignumModRawTarget):
87    """ Test cases for mpi_mod_raw_to_mont_rep(). """
88    test_function = "mpi_mod_raw_to_mont_rep"
89    test_name = "Convert into Mont: "
90    symbol = "R *"
91    input_style = "arch_split"
92    arity = 1
93
94    def result(self) -> List[str]:
95        result = self.to_montgomery(self.int_a)
96        return [self.format_result(result)]
97
98class BignumModRawConvertFromMont(bignum_common.ModOperationCommon,
99                                  BignumModRawTarget):
100    """ Test cases for mpi_mod_raw_from_mont_rep(). """
101    test_function = "mpi_mod_raw_from_mont_rep"
102    test_name = "Convert from Mont: "
103    symbol = "1/R *"
104    input_style = "arch_split"
105    arity = 1
106
107    def result(self) -> List[str]:
108        result = self.from_montgomery(self.int_a)
109        return [self.format_result(result)]
110
111
112# END MERGE SLOT 7
113
114# BEGIN MERGE SLOT 8
115
116# END MERGE SLOT 8
117
118# BEGIN MERGE SLOT 9
119
120# END MERGE SLOT 9
121
122# BEGIN MERGE SLOT 10
123
124# END MERGE SLOT 10
125