diff options
author | Hans Nilsson <[email protected]> | 2017-10-31 15:31:47 +0100 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2017-11-10 12:27:47 +0100 |
commit | e394689e748ac582c6b4556e41556137c583b21a (patch) | |
tree | 55c2df330a42b99a9a035e365a5fa44072797911 /lib/crypto/src/crypto.erl | |
parent | 1d0bd5f30cfd95d0977061618a5e483a8606deca (diff) | |
download | otp-e394689e748ac582c6b4556e41556137c583b21a.tar.gz otp-e394689e748ac582c6b4556e41556137c583b21a.tar.bz2 otp-e394689e748ac582c6b4556e41556137c583b21a.zip |
crypto: Add privkey_to_pubkey/2 to get the public key from a priv key in an Engine
Only RSA and DSA so far.
Diffstat (limited to 'lib/crypto/src/crypto.erl')
-rw-r--r-- | lib/crypto/src/crypto.erl | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl index 7510babdde..0d39dcc76e 100644 --- a/lib/crypto/src/crypto.erl +++ b/lib/crypto/src/crypto.erl @@ -42,6 +42,7 @@ -export([public_encrypt/4, private_decrypt/4]). -export([private_encrypt/4, public_decrypt/4]). -export([dh_generate_parameters/2, dh_check/1]). %% Testing see +-export([privkey_to_pubkey/2]). -export([ec_curve/1, ec_curves/0]). -export([rand_seed/1]). %% Engine @@ -1058,6 +1059,16 @@ ec_curves() -> ec_curve(X) -> crypto_ec_curves:curve(X). + +privkey_to_pubkey(Alg, EngineMap) when Alg == rsa; Alg == dss; Alg == ecdsa -> + case privkey_to_pubkey_nif(Alg, format_pkey(Alg,EngineMap)) of + [_|_]=L -> map_ensure_bin_as_int(L); + X -> X + end. + +privkey_to_pubkey_nif(_Alg, _EngineMap) -> ?nif_stub. + + %% %% EC %% @@ -1125,6 +1136,14 @@ ensure_int_as_bin(Int) when is_integer(Int) -> ensure_int_as_bin(Bin) -> Bin. +map_ensure_bin_as_int(List) when is_list(List) -> + lists:map(fun ensure_bin_as_int/1, List). + +ensure_bin_as_int(Bin) when is_binary(Bin) -> + bin_to_int(Bin); +ensure_bin_as_int(E) -> + E. + format_pkey(_Alg, #{engine:=_, key_id:=T}=M) when is_binary(T) -> format_pwd(M); format_pkey(_Alg, #{engine:=_, key_id:=T}=M) when is_list(T) -> format_pwd(M#{key_id:=list_to_binary(T)}); format_pkey(_Alg, #{engine:=_ }=M) -> error({bad_key_id, M}); |