-
Notifications
You must be signed in to change notification settings - Fork 103
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
Add SHA256 utility implementation #408
Add SHA256 utility implementation #408
Conversation
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the things I've pointed out inline, we should also add tests for this implementation.
All of that said, the idea here is good.
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Thanks for the comments. I hadn't finished doing code style last night, just wanted to make sure this was open as draft for the rep2011 discussion today. Agreed, tests necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emersonknapp @clalancette quick question, why we are not using openssl to avoid re-implementing the function in rcutils? i was thinking that would be more cost effective for maintenance? Do we want to avoid the dependency on that intentionally? just a question.
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Yes, the motivation is that we want to use this function in RCL, which does not have a direct dependency on OpenSSL. ros2-security does have the OpenSSL dependency, but not all installations will enable that feature, but type version hashing will be built into rcl. @wjwwood may also have more input on the reason |
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few comments, but they are all pretty minor. Overall this looks pretty good to me.
src/sha256.c
Outdated
for (i = 0; i < len; ++i) { | ||
ctx->data[ctx->datalen] = data[i]; | ||
ctx->datalen++; | ||
if (ctx->datalen == 64) { | ||
sha256_transform(ctx, ctx->data); | ||
ctx->bitlen += 512; | ||
ctx->datalen = 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is worth it, but we could probably optimize this. In particular, we could memcpy
64 bytes at a time into ctx->data
(dealing with the special case of the first block and the last block), calling sha256_transform
on each 64-byte block we complete.
I'll leave it up to you whether you think that improvement is worth it and you want to try it. This is not a blocking comment from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave block-copy implementation a go. The tests still pass so it seems all right. I don't have a performance comparison but maybe it looks better this way.
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for iterating. This looks good to me with green CI.
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Gist: https://gist.githubusercontent.com/emersonknapp/e2b18a4fab8fcd32f47ceb057768b8e8/raw/fddd335b1bc03a0c5381e82c3b3989fae80e2d5f/ros2.repos |
You can ignore that failure; it is fixed in ros2/rclcpp#2092 . |
OK then 👍, I don't have merge access on this repo so that's up to you now! Thanks for the reviews |
To be used for REP-2011 type version hashing.
Simple sha256 implementation to generate a 256-byte message digest for any data. Implementation originally copied from Brad Conte https://github.com/B-Con/crypto-algorithms, with modifications to fit code style and fix compiler warnings.
Prereq for ros2/rcl#1027
Part of ros2/ros2#1159