Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Support of SHA-256 Authentication Mode

support of SHA-256 authentication mode

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By jan.kolar , 14 January, 2020
Forums
Gurux.DLMS

There is problem with SHA-256 authentication mode in Gurux.DLMS.cpp library. If you see method CGXSecure::Secure input data for hash are incorrectly calculated. IEC 62056-5-3 says that in Pass 3 authentication data should be calculated as follows:

SHA-256 (HLS_Secret || SystemTitle-C || SystemTitle-S || StoC || CtoS).

You are calculating hash as follows:
SHA-256 (StoC || HLS Secret)

Very probably also SHA-256 algorithm implemented in CGXDLMSSha256::Encrypt is not correct. I started debug it and see a few weird things. For example if input data are 58 bytes length, method takes first 6 bytes and give them to CGXDLMSSha256::Final method (instead of appending 6 bytes on end). So remaining 58 - 6 = 52 bytes are not taken into account. Also in method CGXDLMSSha256::Update there is dangerous operation on following line:

tmp_len = 64 - (data.GetSize() - data.GetPosition());

Theoretically the result of operation may be negative number. We are storing it into unsigned int variable tmp_len.

jan.kolar

6 years 8 months ago

Implementation of

Implementation of CGXDLMSSha256::Encrypt method is bad. I have replaced it with my own implementation and now I succeed login to meter.
If you want I can send you fixed files. Unfortunately i can upload here only images.

Profile picture for user Kurumi

Kurumi

6 years 8 months ago

Hi Jan,

Hi Jan,

You are right. I just check SHA-256 from Green Book. We'll fix this.

BR,
Mikko

jan.kolar

6 years 8 months ago

Don't forget that input data

Don't forget that input data are composed differently in pass 3 and pass 4.

Profile picture for user Kurumi

Kurumi

6 years 8 months ago

Hi Ján,

Hi Ján,
This is now fixed. Get the latest version. Your name is added to credits.
Thank you for this information.

BR,
Mikko

jan.kolar

6 years 8 months ago

Thank you. I have reviewed

Thank you. I have reviewed your changes. I dont see differentiation between step3 and step4. Please see GreenBook, chapter 9.2.7.4, Table 42.

Pass 3:
SHA-256(HLS_Secret || SystemTitle-C || SystemTitle-S || StoC || CtoS)

Pass 4:
SHA-256(HLS_Secret || SystemTitle-S || SystemTitle-C || CtoS || StoC)

Order of fields is important. The result is different in Pass 3 and Pass 4. You should change order of fields in Pass 4, because the following code in CGXCommunication::InitializeConnection will fail even if response from meter is good.

if (m_Parser->IsAuthenticationRequired())
{
if ((ret = m_Parser->GetApplicationAssociationRequest(data)) != 0 ||
(ret = ReadDataBlock(data, reply)) != 0 ||
(ret = m_Parser->ParseApplicationAssociationResponse(reply.GetData())) != 0)
{
return ret;
}
}

Profile picture for user Kurumi

Kurumi

6 years 8 months ago

Hi Jan,

Hi Jan,

This is now fixed. Get the latest version.

BR,

Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 08/26/2026 - 09:04
    Gurux.DLMS.Python 1.0.203
  • Mon, 08/17/2026 - 11:28
    Gurux.DLMS.Python 1.0.202
  • Mon, 08/17/2026 - 09:47
    gurux.dlms.cpp 9.0.2608.1701
  • Mon, 08/17/2026 - 09:25
    gurux.dlms.c 9.0.2608.1701
  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701

New forum topics

  • Security vulnerability report — request for a private contact (GuruxDLMS.c / ANSI C)
  • Topic: Insufficient Memory Error When Reading Class 7 Profile Generic Objects
  • SN ReadResponse returns all-null values when response spans multiple HDLC frames
  • Gurux.Serial.Android 3.0.6 – CH340 (HL-340) USB-Serial Adapter Not Working,
  • Trying to talk to a L&G E360 meter (Using Python Gurux)
More

Who's new

  • cyby
  • Metin Onan
  • ssv007
  • 3nzol3dur
  • dw772
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin