defmodule Cryptx do @moduledoc """ The module for working with cryptography. Implements hash-functions and functions for SRP-6a. Don't forget, this module use NIF, write on C++ with Boost library. So, real implements of this functions you find in `c_src` folder. ## Links [https://en.wikipedia.org/wiki/Secure_Remote_Password_protocol](https://en.wikipedia.org/wiki/Secure_Remote_Password_protocol) [https://habrahabr.ru/post/121021/](https://habrahabr.ru/post/121021/) """ @doc """ Calculate sha1-hash for given data """ def sha1(data) do call({:sha1, data}) end @doc """ Calculate sha512-hash for given data """ def sha512(data) do call({:sha512, data}) end @doc """ B are random one time ephemeral keys of the user and host respectively. """ def compute_B(v) do call({:compute_B, v}) end @doc """ u = H(A, B) """ def compute_u(bigA, bigB) do call({:compute_u, bigA, bigB}) end @doc """ K = H(S) """ def compute_K(bigA, v, u, b) do call({:compute_K, bigA, v, u, b}) end @doc """ M = H(H(N) xor H(g), H(I), s, A, B, K) """ def compute_M(bigI, s, bigA, bigB, bigK) do call({:compute_M, bigI, s, bigA, bigB, bigK}) end @doc """ R = H(A, M, K) """ def compute_R(bigA, bigM, bigK) do call({:compute_R, bigA, bigM, bigK}) end @doc """ s = random 512 bit number """ def compute_s() do call({:compute_s}) end @doc """ v = g ^ x % N """ def compute_v(x) do call({:compute_v, x}) end @doc """ Checking equals number with zero (modulo N) """ def is_zero_mod_N(number) do call({:is_zero_mod_N, number}) end @doc false defp call({:sha1, data}) do to_string(CryptxC.sha1(data)) end @doc false defp call({:sha512, data}) do to_string(CryptxC.sha512(data)) end @doc false defp call({:compute_B, v}) do CryptxC.compute_B(v) end @doc false defp call({:compute_u, bigA, bigB}) do to_string(CryptxC.compute_u(bigA, bigB)) end @doc false defp call({:compute_K, bigA, v, u, b}) do to_string(CryptxC.compute_K(bigA, v, u, b)) end @doc false defp call({:compute_M, bigI, s, bigA, bigB, bigK}) do to_string(CryptxC.compute_M(bigI, s, bigA, bigB, bigK)) end @doc false defp call({:compute_R, bigA, bigM, bigK}) do to_string(CryptxC.compute_R(bigA, bigM, bigK)) end @doc false defp call({:compute_s}) do to_string(CryptxC.compute_s()) end @doc false defp call({:compute_v, x}) do to_string(CryptxC.compute_v(x)) end @doc false defp call({:is_zero_mod_N, number}) do CryptxC.is_zero_mod_N(number) end end