Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 1 | """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 | |
| 17 | from typing import List |
| 18 | |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 19 | from . import test_data_generation |
Gabor Mezei | bd23f3b | 2023-01-25 18:09:49 +0100 | [diff] [blame] | 20 | from . import bignum_common |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 21 | |
| 22 | class 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 Mezei | bd23f3b | 2023-01-25 18:09:49 +0100 | [diff] [blame] | 26 | |
| 27 | class 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 Mezei | b687508 | 2023-01-31 14:35:17 +0100 | [diff] [blame] | 36 | moduli = ["fffffffffffffffffffffffffffffffeffffffffffffffff"] # type: List[str] |
Gabor Mezei | bd23f3b | 2023-01-25 18:09:49 +0100 | [diff] [blame] | 37 | |
| 38 | input_values = [ |
| 39 | "0", "1", |
| 40 | |
Gabor Mezei | 5c9f401 | 2023-02-13 14:15:08 +0100 | [diff] [blame] | 41 | # Modulus - 1 |
| 42 | "fffffffffffffffffffffffffffffffefffffffffffffffe", |
| 43 | |
Gabor Mezei | bd23f3b | 2023-01-25 18:09:49 +0100 | [diff] [blame] | 44 | # First 8 number generated by random.getrandbits(384) - seed(2,2) |
| 45 | ("cf1822ffbc6887782b491044d5e341245c6e433715ba2bdd" |
| 46 | "177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), |
| 47 | ("ffed9235288bc781ae66267594c9c9500925e4749b575bd1" |
| 48 | "3653f8dd9b1f282e4067c3584ee207f8da94e3e8ab73738f"), |
| 49 | ("ef8acd128b4f2fc15f3f57ebf30b94fa82523e86feac7eb7" |
| 50 | "dc38f519b91751dacdbd47d364be8049a372db8f6e405d93"), |
| 51 | ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045" |
| 52 | "defc044a09325626e6b58de744ab6cce80877b6f71e1f6d2"), |
| 53 | ("2d3d854e061b90303b08c6e33c7295782d6c797f8f7d9b78" |
| 54 | "2a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"), |
| 55 | ("fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f1" |
| 56 | "5c14bc4a829e07b0829a48d422fe99a22c70501e533c9135"), |
| 57 | ("97eeab64ca2ce6bc5d3fd983c34c769fe89204e2e8168561" |
| 58 | "867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2"), |
| 59 | ("bd143fa9b714210c665d7435c1066932f4767f26294365b2" |
| 60 | "721dea3bf63f23d0dbe53fcafb2147df5ca495fa5a91c89b"), |
| 61 | |
| 62 | # Next 2 number generated by random.getrandbits(192) |
| 63 | "47733e847d718d733ff98ff387c56473a7a83ee0761ebfd2", |
| 64 | "cbd4d3e2d4dec9ef83f0be4e80371eb97f81375eecc1cb63" |
| 65 | ] |
| 66 | |
| 67 | @property |
| 68 | def arg_a(self) -> str: |
| 69 | return super().format_arg('{:x}'.format(self.int_a)).zfill(2 * self.hex_digits) |
| 70 | |
| 71 | def result(self) -> List[str]: |
| 72 | result = self.int_a % self.int_n |
| 73 | return [self.format_result(result)] |
| 74 | |
| 75 | @property |
| 76 | def is_valid(self) -> bool: |
| 77 | return True |