blob: 34d26f9bb06ba1428553adf58d9476523c1f4d13 [file] [log] [blame]
Janos Follathdf8239b2022-11-02 14:40:58 +00001"""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
Janos Follath284672c2022-11-19 14:55:43 +000017from typing import Dict, List
Janos Follathdf8239b2022-11-02 14:40:58 +000018
19from . import test_data_generation
Minos Galanakise9c86a12022-11-09 11:46:47 +000020from . import bignum_common
Janos Follathdf8239b2022-11-02 14:40:58 +000021
Janos Follath0cd89672022-11-09 12:14:14 +000022class BignumModRawTarget(test_data_generation.BaseTarget):
23 #pylint: disable=abstract-method, too-few-public-methods
Janos Follathdf8239b2022-11-02 14:40:58 +000024 """Target for bignum mod_raw test case generation."""
25 target_basename = 'test_suite_bignum_mod_raw.generated'
26
Minos Galanakis855c2282022-11-10 11:33:25 +000027# BEGIN MERGE SLOT 1
28
29# END MERGE SLOT 1
30
31# BEGIN MERGE SLOT 2
32
Gabor Mezei6b3c0c52022-11-23 16:45:05 +010033class BignumModRawSub(bignum_common.ModOperationCommon,
34 BignumModRawTarget):
35 """Test cases for bignum mpi_mod_raw_sub()."""
Gabor Mezeic426d9b2022-11-15 18:51:20 +010036 symbol = "-"
37 test_function = "mpi_mod_raw_sub"
38 test_name = "mbedtls_mpi_mod_raw_sub"
Gabor Mezei6b3c0c52022-11-23 16:45:05 +010039 input_style = "fixed"
40 arity = 2
Gabor Mezeic426d9b2022-11-15 18:51:20 +010041
42 def arguments(self) -> List[str]:
Gabor Mezei6b3c0c52022-11-23 16:45:05 +010043 return [bignum_common.quote_str(n) for n in [self.arg_a,
44 self.arg_b,
45 self.arg_n]
46 ] + self.result()
Gabor Mezeic426d9b2022-11-15 18:51:20 +010047
48 def result(self) -> List[str]:
Gabor Mezei6b3c0c52022-11-23 16:45:05 +010049 result = (self.int_a - self.int_b) % self.int_n
50 return [self.format_result(result)]
Gabor Mezeic426d9b2022-11-15 18:51:20 +010051
Minos Galanakis855c2282022-11-10 11:33:25 +000052# 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
Tom Cosgrove19230092022-11-24 15:56:53 +000064class 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
Tom Cosgrove19230092022-11-24 15:56:53 +000073 def result(self) -> List[str]:
74 result = (self.int_a + self.int_b) % self.int_n
75 return [self.format_result(result)]
76
Minos Galanakis855c2282022-11-10 11:33:25 +000077# END MERGE SLOT 5
78
79# BEGIN MERGE SLOT 6
80
81# END MERGE SLOT 6
82
83# BEGIN MERGE SLOT 7
Janos Follathf352c672022-11-20 13:40:25 +000084
Janos Follath155ad8c2022-11-17 14:42:40 +000085class BignumModRawConvertToMont(bignum_common.ModOperationCommon,
Janos Follath948afce2022-11-17 13:38:56 +000086 BignumModRawTarget):
Minos Galanakisa252f6b2022-11-09 19:23:53 +000087 """ Test cases for mpi_mod_raw_to_mont_rep(). """
Minos Galanakisa252f6b2022-11-09 19:23:53 +000088 test_function = "mpi_mod_raw_to_mont_rep"
89 test_name = "Convert into Mont: "
Janos Follath8ae7a652022-11-19 15:05:19 +000090 symbol = "R *"
Janos Follath6fa3f062022-11-17 20:33:51 +000091 input_style = "arch_split"
Janos Follath1921fd52022-11-18 17:51:02 +000092 arity = 1
Minos Galanakisa252f6b2022-11-09 19:23:53 +000093
Minos Galanakisa252f6b2022-11-09 19:23:53 +000094 def result(self) -> List[str]:
Janos Follath1921fd52022-11-18 17:51:02 +000095 result = (self.int_a * self.r) % self.int_n
96 return [self.format_result(result)]
Minos Galanakisa252f6b2022-11-09 19:23:53 +000097
Minos Galanakis50de0732022-11-09 19:36:16 +000098
Janos Follathf352c672022-11-20 13:40:25 +000099class BignumModRawConvertFromMont(bignum_common.ModOperationCommon,
100 BignumModRawTarget):
Minos Galanakis50de0732022-11-09 19:36:16 +0000101 """ Test cases for mpi_mod_raw_from_mont_rep(). """
Minos Galanakis50de0732022-11-09 19:36:16 +0000102 test_function = "mpi_mod_raw_from_mont_rep"
103 test_name = "Convert from Mont: "
Janos Follath8ae7a652022-11-19 15:05:19 +0000104 symbol = "1/R *"
Janos Follathf352c672022-11-20 13:40:25 +0000105 input_style = "arch_split"
106 arity = 1
Minos Galanakis50de0732022-11-09 19:36:16 +0000107
Janos Follath1921fd52022-11-18 17:51:02 +0000108 def result(self) -> List[str]:
109 result = (self.int_a * self.r_inv) % self.int_n
110 return [self.format_result(result)]
111
Minos Galanakis78665eb2022-12-07 18:10:46 +0000112class BignumModRawModNegate(bignum_common.ModOperationCommon,
113 BignumModRawTarget):
114 """ Test cases for mpi_mod_raw_neg(). """
115 test_function = "mpi_mod_raw_neg"
116 test_name = "Modular negation: "
117 symbol = "(-A)"
118 input_style = "arch_split"
119 arity = 1
Janos Follath1921fd52022-11-18 17:51:02 +0000120
Minos Galanakis78665eb2022-12-07 18:10:46 +0000121 def result(self) -> List[str]:
122 result = (self.int_n - self.int_a) % self.int_n
123 return [self.format_result(result)]
Janos Follath1be322a2022-11-02 14:46:23 +0000124# END MERGE SLOT 7
125
126# BEGIN MERGE SLOT 8
127
128# END MERGE SLOT 8
129
130# BEGIN MERGE SLOT 9
131
132# END MERGE SLOT 9
133
134# BEGIN MERGE SLOT 10
135
136# END MERGE SLOT 10