forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 23
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
DX-67209 updated aes_encrypt/decrypt #29
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16ebb1f
DX-67209 updated aes_encrypt/decrypt
xxlaykxx 37cfd5c
DX-67209 fixed tests
xxlaykxx ce60e00
fixed tests
xxlaykxx 68ee269
fixed tests
xxlaykxx 3b3b257
DX-67209 chaged error handling, fixed tests
xxlaykxx e3822ff
move determining of cipher algo to separate method
xxlaykxx c92c8bc
Add more unit tests
xxlaykxx 3e06924
fixed tests
xxlaykxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,8 +306,6 @@ CAST_NUMERIC_FROM_VARBINARY(double, arrow::DoubleType, FLOAT8) | |
#undef GDV_FN_CAST_VARCHAR_INTEGER | ||
#undef GDV_FN_CAST_VARCHAR_REAL | ||
|
||
static constexpr int64_t kAesBlockSize = 16; // bytes | ||
|
||
GANDIVA_EXPORT | ||
const char* gdv_fn_aes_encrypt(int64_t context, const char* data, int32_t data_len, | ||
const char* key_data, int32_t key_data_len, | ||
|
@@ -318,6 +316,15 @@ const char* gdv_fn_aes_encrypt(int64_t context, const char* data, int32_t data_l | |
return ""; | ||
} | ||
|
||
int64_t kAesBlockSize = 0; | ||
if (key_data_len == 16 || key_data_len == 24 || key_data_len == 32) { | ||
kAesBlockSize = static_cast<int64_t>(key_data_len); | ||
} else { | ||
gdv_fn_context_set_error_msg(context, "invalid key length"); | ||
*out_len = 0; | ||
return nullptr; | ||
Comment on lines
+320
to
+325
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't the helper functions already check the length? I think it would be better to just do the check in one place since the code would be easier to read and better tested. It doesn't look like this path is being tested since the unit tests call the helper functions. |
||
} | ||
|
||
*out_len = | ||
static_cast<int32_t>(arrow::bit_util::RoundUpToPowerOf2(data_len, kAesBlockSize)); | ||
char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len)); | ||
|
@@ -330,7 +337,7 @@ const char* gdv_fn_aes_encrypt(int64_t context, const char* data, int32_t data_l | |
} | ||
|
||
try { | ||
*out_len = gandiva::aes_encrypt(data, data_len, key_data, | ||
*out_len = gandiva::aes_encrypt(data, data_len, key_data, key_data_len, | ||
reinterpret_cast<unsigned char*>(ret)); | ||
} catch (const std::runtime_error& e) { | ||
gdv_fn_context_set_error_msg(context, e.what()); | ||
|
@@ -351,6 +358,15 @@ const char* gdv_fn_aes_decrypt(int64_t context, const char* data, int32_t data_l | |
return ""; | ||
} | ||
|
||
int64_t kAesBlockSize = 0; | ||
if (key_data_len == 16 || key_data_len == 24 || key_data_len == 32) { | ||
kAesBlockSize = static_cast<int64_t>(key_data_len); | ||
} else { | ||
gdv_fn_context_set_error_msg(context, "invalid key length"); | ||
*out_len = 0; | ||
return nullptr; | ||
} | ||
|
||
*out_len = | ||
static_cast<int32_t>(arrow::bit_util::RoundUpToPowerOf2(data_len, kAesBlockSize)); | ||
char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len)); | ||
|
@@ -363,14 +379,14 @@ const char* gdv_fn_aes_decrypt(int64_t context, const char* data, int32_t data_l | |
} | ||
|
||
try { | ||
*out_len = gandiva::aes_decrypt(data, data_len, key_data, | ||
*out_len = gandiva::aes_decrypt(data, data_len, key_data, key_data_len, | ||
reinterpret_cast<unsigned char*>(ret)); | ||
} catch (const std::runtime_error& e) { | ||
gdv_fn_context_set_error_msg(context, e.what()); | ||
*out_len = 0; | ||
return nullptr; | ||
} | ||
|
||
ret[*out_len] = '\0'; | ||
return ret; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could be combined with the other similar code below into a helper function.