[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-dev] ed25519_master_id_public_key -> ed25519 id



On Sun, Oct 10, 2021 at 8:44 AM nusenu <nusenu-lists@xxxxxxxxxx> wrote:
>
> Hi,
>
> given a relay's ed25519_master_id_public_key
> file, is there a simple way to generate the
> 43 chars long ed25519 identity string (also found in fingerprint-ed25519)?
>

Yes, there is!

First you verify that the file is really 64 bytes long, and that the
first 32 bytes of the file are really "== ed25519v1-public: type0
==\0\0\0".

Having done that, you base64-encode the second 32 bytes of the file,
with no "=" padding.

I've attached a lazy little python script.

cheers,
-- 
Nick
#!/usr/bin/python

import sys
import binascii

# requires python 3
assert sys.version_info >= (3,0,0)

try:
    s = open(sys.argv[1], "rb").read()
except IndexError:
    print("Syntax: {} <filename>".format(sys.argv[0]))
    sys.exit(1)

header = b"== ed25519v1-public: type0 ==\0\0\0"

if len(s) != 64 and s[:32] != header:
    print("This wasn't an ed25519_master_id_public_key file.")
    sys.exit(1)
else:
    print(binascii.b2a_base64(s[32:]).decode("ascii").strip().replace("=",""))
_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev