ExSwan.Crypto (exswan v0.1.0)

View Source

Cryptographic utilities for WebAuthn operations.

This module provides functions for signature verification, public key handling, and other cryptographic operations required by the WebAuthn specification.

Summary

Functions

Computes the signed data for WebAuthn assertion verification.

Verifies a digital signature using the provided public key and data.

Verify a COSE signature over msg using a COSE_Key map (already CBOR-decoded). sig is the signature bytes as delivered by COSE (raw r||s for ECDSA; 64B for Ed25519; PKCS#1/RSASSA-PSS for RSA). alg is the COSE alg int (e.g. -7 for ES256).

Functions

compute_signed_data(authenticator_data, client_data_hash)

@spec compute_signed_data(binary(), binary()) :: binary()

Computes the signed data for WebAuthn assertion verification.

Concatenates authenticator data and client data hash as per WebAuthn spec.

verify_signature(signature, signed_data, public_key_map, algorithm)

@spec verify_signature(binary(), binary(), map(), integer()) :: :ok | {:error, atom()}

Verifies a digital signature using the provided public key and data.

Parameters

  • signature - The signature bytes to verify
  • signed_data - The data that was signed
  • public_key_map - COSE public key map from credential
  • algorithm - Signature algorithm identifier

Returns

  • :ok if signature is valid
  • {:error, reason} if verification fails

Examples

public_key = %{1 => 2, 3 => -7, -1 => 1, -2 => x_coord, -3 => y_coord}
{:ok} = ExSwan.Crypto.verify_signature(signature, data, public_key, -7)

verify_signature_with_cose(msg, sig, cose_key, alg)

Verify a COSE signature over msg using a COSE_Key map (already CBOR-decoded). sig is the signature bytes as delivered by COSE (raw r||s for ECDSA; 64B for Ed25519; PKCS#1/RSASSA-PSS for RSA). alg is the COSE alg int (e.g. -7 for ES256).