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

  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701
  • Thu, 07/23/2026 - 16:19
    gurux.dlms.java 4.0.96
  • Thu, 07/09/2026 - 14:34
    Gurux.DLMS.Python 1.0.201
  • Fri, 06/26/2026 - 16:32
    Gurux.Service 3.0.2606.2601
  • Wed, 06/24/2026 - 08:36
    Gurux.DLMS.Python 1.0.200

New forum topics

  • Version mismatch between Gurux.DLMS 9.x and Gurux.Common/Gurux.Serial 8.x
  • Service not known error on gprs communication
  • Help Needed: Interfacing Saral 100 Energy Meter with Microcontroller via RS232
  • Connecting Meter to Agent via serial
  • Reading block profile with Compact array
More

Who's new

  • Wooplke djoole…
  • Duaneduh
  • ClaytonPap
  • sAYgntkdaTjhgpvfz
  • HenryEneno
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin