Skip to content

Commit 1c50b37

Browse files
committed
Always add final padding during memo encryption.
This avoids weird edge cases, when the message is exactly the length of 16 byte span, and the last byte then gets erroneously treated as padding marker. Note: messages with length of 15 (or 16+15, etc) bytes still get encoded as before, it's only when the edge is pushed and there's no place for a "padding marker", we add 16 more bytes (yes, they all consist of the same 0x0F byte). Example: "1234567890A" = "1234567890A" + ("\x0F" * 1) "1234567890AA" = "1234567890AA" + ("\x0F" * 16) Note: bitcoin-core does it the same way, which makes sense. (As it's the only sane way to distinguish between actual last byte of the message and padding markers.)
1 parent b3f1bda commit 1c50b37

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

bitsharesbase/memo.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ def encode_memo(priv, pub, nonce, message):
8787
checksum = hashlib.sha256(raw).digest()
8888
raw = (checksum[0:4] + raw)
8989
" Padding "
90-
BS = 16
91-
" FIXME: this adds 16 bytes even if not required "
92-
if len(raw) % BS:
93-
raw = _pad(raw, BS)
90+
raw = _pad(raw, 16)
9491
" Encryption "
9592
return hexlify(aes.encrypt(raw)).decode('ascii')
9693

0 commit comments

Comments
 (0)