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

memcpy rather than loop? #39

Closed
redorkulated opened this issue Jul 21, 2016 · 3 comments
Closed

memcpy rather than loop? #39

redorkulated opened this issue Jul 21, 2016 · 3 comments

Comments

@redorkulated
Copy link

Hey,

Great bit of code, should save me from using openssl (hopefully)! Just curious, on this section what made you use a loop rather than just memcpy(output,input,KEYLEN) ?:

static void BlockCopy(uint8_t* output, uint8_t* input) { uint8_t i; for (i=0;i<KEYLEN;++i) { output[i] = input[i]; } }

Of course memcpy itself is a call and then another loop but it might on some computers/compilers it might be more optimised then byte by byte copying

@kokke
Copy link
Owner

kokke commented Jul 21, 2016

Hi Michael,

Thanks for the kinds words :) I appreciate your interest in my project.

Your guess is correct, it is to save a function call and avoid the dependency on memcpy.
The reason is also that it produces the smallest code output using the compilers I've benchmarked. It is a valid candidate for optimization if you are already linking memcpy into the C runtime, sure :)

@redorkulated
Copy link
Author

Very interesting :D , I do love it how you can start to refine C down so much to save on ASM instructions! I have never had to work in an embedded environment but I still love to worry about each byte and instruction being pointlessly wasted.

@kokke
Copy link
Owner

kokke commented Jul 21, 2016

The project started out because I needed the algorithm but didn't have enough space for what I could download on the web :)

There are smaller implementations, which I haven't had the time to review.
Links in this issue:
#17

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