blob: 7e1dafce48921efb8d383e475c4d9105d0436515 [file] [log] [blame]
Gabor Mezei95ecaaf2023-01-16 16:53:29 +01001"""Framework classes for generation of ecp 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 List
18
19from . import test_case
20from . import test_data_generation
Gabor Mezeibd23f3b2023-01-25 18:09:49 +010021from . import bignum_common
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010022
23class EcpTarget(test_data_generation.BaseTarget):
24 #pylint: disable=abstract-method, too-few-public-methods
25 """Target for ecp test case generation."""
26 target_basename = 'test_suite_ecp.generated'
Gabor Mezeibd23f3b2023-01-25 18:09:49 +010027
28class EcpP192R1Raw(bignum_common.ModOperationCommon,
29 EcpTarget):
30 """Test cases for ecp quasi_reduction()."""
31 symbol = "-"
32 test_function = "ecp_mod_p192_raw"
33 test_name = "ecp_mod_p192_raw"
34 input_style = "fixed"
35 arity = 1
36
37 moduli = [ "fffffffffffffffffffffffffffffffeffffffffffffffff" ] # type: List[str]
38
39 input_values = [
40 "0", "1",
41
42 # First 8 number generated by random.getrandbits(384) - seed(2,2)
43 ("cf1822ffbc6887782b491044d5e341245c6e433715ba2bdd"
44 "177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"),
45 ("ffed9235288bc781ae66267594c9c9500925e4749b575bd1"
46 "3653f8dd9b1f282e4067c3584ee207f8da94e3e8ab73738f"),
47 ("ef8acd128b4f2fc15f3f57ebf30b94fa82523e86feac7eb7"
48 "dc38f519b91751dacdbd47d364be8049a372db8f6e405d93"),
49 ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045"
50 "defc044a09325626e6b58de744ab6cce80877b6f71e1f6d2"),
51 ("2d3d854e061b90303b08c6e33c7295782d6c797f8f7d9b78"
52 "2a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"),
53 ("fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f1"
54 "5c14bc4a829e07b0829a48d422fe99a22c70501e533c9135"),
55 ("97eeab64ca2ce6bc5d3fd983c34c769fe89204e2e8168561"
56 "867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2"),
57 ("bd143fa9b714210c665d7435c1066932f4767f26294365b2"
58 "721dea3bf63f23d0dbe53fcafb2147df5ca495fa5a91c89b"),
59
60 # Next 2 number generated by random.getrandbits(192)
61 "47733e847d718d733ff98ff387c56473a7a83ee0761ebfd2",
62 "cbd4d3e2d4dec9ef83f0be4e80371eb97f81375eecc1cb63"
63 ]
64
65 @property
66 def arg_a(self) -> str:
67 return super().format_arg('{:x}'.format(self.int_a)).zfill(2 * self.hex_digits)
68
69 def result(self) -> List[str]:
70 result = self.int_a % self.int_n
71 return [self.format_result(result)]
72
73 @property
74 def is_valid(self) -> bool:
75 return True