AES test vectors#

Test vectors for AES.

exception crypto_condor.vectors.AES.AesVectorsError#

Bases: Exception

Exception for errors importing AES vectors.

class crypto_condor.vectors.AES.AesVectors(mode, key_length, nist, wycheproof)#

Bases: object

A class to load test vectors for AES.

Do not instantiate directly, use load().

Depending on the mode, NIST and Wycheproof test vectors can be loaded.

Parameters:
  • mode (Mode) – The mode of operation to get test vectors of.

  • key_length (KeyLength) – The key length in bits. NIST vectors can be selected by key length.

  • nist (dict[int, list[AesNistVectors]]) – A dictionary of NIST test vectors, indexed by key length.

  • wycheproof (AesWycheproofVectors | None) – An instance of AesWycheproofVectors, if there are Wycheproof vectors for the given mode of operation.

Example

To load the test vectors for AES-128-ECB:

>>> from crypto_condor.vectors.AES import KeyLength, Mode, AesVectors
>>> vectors = AesVectors.load(Mode.ECB, KeyLength.AES128)

To test for compliance use nist vectors, which are grouped by key length.

>>> for key_length in vectors.nist:
...     print(int(key_length))
128

Some modes do not have resilience test vectors.

>>> vectors.wycheproof is None
True

Others do.

>>> vectors = AesVectors.load(Mode.GCM, KeyLength.ALL)
>>> vectors.wycheproof is not None
True
classmethod load(mode, key_length=KeyLength.ALL)#

Loads AES test vectors.

Parameters:
  • mode (Mode) – The mode of operation to get test vectors of.

  • key_length (KeyLength) – The key length in bits. NIST test vectors can be selected by key length.

Returns:

An instance of AesVectors with the corresponding vectors.

class crypto_condor.vectors.AES.AesWycheproofGroup#

Bases: TypedDict

Represents a Wycheproof AES test group.

class crypto_condor.vectors.AES.AesWycheproofTest#

Bases: TypedDict

Represents a single AES Wycheproof test.

class crypto_condor.vectors.AES.AesWycheproofVectors#

Bases: TypedDict

Represents a Wycheproof file of AES test vectors.

enum crypto_condor.vectors.AES.KeyLength(value)#

Bases: IntEnum

Supported key lengths.

AES has three different key lengths: 128, 192, and 256 bits. Since users may want to test a specific key length, this enum defines these three options alongside the KeyLength.ALL option to test all three.

Member Type:

int

Valid values are as follows:

ALL = <KeyLength.ALL: 0>#
AES128 = <KeyLength.AES128: 128>#
AES192 = <KeyLength.AES192: 192>#
AES256 = <KeyLength.AES256: 256>#
enum crypto_condor.vectors.AES.Mode(value)#

Bases: StrEnum

Supported AES modes of operation.

The AES primitive is used with a variety of modes of operation. This enum defines those that are supported by crypto-condor.

Member Type:

str

Valid values are as follows:

ECB = <Mode.ECB: 'ECB'>#
CBC = <Mode.CBC: 'CBC'>#
CBC_PKCS7 = <Mode.CBC_PKCS7: 'CBC-PKCS7'>#
CFB = <Mode.CFB: 'CFB'>#
CFB8 = <Mode.CFB8: 'CFB8'>#
CFB128 = <Mode.CFB128: 'CFB128'>#
CTR = <Mode.CTR: 'CTR'>#
GCM = <Mode.GCM: 'GCM'>#
CCM = <Mode.CCM: 'CCM'>#

The Enum and its members also have the following methods:

classmethod classic_modes()#

Returns a list of all classic modes.

crypto_condor.vectors.AES.load_nist_vectors(mode, key_length)#

Gets NIST test vectors from a list of shortened filenames.

Parameters:
  • mode (Mode) – The mode of operation to get test vectors of.

  • key_length (KeyLength) – The key length in bits. NIST test vectors can be selected by key length.

Returns:

A dictionary containing list of NIST vectors indexed by key length.

Return type:

dict[int, list[AesNistVectors]]

crypto_condor.vectors.AES.load_wycheproof_vectors(mode)#

Loads Wycheproof test vectors.

Parameters:

mode (Mode) – The mode of operation to get test vectors of.

Returns:

The corresponding AesWycheproofVectors or None if there aren’t Wycheproof vectors for the given mode of operation.

Raises:
  • OSError – If an error occurred when opening or reading the file.

  • json.JSONDecodeError – If the vector files has invalid JSON.

Return type:

AesWycheproofVectors | None