PT-163362624 generic hash functions #503
@ -2,7 +2,7 @@
|
||||
|
||||
%% NOTE: When possible deps are referenced by Git ref to ensure consistency between builds.
|
||||
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git",
|
||||
{ref,"19d0e3e"}}}
|
||||
{ref,"6aec14e"}}}
|
||||
]}.
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[{<<"aebytecode">>,
|
||||
{git,"https://github.com/aeternity/aebytecode.git",
|
||||
{ref,"19d0e3ee8493ac2a8f041636445734bade45d65f"}},
|
||||
{ref,"6aec14e64d9ad4dedad98c64b2c16e30af1ea9ea"}},
|
||||
0}].
|
||||
|
@ -149,11 +149,16 @@ global_env() ->
|
||||
{["Map", "member"], Fun([K, Map(K, V)], Bool)},
|
||||
{["Map", "size"], Fun1(Map(K, V), Int)},
|
||||
%% Crypto/Curve operations
|
||||
{["Crypto", "ecverify"], Fun([Hash, Address, SignId], Bool)},
|
||||
{["Crypto", "ecverify"], Fun([Hash, Address, SignId], Bool)},
|
||||
{["Crypto", "sha3"], Fun1(A, Hash)},
|
||||
{["Crypto", "sha256"], Fun1(A, Hash)},
|
||||
{["Crypto", "blake2b"], Fun1(A, Hash)},
|
||||
%% Strings
|
||||
{["String", "length"], Fun1(String, Int)},
|
||||
{["String", "concat"], Fun([String, String], String)},
|
||||
{["String", "sha3"], Fun1(String, Hash)},
|
||||
{["String", "length"], Fun1(String, Int)},
|
||||
{["String", "concat"], Fun([String, String], String)},
|
||||
{["String", "sha3"], Fun1(String, Hash)},
|
||||
{["String", "sha256"], Fun1(String, Hash)},
|
||||
{["String", "blake2b"], Fun1(String, Hash)},
|
||||
%% Conversion
|
||||
{["Int", "to_str"], Fun1(Int, String)},
|
||||
{["Address", "to_str"], Fun1(Address, String)}
|
||||
|
@ -322,6 +322,17 @@ ast_body(?qid_app(["Crypto", "ecverify"], [Msg, PK, Sig], _, _), Icode) ->
|
||||
[ast_body(Msg, Icode), ast_body(PK, Icode), ast_body(Sig, Icode)],
|
||||
[word, word, sign_t()], word);
|
||||
|
||||
ast_body(?qid_app(["Crypto", "sha3"], [Term], [Type], _), Icode) ->
|
||||
generic_hash_primop(?PRIM_CALL_CRYPTO_SHA3, Term, Type, Icode);
|
||||
ast_body(?qid_app(["Crypto", "sha256"], [Term], [Type], _), Icode) ->
|
||||
generic_hash_primop(?PRIM_CALL_CRYPTO_SHA256, Term, Type, Icode);
|
||||
ast_body(?qid_app(["Crypto", "blake2b"], [Term], [Type], _), Icode) ->
|
||||
generic_hash_primop(?PRIM_CALL_CRYPTO_BLAKE2B, Term, Type, Icode);
|
||||
ast_body(?qid_app(["String", "sha256"], [String], _, _), Icode) ->
|
||||
string_hash_primop(?PRIM_CALL_CRYPTO_SHA256_STRING, String, Icode);
|
||||
ast_body(?qid_app(["String", "blake2b"], [String], _, _), Icode) ->
|
||||
string_hash_primop(?PRIM_CALL_CRYPTO_BLAKE2B_STRING, String, Icode);
|
||||
|
||||
%% Strings
|
||||
%% -- String length
|
||||
ast_body(?qid_app(["String", "length"], [String], _, _), Icode) ->
|
||||
@ -599,6 +610,16 @@ prim_call(Prim, Amount, Args, ArgTypes, OutType) ->
|
||||
type_hash= #integer{value = TypeHash}
|
||||
}.
|
||||
|
||||
generic_hash_primop(PrimOp, Term, Type, Icode) ->
|
||||
ArgType = ast_type(Type, Icode),
|
||||
TypeValue = type_value(ArgType),
|
||||
prim_call(PrimOp, #integer{value = 0},
|
||||
[TypeValue, ast_body(Term, Icode)],
|
||||
[typerep, ArgType], word).
|
||||
|
||||
string_hash_primop(PrimOp, String, Icode) ->
|
||||
prim_call(PrimOp, #integer{value = 0}, [ast_body(String, Icode)], [string], word).
|
||||
|
||||
make_type_def(Args, Def, Icode = #{ type_vars := TypeEnv }) ->
|
||||
TVars = [ X || {tvar, _, X} <- Args ],
|
||||
fun(Types) ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user