blob: 9086c2eb51de79bcdabb070e9fb37f5b13968149 [file] [log] [blame]
Janos Follathb99b0562022-11-02 14:44:08 +00001"""Framework classes for generation of bignum mod 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
Werner Lewiscff75782022-11-30 16:34:07 +000017from typing import Dict, List # pylint: disable=unused-import
18
Janos Follathb99b0562022-11-02 14:44:08 +000019from . import test_data_generation
Werner Lewiscff75782022-11-30 16:34:07 +000020from . import bignum_common # pylint: disable=unused-import
Janos Follathb99b0562022-11-02 14:44:08 +000021
Janos Follath0cd89672022-11-09 12:14:14 +000022class BignumModTarget(test_data_generation.BaseTarget):
23 #pylint: disable=abstract-method, too-few-public-methods
Janos Follathb99b0562022-11-02 14:44:08 +000024 """Target for bignum mod test case generation."""
25 target_basename = 'test_suite_bignum_mod.generated'
26
Janos Follath1be322a2022-11-02 14:46:23 +000027# BEGIN MERGE SLOT 1
28
29# END MERGE SLOT 1
30
31# BEGIN MERGE SLOT 2
32
33# END MERGE SLOT 2
34
35# BEGIN MERGE SLOT 3
36
Tom Cosgrove62b20482022-12-01 14:27:37 +000037class BignumModSub(bignum_common.ModOperationCommon, BignumModTarget):
38 """Test cases for bignum mpi_mod_sub()."""
39 symbol = "-"
40 test_function = "mpi_mod_sub"
41 test_name = "mbedtls_mpi_mod_sub"
42 input_style = "fixed"
43 arity = 2
44
Tom Cosgrove62b20482022-12-01 14:27:37 +000045 def result(self) -> List[str]:
46 result = (self.int_a - self.int_b) % self.int_n
Tom Cosgrovef51f9722022-12-05 15:47:40 +000047 # To make negative tests easier, append 0 for success to the
48 # generated cases
49 return [self.format_result(result), "0"]
Tom Cosgrove62b20482022-12-01 14:27:37 +000050
Janos Follath1be322a2022-11-02 14:46:23 +000051# END MERGE SLOT 3
52
53# BEGIN MERGE SLOT 4
54
55# END MERGE SLOT 4
56
57# BEGIN MERGE SLOT 5
Werner Lewise1b6b7c2022-11-29 12:25:05 +000058class BignumModAdd(bignum_common.ModOperationCommon, BignumModTarget):
59 """Test cases for bignum mpi_mod_add()."""
60 count = 0
61 symbol = "+"
62 test_function = "mpi_mod_add"
63 test_name = "mbedtls_mpi_mod_add"
64 input_style = "fixed"
65
66 def result(self) -> List[str]:
67 result = (self.int_a + self.int_b) % self.int_n
68 # To make negative tests easier, append "0" for success to the
69 # generated cases
70 return [self.format_result(result), "0"]
71
Janos Follath1be322a2022-11-02 14:46:23 +000072
73# END MERGE SLOT 5
74
75# BEGIN MERGE SLOT 6
76
77# END MERGE SLOT 6
78
79# BEGIN MERGE SLOT 7
80
81# END MERGE SLOT 7
82
83# BEGIN MERGE SLOT 8
84
85# END MERGE SLOT 8
86
87# BEGIN MERGE SLOT 9
88
89# END MERGE SLOT 9
90
91# BEGIN MERGE SLOT 10
92
93# END MERGE SLOT 10