Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMAC 384 and HMAC 512 keys are not supported #112

Open
LeviSchuck opened this issue Aug 9, 2023 · 0 comments
Open

HMAC 384 and HMAC 512 keys are not supported #112

LeviSchuck opened this issue Aug 9, 2023 · 0 comments

Comments

@LeviSchuck
Copy link

In pycose/keys/symmetric.py, there are several checks on key length which exclude keys for HS384 and HS512 algorithms.

if key_len not in [16, 24, 32]:

Here's how I reproduce this issue

from pycose.keys import SymmetricKey, keyops
from pycose.algorithms import HMAC256, HMAC384, HMAC512
from binascii import hexlify
hashes = [
    ["HS256", HMAC256],
    ["HS384", HMAC384],
    ["HS512", HMAC512]
]

for [name, alg] in hashes:
    print(f"{alg} - {alg.get_digest_length()}")
    key = SymmetricKey.generate_key(alg.get_digest_length())
    key.kid = b"[email protected]"
    key.key_ops = [keyops.MacCreateOp, keyops.MacVerifyOp]
    key.alg = alg
    print(hexlify(key.encode()))

This may be corrected by updating said list to

if key_len not in [16, 24, 32, 48, 64]:

Other implementations do support this length, for example in rust: https://github.com/tramires/cose-rust/blob/main/src/algs.rs#L1006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant