Danger

Nothing here should be used for any security purposes.

  • If you need cryptographic tools in a Python environment use pyca or PyNaCl.

  • If you need efficient and reliable abstract math utilities in a Python-like environment consider using SageMath.

API#

class toy_crypto.wycheproof.Loader(path: Path) None[source]#

Tools for loading Wycheproof test vectors.

Parameters:

path (Path)

classmethod collect_formats(schema: Mapping[str, object]) Mapping[str, str][source]#

Collects format annotation for all string types in schema.

Parameters:

schema (Mapping[str, object]) – The schema from which to collect string format annotations.

Return type:

Mapping[str, str]

Warning

If the same property name is used in different parts of the schema and have distinct formats, which format will be assigned to the single property name is undefined.

load(path: Path | str, *, subdir: str = 'testvectors_v1', strict_validation: bool = False) TestData[source]#

Returns the file data

Parameters:
  • path (Path | str) – relative path to json file with test vectors.

  • subdir (str, default: 'testvectors_v1') – The the subdirectory of wycheproof with the test vector to load.

  • strict_validation (bool, default: False) – If true, fail if schema validation fails.

Raises:
  • Exceptions – if the expected data file can’t be found or read.

  • Exception – if strict_validation is True and schema validation fails.

Return type:

TestData

property root_dir: Path#

The absolute path of the wycheproof root directory.

class toy_crypto.wycheproof.TestCase(test_case: Mapping[str, object]) None[source]#
Parameters:

test_case (Mapping[str, object])

property acceptable: bool#

If the test case is expected to be acceptable.

property comment: str#

The comment for the case.

The comment might be the empty string.

property flags: Set[str]#

The set of flags that are set for the case.

has_flag(flag: str) bool[source]#

True if flag is set for this case.

Parameters:

flag (str)

Return type:

bool

property invalid: bool#

If the test case expected to be invalid.

property other_data: Mapping[str, object]#

The test case data that isn’t captured by known properties.

property result: str#

The expected result of the test

Should be one of “valid”, “invalid”, “acceptable”

property tcId: int#

The test case ID "tcId of the test case

property valid: bool#

If the test case is expected to be valid.

class toy_crypto.wycheproof.TestGroup(group: dict[str, object], formats: Mapping[str, str]) None[source]#

Data that is common to all tests in the group.

Parameters:
  • group (dict[str, object])

  • formats (Mapping[str, str])

property other_data: Mapping[str, object]#

The data that isn’t captured by known properties.

property tests: Iterator[TestCase]#

All of the test cases in the group.

property type: str | None#

The test group type.

class toy_crypto.wycheproof.TestData(data: dict[str, object], formats: Mapping[str, str], schema_path: Path, schema_status: str = 'valid') None[source]#

The object that results from loading a wycheproof JSON file.

Parameters:
  • data (dict[str, object])

  • formats (Mapping[str, str])

  • schema_path (Path)

  • schema_status (str, default: 'valid')

property formats: Mapping[str, str]#

JSON keyword to string format annotation.

Warning

The is not completely reliable.

property notes: Mapping[str, Note]#

The notes for each test case flag.

property schema_file: Path#

The path where the schema file was expected.

The existence of this path does not mean that the file exists at that location.

schema_is_loaded() bool[source]#

True iff the schema file was found and read.

That will be true even if the schema file is itself invalid.

Return type:

bool

schema_is_valid() bool[source]#

True iff the JSON data properly validated against a valid schema.

Note that this can be False if the schema failed to load.

Return type:

bool

property test_count: int | None#

The test count from the JSON “numberOfTests” value.

class toy_crypto.wycheproof.Note(note_name: str, notes: dict[str, object]) None[source]#

Notes on flags for in TestData

Parameters:
  • note_name (str)

  • notes (dict[str, object])

property bug_type: str#

The type of the bug tested for

property cves: Sequence[str]#

A list of potentially related CVEs

property description: str | None#

A description of the flag

property effect: str | None#

The expected effect of failing the test vector

A list of potentially related references

toy_crypto.wycheproof.deserialize_top_level(properties: dict[str, object], formats: Mapping[str, str]) None[source]#

Mutates. Deserializes root level members according for format

Any string values in HexBytes format is converted to bytes, and any in BigInt format is converted to an signed int.

Parameters:
  • properties (dict[str, object])

  • formats (Mapping[str, str])

Return type:

None