Skip to content

Commit

Permalink
xmr: bp - get_exponent optim
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 26, 2018
1 parent 3e59ff8 commit 8dae75d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/apps/monero/xmr/bulletproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

BP_LOG_N = 6
BP_N = 1 << BP_LOG_N # 64
BP_M = 4 # maximal number of bulletproofs
BP_M = 16 # maximal number of bulletproofs

ZERO = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
ONE = b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
Expand Down Expand Up @@ -48,6 +48,8 @@

tmp_bf_1 = bytearray(32)
tmp_bf_2 = bytearray(32)
tmp_bf_exp = bytearray(11 + 32 + 4)
tmp_bf_exp_mv = memoryview(tmp_bf_exp)

tmp_pt_1 = crypto.new_point()
tmp_pt_2 = crypto.new_point()
Expand Down Expand Up @@ -270,13 +272,14 @@ def get_exponent(dst, base, idx):
dst = _ensure_dst_key(dst)
salt = b"bulletproof"
idx_size = uvarint_size(idx)
buff = bytearray(len(salt) + 32 + idx_size)
final_size = len(salt) + 32 + idx_size
buff = tmp_bf_exp_mv
memcpy(buff, 0, base, 0, 32)
memcpy(buff, 32, salt, 0, len(salt))
dump_uvarint_b_into(idx, buff, 32 + len(salt))
h1 = crypto.cn_fast_hash(buff)
pt = crypto.hash_to_ec(h1)
crypto.encodepoint_into(pt, dst)
crypto.keccak_hash_into(tmp_bf_1, buff[ : final_size])
crypto.hash_to_ec_into(tmp_pt_1, tmp_bf_1)
crypto.encodepoint_into(tmp_pt_1, dst)
return dst


Expand Down

0 comments on commit 8dae75d

Please sign in to comment.