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. Problem of HLS Peer Authentication With GMAC

problem of HLS peer authentication with GMAC

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 twinkle__star , 25 March, 2017
Forums
DLMSDirector

Hi,
I'm developing a smart meter, and referencing this open source code.
I've tested this code with parameters of 9.2.4.8.4 example in Green Book 7 as following:

System Title : 4D4D4D0000BC614E
Frame Counter : 01234567
Initialization Vector : 4D4D4D0000BC614E01234567
Block cipher key (global) : 000102030405060708090A0B0C0D0E0F
Authentication Key : D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF
Security control : 10
CtoS : 4B35366956616759 (“K56iVagY”)
StoC : 503677524A323146 (“P6wRJ21F”)

and GXDLMSChipperingStream class constructor described as following:

GXDLMSChipperingStream gcm = new GXDLMSChipperingStream(
Security.Authentication,
true, // encrypt
new byte[16] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, // block cipher key (AK)
new byte[25] { 0x10, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF 0x4B, 0x35, 0x36, 0x69, 0x56, 0x61, 0x67, 0x59}, // aad (0x10 + AK + CtoS)
new byte[12] { 0x4D, 0x4D, 0x4D, 0x00, 0x00, 0xBC, 0x61, 0x4E, 0x01, 0x23, 0x45, 0x67 }, // IV
null);
byte[] plaintext = new byte[] { 0x4B, 0x35, 0x36, 0x69, 0x56, 0x61, 0x67, 0x59 };
gcm.Write(plaintext);
byte[] result = gcm.FlushFinalBlock();
Console.WriteLine(BitConverter.ToString(a.Tag));

The result tag must be as following in Green Book 7:

T (SC II AK II CtoS) FE1466AFB3DBCD4F9389E2B7
T (SC II AK II StoC) 1A52FE7DD3E72748973C1E28

but actually different resulted.

AA-49-7E-EB-16-BB-49-09-3B-2C-B9-39

What's wrong with my code?
please help...

Profile picture for user Kurumi

Kurumi

9 years 2 months ago

GMAC

Hi,

Do you have latest version from source codes? Then check your Invocation counter. I do not have Blue Book here but in my mind it's reversed.

BR,

Mikko

twinkle__star

9 years 2 months ago

Invocation counter is

Invocation counter is contained in last 4 bytes of AAD field(but I was wrong to comment //IV, Sorry), and I've downloaded source code at 2017-3-24 from Github.
I've thought that there's a problem of parametering gcm.
In the book, only authentication does not contain plaintext, but GXDLMSChipperingStream.Write(byte[]) requires plaintext. I've tested with non-plaintext (new byte[]{}), but result is wrong, too.
Maybe other problem with my parameterizing?
Mr. kurumi, Please help me to get the correct result.
Thank you in advance sincerely.

Profile picture for user Kurumi

Kurumi

9 years 2 months ago

GMAC

Hi,

I check this from Green Book. If I set parameters from the GB 8-2 I get right reply.

target.Ciphering.SystemTitle = Helpers.HexToBytes("4D4D4D0000000001");
server.Ciphering.SystemTitle = Helpers.HexToBytes("4D4D4D0000BC614E");
//Invocation counter
target.Ciphering.InvocationCounter = 0x00000001;
server.Ciphering.InvocationCounter = 0x01234567;
target.Ciphering.BlockCipherKey = Helpers.HexToBytes("000102030405060708090A0B0C0D0E0F");
server.Ciphering.BlockCipherKey = Helpers.HexToBytes("000102030405060708090A0B0C0D0E0F");
target.Ciphering.AuthenticationKey = Helpers.HexToBytes("D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF");
server.Ciphering.AuthenticationKey = Helpers.HexToBytes("D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF");
target.Authentication = Authentication.HighGMAC;
target.CtoSChallenge = Helpers.HexToBytes("4B35366956616759");
server.StoCChallenge = Helpers.HexToBytes("503677524A323146");

http://www.gurux.fi/GuruxDLMSTranslator?pdu=C30181000F0000280000FF01010…

twinkle__star

9 years 2 months ago

Hi, Mr. kurumi.

Hi, Mr. kurumi.
I've tested with 3 Security of Authentication, Encryption, Authentication_Encryption.
And the results of Encryption, Authentication_Encryption were correct.
Only Authentication's result was wrong.
Could you tell me why this happened?

twinkle__star

9 years 2 months ago

Source Code Here.

Source Code Here.

byte[] block_cipher_key = StringToByteArray("000102030405060708090A0B0C0D0E0F");
byte[] authentication_key = StringToByteArray("D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF");
byte[] system_title = StringToByteArray("4D4D4D0000BC614E");
uint frame_counter = 0x01234567;

byte[] plain_text = StringToByteArray("4B35366956616759");

byte[] aad = GetAuthenticatedData(Security.Authentication, authentication_key, plain_text);

GXDLMSChipperingStream gcm = new GXDLMSChipperingStream(
Security.Authentication,
true,
block_cipher_key,
aad,
GetNonse(frame_counter, system_title),
null
);
gcm.Write(plain_text);
byte[] cipher_text = gcm.FlushFinalBlock();

Console.WriteLine($"Tag ({gcm.GetTag().Length}) : {BitConverter.ToString(gcm.GetTag())}");

Result :
Tag (12) : 79-16-34-63-74-90-FD-5C-3A-EA-6A-0F

twinkle__star

9 years 2 months ago

I have solved this problem!!!

================ SOLVED !!!! ==================
I'm very sorry to annoy you about this problem.
I've missed that if Security is Authentication, MUST have not to call Write(byte[]).
The problem is solved.
Thank you for you attention to me.
Please help me in advance.

Profile picture for user Kurumi

Kurumi

9 years 2 months ago

GMAC

Hi,

I'm glad that this is solved.

BR,

Mikko

zhihongzeng

8 years 8 months ago

i want to the soure codes of aes_gmac(for C)

hello :
twinkle__star
I have the same problem with kurumi at work .i have see you tell kurumi "http://www.gurux.fi/GuruxDLMSTranslator?pdu=C30181000F0000280000FF01010…; now i want to the soure codes of aes_gmac,can you give me,my email :[Email removed by Admin] Thank you twinkle__star.
Wish best Regards zhihong zeng.

vineet

8 years 2 months ago

In reply to GMAC by Kurumi

Target challenge does not match

Dear Mikko
I must be making some dumb mistake but I have several times on GuruX Translator .. and ...
The reply for server challenge is correct.
But the reply for the target challenge does not come out to be correct ...

System Title: 4D4D4D0000BC614E
Invocation Counter 01234567
Challenge: 4B35366956616759
Expected Challenge String: FE 14 66 AF B3 DB CD 4F 93 89 E2 B7
GuruX generated Challenge String: 55 C8 77 21 3C D8 0F 7C C4 13 7E 2E

Could you please help me here?
Many thanks.

Profile picture for user pardeepk3264

pardeepk3264

6 years 3 months ago

Please help me to selection

Please help me to selection of function in C language

which function I will used for get a Expected Challenge String. as above mentiond

Profile picture for user Kurumi

Kurumi

6 years 3 months ago

In reply to Please help me to selection by pardeepk3264

Hi RAJPURA,

Hi RAJPURA,

Please, create a new topic if you have a new question.
I'll answer your question there.

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