View Source Altcha (Altcha v0.2.0)

Altcha module provides functions for creating and verifying ALTCHA challenges.

Summary

Functions

Converts an algorithm name from binary format to an atom.

Converts an algorithm atom to its binary representation.

Creates a challenge with the specified options.

Extracts parameters from the payload's salt.

Hashes data using the specified algorithm.

Hashes data using the specified algorithm and returns it as a hex string.

Computes HMAC for the given data using the specified algorithm and key.

Creates an HMAC from the data using the specified algorithm and key, and returns it as a hex string.

Generates a specified number of random bytes.

Generates a random integer between 0 and the given maximum value.

Solves a challenge by searching for a number that matches the given challenge.

Verifies if the hash of form fields matches the provided hash.

Verifies the server signature using the payload and HMAC key.

Verifies a solution by checking its validity and comparing it with the expected challenge.

Functions

Link to this function

algorithm_from_binary(algorithm)

View Source
@spec algorithm_from_binary(any()) :: any()

Converts an algorithm name from binary format to an atom.

Link to this function

algorithm_to_binary(algorithm)

View Source

Converts an algorithm atom to its binary representation.

Link to this function

create_challenge(challenge_options)

View Source

Creates a challenge with the specified options.

Extracts parameters from the payload's salt.

Hashes data using the specified algorithm.

Link to this function

hash_hex(data, algorithm)

View Source

Hashes data using the specified algorithm and returns it as a hex string.

Link to this function

hmac_hash(data, algorithm, key)

View Source

Computes HMAC for the given data using the specified algorithm and key.

Link to this function

hmac_hex(data, algorithm, key)

View Source

Creates an HMAC from the data using the specified algorithm and key, and returns it as a hex string.

Generates a specified number of random bytes.

Generates a random integer between 0 and the given maximum value.

Link to this function

solve_challenge(challenge, salt, algorithm \\ :sha256, max \\ 1_000_000, start \\ 0)

View Source

Solves a challenge by searching for a number that matches the given challenge.

Link to this function

verify_fields_hash(form_data, fields, fields_hash, algorithm)

View Source

Verifies if the hash of form fields matches the provided hash.

Link to this function

verify_server_signature(payload, hmac_key)

View Source

Verifies the server signature using the payload and HMAC key.

Link to this function

verify_solution(payload, hmac_key, check_expires \\ true)

View Source

Verifies a solution by checking its validity and comparing it with the expected challenge.