Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
32b99b79
Commit
32b99b79
authored
Apr 09, 2019
by
poljar
Browse files
python: Add support for the long KDF MAC calculation.
parent
659eb34f
Changes
2
Hide whitespace changes
Inline
Side-by-side
python/olm/sas.py
View file @
32b99b79
...
...
@@ -220,3 +220,38 @@ class Sas(object):
)
)
return
bytes_to_native_str
(
ffi
.
unpack
(
mac_buffer
,
mac_length
))
@
other_pubkey_set
def
calculate_mac_long_kdf
(
self
,
message
,
extra_info
):
# type: (str, str) -> str
"""Generate a message authentication code based on the shared secret.
This function should not be used unless compatibility with an older
non-tagged Olm version is required.
Args:
message (str): The message to produce the authentication code for.
extra_info (str): Extra information to mix in when generating the
MAC
Raises OlmSasError on failure.
"""
byte_message
=
to_bytes
(
message
)
byte_info
=
to_bytes
(
extra_info
)
mac_length
=
lib
.
olm_sas_mac_length
(
self
.
_sas
)
mac_buffer
=
ffi
.
new
(
"char[]"
,
mac_length
)
self
.
_check_error
(
lib
.
olm_sas_calculate_mac_long_kdf
(
self
.
_sas
,
ffi
.
from_buffer
(
byte_message
),
len
(
byte_message
),
ffi
.
from_buffer
(
byte_info
),
len
(
byte_info
),
mac_buffer
,
mac_length
)
)
return
bytes_to_native_str
(
ffi
.
unpack
(
mac_buffer
,
mac_length
))
python/tests/sas_test.py
View file @
32b99b79
...
...
@@ -80,3 +80,20 @@ class TestClass(object):
alice_mac
=
sas_alice
.
calculate_mac
(
message
,
extra_info
)
assert
alice_mac
==
expected_mac
def
test_long_mac_generating
(
self
):
sas_alice
=
Sas
()
sas_bob
=
Sas
()
with
pytest
.
raises
(
OlmSasError
):
sas_alice
.
calculate_mac_long_kdf
(
MESSAGE
,
EXTRA_INFO
)
sas_alice
.
set_their_pubkey
(
sas_bob
.
pubkey
)
sas_bob
.
set_their_pubkey
(
sas_alice
.
pubkey
)
alice_mac
=
sas_alice
.
calculate_mac_long_kdf
(
MESSAGE
,
EXTRA_INFO
)
bob_mac
=
sas_bob
.
calculate_mac_long_kdf
(
MESSAGE
,
EXTRA_INFO
)
bob_short_mac
=
sas_bob
.
calculate_mac
(
MESSAGE
,
EXTRA_INFO
)
assert
alice_mac
==
bob_mac
assert
alice_mac
!=
bob_short_mac
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment