Skip to content

Commit c3b68cc

Browse files
committed
Fix for to_bytes
1 parent 8d2e78e commit c3b68cc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/Crypto/Protocol/HPKE.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .KDF import _HKDF_extract, _HKDF_expand
88
from .DH import key_agreement, import_x25519_public_key, import_x448_public_key
99
from Crypto.Util.strxor import strxor
10-
from Crypto.Util.number import long_to_bytes
1110
from Crypto.PublicKey import ECC
1211
from Crypto.PublicKey.ECC import EccKey
1312
from Crypto.Hash import SHA256, SHA384, SHA512
@@ -254,7 +253,7 @@ def _key_schedule(self,
254253
suite_id,
255254
self._hashmod)
256255

257-
key_schedule_context = self._mode.to_bytes() + psk_id_hash + info_hash
256+
key_schedule_context = self._mode.to_bytes(1) + psk_id_hash + info_hash
258257

259258
secret = labeled_extract(shared_secret,
260259
b'secret',
@@ -286,7 +285,7 @@ def _key_schedule(self,
286285
return key, base_nonce, exporter_secret
287286

288287
def _new_cipher(self):
289-
nonce = strxor(self._base_nonce, long_to_bytes(self._sequence, self._Nn))
288+
nonce = strxor(self._base_nonce, self._sequence.to_bytes(self._Nn, 'big'))
290289
if self._aead_id in (AEAD.AES128_GCM, AEAD.AES256_GCM):
291290
cipher = AES.new(self._key, AES.MODE_GCM, nonce=nonce, mac_len=self._Nt)
292291
elif self._aead_id == AEAD.CHACHA20_POLY1305:

0 commit comments

Comments
 (0)