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