helper_ackPayload formating
This commit is contained in:
parent
c5462a00cc
commit
a70b063004
|
@ -1,9 +1,7 @@
|
|||
import hashlib
|
||||
import highlevelcrypto
|
||||
import random
|
||||
import helper_random
|
||||
from binascii import hexlify, unhexlify
|
||||
from struct import pack, unpack
|
||||
from binascii import hexlify
|
||||
from struct import pack
|
||||
from addresses import encodeVarint
|
||||
|
||||
# This function generates payload objects for message acknowledgements
|
||||
|
@ -13,13 +11,16 @@ from addresses import encodeVarint
|
|||
# - level 1: a getpubkey request for a (random) dummy key hash
|
||||
# - level 2: a standard message, encrypted to a random pubkey
|
||||
|
||||
|
||||
def genAckPayload(streamNumber=1, stealthLevel=0):
|
||||
if (stealthLevel == 2): # Generate privacy-enhanced payload
|
||||
# Generate a dummy privkey and derive the pubkey
|
||||
dummyPubKeyHex = highlevelcrypto.privToPub(hexlify(helper_random.randomBytes(32)))
|
||||
dummyPubKeyHex = highlevelcrypto.privToPub(
|
||||
hexlify(helper_random.randomBytes(32)))
|
||||
# Generate a dummy message of random length
|
||||
# (the smallest possible standard-formatted message is 234 bytes)
|
||||
dummyMessage = helper_random.randomBytes(random.randint(234, 800))
|
||||
dummyMessage = helper_random.randomBytes(
|
||||
helper_random.randomrandrange(234, 801))
|
||||
# Encrypt the message using standard BM encryption (ECIES)
|
||||
ackdata = highlevelcrypto.encrypt(dummyMessage, dummyPubKeyHex)
|
||||
acktype = 2 # message
|
||||
|
@ -35,6 +36,7 @@ def genAckPayload(streamNumber=1, stealthLevel=0):
|
|||
acktype = 2 # message
|
||||
version = 1
|
||||
|
||||
ackobject = pack('>I', acktype) + encodeVarint(version) + encodeVarint(streamNumber) + ackdata
|
||||
ackobject = pack('>I', acktype) + encodeVarint(
|
||||
version) + encodeVarint(streamNumber) + ackdata
|
||||
|
||||
return ackobject
|
||||
|
|
Loading…
Reference in New Issue
Block a user