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

mp_int_to_unsigned does not return the number of bytes actually written #20

Closed
lhf opened this issue Jul 11, 2018 · 2 comments
Closed

Comments

@lhf
Copy link

lhf commented Jul 11, 2018

mp_int_to_unsigned does not return the number of bytes actually written to the buffer.

mp_int_to_unsigned calls s_tobin, which does return the number of bytes actually written to the buffer, so the information is available.

One solution is to change mp_int_to_unsigned to

mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int *limit)

but it is a breaking change.

@creachadair
Copy link
Owner

One may call mp_int_unsigned_len(&z) to get the length of the buffer consumed, e.g.,

mp_result len = mp_int_unsigned_len(&z);
unsigned char *buf = malloc(len);
mp_int_to_unsigned(&z, buf, len);

I realize that's an extra call, but it's not a very expensive one, so I'd rather not change the API for this.

@lhf
Copy link
Author

lhf commented Jul 28, 2018

I misread the docs. Sorry for the noise.

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