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 4 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 4 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 4 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 4 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 4 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 4 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

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin