What is the preferred or recommended way to pursue contestant time compares when array lengths are not equal?
Should we exit as early as possible? Something like:
if (array1.size() != array2.size()) {
return NOT_EQUAL;
}
int accum = 0;
for(int i = 0; i < array1.size(); i++) {
accum |= array1[i] ^ array2[i];
}
return (accum == 0) ? EQUAL : NOT_EQUAL;
Or should we avoid the early exit, and compare as much as possible in hopes of masking as much as possible? Something like:
int size = min(array1.size(), array2.size());
int accum = (array1.size() ^ array2.size());
for(int i = 0; i < size; i++) {
accum |= array1[i] ^ array2[i];
}
return (accum == 0) ? EQUAL : NOT_EQUAL;
Or something else?
Or is this question more appropriate for the folks on the Crypto.SE because its theoretical minutia?
Aucun commentaire:
Enregistrer un commentaire