Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ltc_ecc_mul2add.c integer sign issue #90

Closed
karel-m opened this issue Jan 3, 2016 · 5 comments
Closed

ltc_ecc_mul2add.c integer sign issue #90

karel-m opened this issue Jan 3, 2016 · 5 comments
Milestone

Comments

@karel-m
Copy link
Member

karel-m commented Jan 3, 2016

I got the following compiler warning:

"src/ltc/pk/ecc/ltc_ecc_mul2add.c", line 137: warning #2068-D: integer
          conversion resulted in a change of sign
    for (x = -1;; ) {

The code in question:

043  unsigned       bitbufA, bitbufB, lenA, lenB, len, x, y, nA, nB, nibble;
...
136  /* for every byte of the multiplicands */
137  for (x = -1;; ) {
138     /* grab a nibble */
139     if (++nibble == 4) {
140        ++x; if (x == len) break;
141        bitbufA = tA[x];
142        bitbufB = tB[x];
143        nibble  = 0;
144     }

It seems that we are assigning -1 to unsigned integer.

I have not investigated yet what would be the best fix.

--Karel

@sjaeckel
Copy link
Member

sjaeckel commented Jan 5, 2016

well, very stupid idea but have you tried for (x = 0-1;; )? :-)

@karel-m
Copy link
Member Author

karel-m commented Jan 10, 2016

Looking at the code - https://github.com/libtom/libtomcrypt/blob/develop/src/pk/ecc/ltc_ecc_mul2add.c#L37 - it seems that changing the type of x from unsigned to int might be better.

Something like this (not tested yet):

  ecc_point     *precomp[16];
  unsigned       bitbufA, bitbufB, lenA, lenB, len, nA, nB, nibble;
  int            x, y;
  unsigned char *tA, *tB;

Note: y is changed just for consistency as both x and y are used for indices.

@sjaeckel
Copy link
Member

Or should we probably rewrite the implementation to be more clear?
this looks like very complicated but I suppose there would be a cleaner way to write this

137  for (x = -1;; ) {
138     /* grab a nibble */
139     if (++nibble == 4) {
140        ++x; if (x == len) break;

@karel-m
Copy link
Member Author

karel-m commented Jan 14, 2016

I have tested that the following works without warnings:

  ecc_point     *precomp[16];
  unsigned       bitbufA, bitbufB, lenA, lenB, len, nA, nB, nibble;
  int            x, y;
  unsigned char *tA, *tB;

Should I send a PR or do we want to change the implementation?

@sjaeckel
Copy link
Member

I'm fine with the fix

karel-m added a commit to DCIT/perl-CryptX that referenced this issue Jan 24, 2016
@sjaeckel sjaeckel added this to the v2.0.0 milestone Mar 10, 2016
@karel-m karel-m closed this as completed Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants