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
MONGOCRYPT-530 Implement FLE2IndexedEqualityEncryptedValueV2 #594
Conversation
src/mc-fle2-payload-iev-private-v2.h
Outdated
*/ | ||
|
||
typedef struct _mc_FLE2IndexedEqualityEncryptedValueV2_t | ||
mc_FLE2IndexedEqualityEncryptedValueV2_t; |
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.
Can we make this API also agnostic to whether the indexed value is equality vs range, as it is in v1? I think the only function that will need to distinguish them will be in parse()
; the rest of the decrypt logic is the same for both equality and range.
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.
Was planning, but I've added some extra prep for 531 to make that more obvious.
@@ -106,6 +106,7 @@ set (MONGOCRYPT_SOURCES | |||
src/mc-fle2-find-equality-payload.c | |||
src/mc-fle2-find-equality-payload-v2.c | |||
src/mc-fle2-payload-iev.c | |||
src/mc-fle2-payload-iev-v2.c |
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.
src/mc-fle2-payload-iev-v2.c | |
src/mc-fle2-payload-ieev-v2.c |
The V1 struct in mc-fle2-payload-iev.c
uses the same struct mc_FLE2IndexedEncryptedValue_t
to represent both payloads FLE2IndexedEqualityEncryptedValue
and FLE2IndexedRangeEncryptedPayload
.
The new mc_FLE2IndexedEqualityEncryptedValueV2_t
only represents FLE2IndexedEqualityEncryptedValueV2
.
Suggest renaming related files to include extra "e" for equality.
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.
My plan is to repeat that style of having unified accessors, I just haven't gotten to MC-531 yet. I've re-organized the code to make that more obvious.
src/mc-fle2-payload-iev-v2.c
Outdated
&reader, &iev->ServerEncryptedValue, SEV_len, status)); | ||
|
||
// Ignore Metadata block. | ||
BSON_ASSERT (mc_reader_get_remaining_length (&reader) == kMetadataLen); |
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.
BSON_ASSERT (mc_reader_get_remaining_length (&reader) == kMetadataLen); | |
if (mc_reader_get_remaining_length (&reader) != kMetadataLen) { | |
CLIENT_ERR ("Expected remaining payload length %" PRIu64 ", got %" PRIu64, | |
kMetadataLen, | |
mc_reader_get_remaining_length (&reader)); | |
return false; | |
} |
Return an error instead of assert since this is parsing user data.
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.
The reason that it asserts rather than erroring is because we've explicitly calculated out position to be at this location when we created SEV_len
. If the remaining length is even NOT kMetadataLen
at this point then the reader implementation has failed in some spectacular way.
* limitations under the License. | ||
*/ | ||
|
||
#ifndef MONGOCRYPT_INDEXED_ENCRYPTED_VALUE_PRIVATE_V2_H |
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.
#ifndef MONGOCRYPT_INDEXED_ENCRYPTED_VALUE_PRIVATE_V2_H | |
#ifndef MONGOCRYPT_INDEXED_EQUALITY_ENCRYPTED_VALUE_PRIVATE_V2_H |
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.
Negative, see above.
src/mc-fle2-payload-iev-v2.c
Outdated
}; | ||
|
||
#define kMetadataLen 96U // encCount(32) + tag(32) + encZeros(32) | ||
#define kMinServerEncryptedValueLen 17U // IV(16) + EncrtyptCTR(1byte) |
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.
#define kMinServerEncryptedValueLen 17U // IV(16) + EncrtyptCTR(1byte) | |
#define kMinServerEncryptedValueLen 17U // IV(16) + EncryptCTR(1byte) |
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.
Done
src/mc-fle2-payload-iev-private-v2.h
Outdated
* } | ||
* | ||
* ServerEncryptedValue := | ||
* EncryptCTR(ServerEncryptionToken, ClientEncryptedValue) |
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.
* EncryptCTR(ServerEncryptionToken, ClientEncryptedValue) | |
* EncryptCTR(ServerEncryptionToken, K_KeyId || ClientEncryptedValue) |
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.
Done
Merged as 528102f |
No description provided.