sqrl.crypto module

class sqrl.crypto.Ed25519(public_key, private_key, msg)[source]

Bases: object

Utility class for signing and verifying ed25519 signatures.

More information about ed25519 can be found at http://ed25519.cr.yp.to/.

Parameters:
  • public_key (bytes) – Key used for verifying signature.
  • private_key (bytes) – Key used for signing data.
  • msg (bytes) – Binary data for which to generate the signature.
is_signature_valid(other_signature)[source]

Check if other_signature is a valid signature for the provided message.

Returns:Boolean indicating whether validation has succeeded.
Return type:bool
sign_data()[source]

Generate ed25519 signature for the provided data.

Returns:ed25519 signature
Return type:bytes
class sqrl.crypto.HMAC(nut, data)[source]

Bases: object

Utility class for generating and verifying HMAC signatures.

This class relies on Django’s built in salted_hmac() to compute actual HMAC values by using SECRET_KEY as key.

Parameters:
  • nut (SQRLNut) – Nut from which necessary data is extracted to add a salt value to the HMAC input data. Currently only models.SQRLNut.session_key is used.
  • data (OrderedDict) – Dict for which to either compute or validate HMAC signature.
is_signature_valid(other_signature)[source]

Check if the other_signature is a valid signature for the provided data and the nut.

Returns:Boolean indicating whether validation has succeeded.
Return type:bool
sign_data()[source]

Generate HMAC signature for the provided data.

Note

max key is ignored in the input data if that key is present.

Returns:Binary signature of the data
Return type:bytes
sqrl.crypto.generate_randomness(bytes=32)[source]

Generate random sample of specified size bytes.

Parameters:bytes (int, optional) – Number of bytes to generate random sample
Returns:Base64.encode() encoded random sample
Return type:str