-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run_test_vectors.sh: extract Merkle tree 3 pubkey from Merkle tree
The Public Keys given for Merkle 3 in the test vectors are wrong (they don't correspond to the Merkle tree or to the test vectors where they are used). The pubkey in the Merkle tree XML file is correct, so we extract the key from there to run the test vectors that need this key.
- Loading branch information
1 parent
5fd2d75
commit 1c989c3
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
prog='extract_merkle_tree_key.py', | ||
description=('Extracts the ECDSA public key from ' | ||
'an XML file for a Merkle tree')) | ||
parser.add_argument('input_file') | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
tree = ET.parse(args.input_file) | ||
root = tree.getroot() | ||
pk = root.find('body').find('MerkleTree').find('PublicKey') | ||
print(pk.find('point').text) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import sys | ||
|
||
import ecdsa | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
prog='sec1_to_pem.py', | ||
description='Converts a SEC1 encoded public key in hex to PEM format') | ||
parser.add_argument('--curve', default='NIST256p') | ||
parser.add_argument('sec1_hex') | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
curve = getattr(ecdsa, args.curve) | ||
sec1 = bytes.fromhex(args.sec1_hex) | ||
vk = ecdsa.VerifyingKey.from_string(sec1, curve=curve) | ||
print(str(vk.to_pem(), encoding='ascii'), end='') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |