check if two data blobs are equal, where the time taken should not depend on the
contents of either blob.
**/
-_PUBLIC_ int data_blob_cmp_const_time(const DATA_BLOB *d1, const DATA_BLOB *d2)
+_PUBLIC_ bool data_blob_equal_const_time(const DATA_BLOB *d1, const DATA_BLOB *d2)
{
int ret;
if (d1->data == NULL && d2->data != NULL) {
- return -1;
+ return false;
}
if (d1->data != NULL && d2->data == NULL) {
- return 1;
+ return false;
}
- if (d1->data == d2->data) {
- return d1->length - d2->length;
+ if (d1->length != d2->length) {
+ return false;
}
- ret = memcmp_const_time(d1->data, d2->data, MIN(d1->length, d2->length));
- if (ret == 0) {
- return d1->length - d2->length;
+ if (d1->data == d2->data) {
+ return true;
}
- return ret;
+ ret = memcmp_const_time(d1->data, d2->data, d1->length);
+ return ret == 0;
}
/**
check if two data blobs are equal, where the time taken should not depend on the
contents of either blob.
**/
-_PUBLIC_ int data_blob_cmp_const_time(const DATA_BLOB *d1, const DATA_BLOB *d2);
+_PUBLIC_ bool data_blob_equal_const_time(const DATA_BLOB *d1, const DATA_BLOB *d2);
/**
print the data_blob as hex string
DATA_BLOB blob2;
NTSTATUS status;
enum ndr_err_code ndr_err;
- int cmp;
+ bool equal;
status = netlogon_creds_cli_get(context, frame, &creds2);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
- cmp = data_blob_cmp_const_time(&blob1, &blob2);
+ equal = data_blob_equal_const_time(&blob1, &blob2);
TALLOC_FREE(frame);
- return (cmp == 0);
+ return equal;
}
static NTSTATUS netlogon_creds_cli_store_internal(
confounder_len = 512 - new_password.length;
enc_blob = data_blob_const(r->in.new_password->data, confounder_len);
dec_blob = data_blob_const(password_buf.data, confounder_len);
- if (confounder_len > 0 && data_blob_cmp_const_time(&dec_blob, &enc_blob) == 0) {
+ if (confounder_len > 0 && data_blob_equal_const_time(&dec_blob, &enc_blob)) {
DBG_WARNING("Confounder buffer not encrypted Length[%zu]\n",
confounder_len);
TALLOC_FREE(creds);
new_password.length);
dec_blob = data_blob_const(password_buf.data + confounder_len,
new_password.length);
- if (data_blob_cmp_const_time(&dec_blob, &enc_blob) == 0) {
+ if (data_blob_equal_const_time(&dec_blob, &enc_blob)) {
DBG_WARNING("Password buffer not encrypted Length[%zu]\n",
new_password.length);
TALLOC_FREE(creds);
confounder_len = 512 - new_password.length;
enc_blob = data_blob_const(r->in.new_password->data, confounder_len);
dec_blob = data_blob_const(password_buf.data, confounder_len);
- if (confounder_len > 0 && data_blob_cmp_const_time(&dec_blob, &enc_blob) == 0) {
+ if (confounder_len > 0 && data_blob_equal_const_time(&dec_blob, &enc_blob)) {
DBG_WARNING("Confounder buffer not encrypted Length[%zu]\n",
confounder_len);
return NT_STATUS_WRONG_PASSWORD;
new_password.length);
dec_blob = data_blob_const(password_buf.data + confounder_len,
new_password.length);
- if (data_blob_cmp_const_time(&dec_blob, &enc_blob) == 0) {
+ if (data_blob_equal_const_time(&dec_blob, &enc_blob)) {
DBG_WARNING("Password buffer not encrypted Length[%zu]\n",
new_password.length);
return NT_STATUS_WRONG_PASSWORD;