Comments (5)
Thanks. But your construction does not work.
Right direct solution for { a + b, if (a + b) < 2^32; a + b - 2^32 + 1, elsewhere } is
var tmp = syn[1] + 0x1010104;
syn[1] = tmp < 0x100000000 ? tmp : tmp - 0xffffffff;
But in according to math rules summation with modulo (2^32-1) should be less then (2^32-1).
In case syn[1] = 0xfefefefb next syn[1] = 0xffffffff - it is not correspond to mathematical rules.
In case syn[1] = 0xfefefefc next syn[1] = 0x1 - we miss 0x0 in series of integer number.
I think it is mistake in the GOST description. Right summation with modulo (2^32-1) in according to mathematical rules should be { a + b, if (a + b) < 2^32 - 1; a + b - 2^32 + 1, elsewhere }
So right solution
var tmp = syn[1] + 0x1010104;
syn[1] = tmp < 0xffffffff ? tmp : tmp - 0xffffffff;
And this is full equivalent to
syn[1] = signed(unsigned((syn[1] + 0x1010104) & 0xffffffff) % 0xffffffff);
from crypto.
I think it is mistake in the GOST description.
Exactly. GOST's definition of (mod 2^32 - 1)
is not mathematical one. See the attached link to the standard's addendum №4. As for the right code, C-version looks like:
uint64_t value;
// ADD C1 (mod 2^32)
*dst32++ = (uint32_t)0x01010101 + (uint32_t)(*src32++);
// ADD C2 (mod 2^32 - 1)
value = (uint64_t)0x01010104 + (uint64_t)(*src32++);
*dst32++ = (uint32_t)(value + (value >> 32));
I'dont know JS well, but seems that in your code syn[1] = signed(unsigned((syn[1] + 0x1010104) & 0xffffffff) % 0xffffffff)
result of (syn[1] + 0x1010104) & 0xffffffff
is always masked with 0xffffffff
and it's not greater that 2^32
. So, you miss the possible one's wrap.
from crypto.
Clear. value >> 32 - zero if value < 0x100000000 and one if value >= 0x100000000.
(uint32_t)x - equivalent (x & 0xffffffff)
Different for javascript - all numbers are signed. Shift bit operations signed too and 32-bit based. And (value >> 32) == value for any value.
So
var tmp = unsigned(syn[1] + 0x1010104);
syn[1] = signed(tmp < 0x100000000 ? tmp : tmp - 0xffffffff);
Is it right?
from crypto.
var tmp = unsigned(syn[1] + 0x1010104);
syn[1] = signed(tmp < 0x100000000 ? tmp : ((tmp & 0xffffffff) + 1));
Is it the same?
from crypto.
Yes for C/C++. For JS - NO. Because tmp is unsigned and not less then 0x100000000. But operation "&" has 32-bit signed result.
If tmp between 0x100000000 and 0x1fffffffff then (tmp & 0xffffffff) equals (tmp - 0x100000000) for C/C++. Then ((tmp & 0xffffffff) + 1) equals (tmp - 0xffffffff).
I found one more mistake: unsigned(syn[1] + 0x1010104) always less then 0x100000000. Right solution is
var tmp = unsigned(syn[1]) + 0x1010104;
syn[1] = signed(tmp < 0x100000000 ? tmp : tmp - 0xffffffff);
I tested and committed it. Thank you!
from crypto.
Related Issues (17)
- КриптоПРО "Key buffer has wrong size 248 bit"
- Битая ссылка
- КриптоПро импорт PFX файл ошибка "Algorithm not supported" HOT 2
- JSON representation of private key wrongly contains ASN1 header
- Не работает экспорт из КриптоПро Контейнера ГОСТ 2012 HOT 8
- Export SignalCom GOST 2012 key not working HOT 3
- Домен gostcrypto.com не работает? HOT 3
- Hhh
- Github
- JSON of private key written wrongly contains ASN1 header in code
- Ошибка в функции нормализации алгоритмов
- How to get correct signature HOT 2
- Load CryptoPro public.cer: gost.cert.X509(cer) - Error: Algorithm not supported HOT 2
- Поддержка ГОСТ Р.34.12-2015 в GostSecurity HOT 4
- Будет ли модуль для Node.js HOT 13
- Ошибка хэш-кода HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crypto.