Skip to content

Instantly share code, notes, and snippets.

@robot-dreams
Last active November 23, 2021 17:28
Show Gist options
  • Save robot-dreams/e5773c6cde579b6ea33a756b2d87cfe1 to your computer and use it in GitHub Desktop.
Save robot-dreams/e5773c6cde579b6ea33a756b2d87cfe1 to your computer and use it in GitHub Desktop.
secp256k1 #920
from ec import *
import hashlib
def accumulate(m, h):
if h.infinity:
m.update(b'\0')
else:
m.update(h.encode_uncompressed())
# Copied from PR
expected = [
0xe4, 0x71, 0x1b, 0x4d, 0x14, 0x1e, 0x68, 0x48,
0xb7, 0xaf, 0x47, 0x2b, 0x4c, 0xd2, 0x04, 0x14,
0x3a, 0x75, 0x87, 0x60, 0x1a, 0xf9, 0x63, 0x60,
0xd0, 0xcb, 0x1f, 0xaa, 0x85, 0x9a, 0xb7, 0xb4
]
# table[i] = 2^i * h
table = []
h = G
for i in range(256):
table.append(h)
h = 2 * h
m = hashlib.sha256()
h = INFINITY
for i in range(37):
accumulate(m, h)
accumulate(m, -h)
h += G
for i in range(256):
# h = 2^i * G
h = table[i]
delta = 2 * h
for j in range(1, 256, 2):
accumulate(m, h)
h = delta + h
assert list(m.digest()) == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment