VAITP Dataset

← Back to the dataset

CVE-2016-9243

HKDF returns empty byte-string for lengths less than digest_size.

  • CVSS 7.5
  • CWE- misuse of cryptographic API
  • Cryptographic
  • Local

HKDF in cryptography before 1.5.2 returns an empty byte-string if used with a length less than algorithm.digest_size.

CVSS base score
7.5
Published
2017-03-27
OWASP
A02 Cryptographic Failures
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Cryptographic
Subcategory
Cryptographic Implementation Error
Accessibility scope
Local
Impact
Information Disclosure
Affected component
cryptography
Fixed by upgrading
Yes

Solution

Upgrade to HKDF version 1.5.2 or later.

Vulnerable code sample

from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes

hkdf = HKDF(
    algorithm=hashes.SHA256(),
    length=20,
    salt=None,
    info=b''
)

input_key_material = b'some_key_material'
derived_key = hkdf.derive(input_key_material)

print(derived_key)

Patched code sample

import os
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes

salt = os.urandom(16)
info = b'some_context_info'

hkdf = HKDF(
    algorithm=hashes.SHA256(),
    length=20,
    salt=salt,
    info=info
)

input_key_material = b'some_key_material'
derived_key = hkdf.derive(input_key_material)

print(derived_key)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Payload

input_key_material = b'some_key_material'
length = 20  # Length less than SHA256.digest_size (32)

Cite this entry

@misc{vaitp:cve20169243,
  title        = {{HKDF returns empty byte-string for lengths less than digest_size.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2017},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2016-9243},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2016-9243/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.