Index: src/OFSecureData.h ================================================================== --- src/OFSecureData.h +++ src/OFSecureData.h @@ -89,10 +89,21 @@ * @return An initialized OFSecureData */ - (instancetype)initWithItemSize: (size_t)itemSize count: (size_t)count; +/*! + * @brief Checks the OFSecureData for equality to another object. + * + * If the specified object is a subclass of @ref OFData, the comparison is + * performed in constant time. + * + * @param object The object which should be tested for equality + * @return A boolean whether the OFSecureData is equal to the specified object + */ +- (bool)isEqual: (nullable id)object; + /*! * @brief Zeroes the data. */ - (void)zero; Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -454,10 +454,31 @@ { return [[OFSecureData alloc] initWithItems: _items itemSize: _itemSize count: _count]; } + +- (bool)isEqual: (id)object +{ + OFData *otherData; + unsigned char diff; + + if (![object isKindOfClass: [OFData class]]) + return false; + + otherData = object; + + if (otherData->_count != _count || otherData->_itemSize != _itemSize) + return false; + + diff = 0; + + for (size_t i = 0; i < _count * _itemSize; i++) + diff |= otherData->_items[i] ^ _items[i]; + + return (diff == 0); +} - (OFString *)description { return @""; }