Hazardous Materials

This segment contains lower-level functions that are not part of the standard API. This allows developers who know what they are doing to write their own constructions. Remember that it is generally ill-advised to try to implement your own cryptography.

#define CRYPTX_ENABLE_HAZMAT    // to enable the hazardous materials
void cryptx_hazmat_aes_ecb_encrypt(const void *block_in, void *block_out, struct cryptx_aes_ctx *ks)

AES-ECB mode single block encryption.

Note

ECB mode is insecure. Use this function as a constructor for other cipher modes, not standalone.

Parameters
  • block_in – Pointer to block of data to encrypt.

  • block_out – Pointer to buffer to write block of encrypted data.

  • ks – Pointer to AES key schedule.

void cryptx_hazmat_aes_ecb_decrypt(const void *block_in, void *block_out, struct cryptx_aes_ctx *ks)

AES-ECB mode single block decryption.

Note

ECB mode is insecure. Use this function as a constructor for other cipher modes, not standalone.

Parameters
  • block_in – Pointer to block of data to decrypt.

  • block_out – Pointer to buffer to write block of decrypted data.

  • ks – Pointer to AES key schedule.

bool cryptx_hazmat_rsa_oaep_encode(const void *plaintext, size_t len, void *encoded, size_t modulus_len, const uint8_t *auth, uint8_t hash_alg)

Optimal Asymmetric Encryption Padding v2.2 Encoder.

Note

An error returned from the encoder usually is related to the size of plaintext. Maximum plaintext length for encoding is the length of the modulus minus twice the length of the selected hash digest minus two more padding bytes.

Parameters
  • plaintext – Pointer to block of data to encode.

  • len – Length of plaintext to encode.

  • encoded – Pointer to buffer to write encoded output.

  • modulus_len – Length of modulus to encode for (ex: length of RSA public modulus).

  • auth – An optional string to include in the encoding (NULL to omit).

  • hash_alg – Algorithm ID of the hash to use.

Returns

True on successful encoding, False on error.

bool cryptx_hazmat_rsa_oaep_decode(const void *encoded, size_t len, void *plaintext, const uint8_t *auth, uint8_t hash_alg)

Optimal Asymmetric Encryption Padding v2.2 Decoder.

Note

An error returned from the decoder usually means the input did not appear to be valid OAEP-encoded data. OAEP 2.2-encoded data starts with the byte 0x00.

Parameters
  • encoded – Pointer to block of data to decode.

  • len – Length of plaintext to encode.

  • plaintext – Pointer to buffer to write decoded output.

  • auth – String included in the encoding (NULL to omit).

  • hash_alg – Algorithm ID of the hash to use.

Returns

True on successful decoding, False on error.

Warning

doxygenfunction: Unable to resolve function “cryptx_hazmat_powmod” with arguments “None”. Candidate function could not be parsed. Parsing error is Error when parsing function declaration. If the function has no return type: Error in declarator or parameters-and-qualifiers Invalid C++ declaration: Expected identifier in nested name, got keyword: void [error at 4] void cryptx_hazmat_powmod (uint8_t size, uint8_t *restrict base, uint24_t exp, const uint8_t *restrict mod) —-^ If the function has a return type: Error in declarator or parameters-and-qualifiers If pointer to member declarator: Invalid C++ declaration: Expected ‘::’ in pointer to member (function). [error at 26] void cryptx_hazmat_powmod (uint8_t size, uint8_t *restrict base, uint24_t exp, const uint8_t *restrict mod) ————————–^ If declarator-id: Invalid C++ declaration: Expecting “,” or “)” in parameters-and-qualifiers, got “b”. [error at 59] void cryptx_hazmat_powmod (uint8_t size, uint8_t *restrict base, uint24_t exp, const uint8_t *restrict mod) ———————————————————–^

CRYPTX_GF2_INTLEN

Defines the length of a galois field for a curve of degree 233.

struct cryptx_ecc_point

Defines a point for use with elliptic curve arithmetic.

struct cryptx_ecc_point cryptx_hazmat_ecc_point_add(cryptx_ecc_point *p, cryptx_ecc_point *q)

Elliptic Curve Point Addition over SECT233k1.

Note

Outputs in p.

Parameters
  • p – Pointer to first point to add.

  • q – Pointer to second point to add.

void cryptx_hazmat_ecc_point_double(cryptx_ecc_point *p)

Elliptic Curve Point Doubling over SECT233k1.

Note

Outputs in p.

Parameters

p – Pointer to point to double.

void cryptx_hazmat_ecc_point_mul_scalar(cryptx_ecc_point *p, const uint8_t *scalar, size_t scalar_bit_width)

Elliptic Curve Scalar Multiplication over SECT233k1.

Note

Outputs in p.

Parameters
  • p – Pointer to point to multiply.

  • scalar – Pointer to scalar.

  • scalar_bit_width – Length, in bits, of the scalar.