From f517084ba8f5c61e812176c41d331cc072f16935 Mon Sep 17 00:00:00 2001 From: Stefan Andrejevic Date: Thu, 6 Aug 2026 15:13:48 +0200 Subject: [PATCH] fix(ecdsa): use SHA-384 for P-384 keys Select the correct hash algorithm when generating and verifying ECDSA signatures. The previous implementation checked the P-256 curve twice, making the SHA-384 branch unreachable. Replace the duplicated P-256 condition with P-384 so that P-384 keys use SHA-384 as required by the ECDSA specification. --- Gurux.DLMS.python/gurux_dlms/ecdsa/GXEcdsa.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gurux.DLMS.python/gurux_dlms/ecdsa/GXEcdsa.py b/Gurux.DLMS.python/gurux_dlms/ecdsa/GXEcdsa.py index 4180fcf..653020a 100644 --- a/Gurux.DLMS.python/gurux_dlms/ecdsa/GXEcdsa.py +++ b/Gurux.DLMS.python/gurux_dlms/ecdsa/GXEcdsa.py @@ -98,7 +98,7 @@ def sign(self, data): raise ValueError("Invalid private key.") if self.__privateKey.scheme == Ecc.P256: h = hashlib.sha256() - elif self.__privateKey.scheme == Ecc.P256: + elif self.__privateKey.scheme == Ecc.P384: h = hashlib.sha384() else: raise ValueError("Invalid private key scheme.") @@ -184,7 +184,7 @@ def verify(self, signature, data): if self.__publicKey.scheme == Ecc.P256: h = hashlib.sha256() - elif self.__publicKey.scheme == Ecc.P256: + elif self.__publicKey.scheme == Ecc.P384: h = hashlib.sha384() else: raise ValueError("Invalid private key scheme.")