From 9be6f384bae8ebeabc129ede9f8a597de12835d3 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 25 Jul 2019 10:58:40 +0300 Subject: [PATCH] Simplify mgm/incr --- src/cypherpunks.ru/gogost/mgm/mode.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cypherpunks.ru/gogost/mgm/mode.go b/src/cypherpunks.ru/gogost/mgm/mode.go index 2781cbb..20f77c7 100644 --- a/src/cypherpunks.ru/gogost/mgm/mode.go +++ b/src/cypherpunks.ru/gogost/mgm/mode.go @@ -101,10 +101,11 @@ func (mgm *MGM) Overhead() int { } func incr(data []byte) { - if len(data) == 4 { - binary.BigEndian.PutUint32(data, binary.BigEndian.Uint32(data)+1) - } else { - binary.BigEndian.PutUint64(data, binary.BigEndian.Uint64(data)+1) + for i := len(data) - 1; i >= 0; i-- { + data[i]++ + if data[i] != 0 { + return + } } } -- 2.44.0