strap v0.1.0 Strap
A module for using SRP (Secure Remote Password) versions 6 and 6a in Elixir.
Link to this section Summary
Functions
Creates a client structure
Returns known-good primes and generators as defined in RFC5054
Creates a protocol structure
Returns the public key for a given client or server
Creates a server structure
Generates a session key for communication with the remote counterparty
Creates a verifier value that could be sent to the server, e.g. during account creation, without ever sharing the user password
Same as verifier/1
, but can be used only with a protocol,
not a full client. Could be used, e.g. on the server if
the server is supposed to verify characteristics of the user’s
password before creating a verifier
Link to this section Types
client() :: {:client, protocol(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
protocol() :: {srp_version(), binary(), non_neg_integer(), non_neg_integer(), hash_fn()}
server() :: {:server, protocol(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
Link to this section Functions
client(protocol(), binary(), binary(), bin_number(), bin_number()) :: client()
Creates a client structure.
Parameters
- protocol: a protocol structure created by
protocol/4
. - username: a
t:String.t
ort:binary
username. - password: a
t:String.t
ort:binary
password. - salt: the salt,
t:String.t
ort:binary
, as provided from the server. - private: the private key for the client; if not provided, a 256-bit secure random value will be generated.
Returns
A client structure, for use with public_key/1
and session_key/2
.
Notes
The username and password are not stored in the resulting structure, but a hash of their values is stored.
Returns known-good primes and generators as defined in RFC5054.
The following bit-sizes are defined: 1024, 1536, 2048, 3072, 4096, 6144, 8192.
Parameters
- bit_size: the size in bits of the prime group
Returns
Tuple of the form {<<prime :: binary>>, generator}
protocol(srp_version(), binary(), bin_number(), hash_types()) :: protocol()
Creates a protocol structure.
Parameters
- srp_version: Either
:srp6
or:srp6a
- prime: A binary string representing the prime
N
value - generator: The generator
g
integer - hash: One of the hash atoms supported by
:crypto.hash/2
or afn/1
that takes ant:iodata
value and returns a binary hash of that value.
Returns
Returns the public key for a given client or server.
Parameters
- client_server: either a client or server structure, from which the public key will be produced.
Returns
A binary representation of the public key.
server(protocol(), bin_number(), bin_number()) :: server()
Creates a server structure.
Parameters
- protocol: a protocol structure created by
protocol/4
. - verifier: the verifier value, either
t:integer
ort:binary
. - private: the private key for the server; if not provided, a 256-bit secure random value will be generated.
Returns
A server structure, for use with public_key/1
and session_key/2
.
session_key(client() | server(), bin_number()) :: {:error, atom()} | {:ok, binary()}
Generates a session key for communication with the remote counterparty.
Parameters
- client_server: either a client or server structure.
- counterparty_public: the counterparty’s public value.
Returns
Either:
{:ok, session_key}
: if the session key creation was successful{:error, reason}
: if the session key creation was unsuccesful
Session key creation can be unsuccessful if certain mathematical properties do not hold, compromising the security of unshared secrets or future communication.
Creates a verifier value that could be sent to the server, e.g. during account creation, without ever sharing the user password.
Parameters
- client: a client, created previously.
Returns
A binary string of the verifier.
verifier(protocol(), binary(), binary(), bin_number()) :: binary()
Same as verifier/1
, but can be used only with a protocol,
not a full client. Could be used, e.g. on the server if
the server is supposed to verify characteristics of the user’s
password before creating a verifier.
Parameters
- protocol: a protocol object created with
protocol/4
. - username: the username.
- password: the password.
- salt: the salt.
Returns
A binary string of the verifier.